Arduino-PID-Library icon indicating copy to clipboard operation
Arduino-PID-Library copied to clipboard

Private PID::Initialize()

Open zafrirron opened this issue 7 years ago • 2 comments

  1. Please add "lastTime = millis()-SampleTime;" to Initialize (bug)

  2. Please consider to expose this private function to public use...in some use cases changing Kp,Ki,Kd to obtain optimized set there is reason to restart the controller.

  3. May be my misunderstanding of the code but it looks like changing from auto mode to manual as the same like not calling compute in the loop?

  4. Please consider fixing compute() : currently computation done in case of timeChange > SampleTime, the calculation however done based on K(i,d) based on SampleTime instead of the actual timeChange... this is causing fluctuations in the controller results.

  5. After thorough testing and comparison to other PID simulations, I suspect the current compute method doesn't yield a valid PID output...a basic peudo compute code should be:

    outputSum += error * dt; //integral of Err/dt output += ki * outputSum; //Ki * integ(Err/dt) if(!pOnE) output -= kp * dInput; else output += kp * error; //Kp * Err output += kd * dError / dt; //Kd * Derr/Dt

    if(output > outMax) output = outMax; else if(output < outMin) output = outMin; *myOutput = output;

Unfortunately the current code doesn't not yield same result...

zafrirron avatar Feb 17 '18 07:02 zafrirron

Please confirm that you've read this series of posts explaining my design choices: http://brettbeauregard.com/blog/2011/04/improving-the-beginners-pid-introduction/

br3ttb avatar Feb 18 '18 02:02 br3ttb

zafrirron can you please send us a real code replacement of compute() instead of pseudocode? My feeling is that you are right (I see strange behavior in the current code) and I would like to test your concept.

cptX avatar Mar 17 '18 00:03 cptX