Arduino-PID-Library
Arduino-PID-Library copied to clipboard
Private PID::Initialize()
-
Please add "lastTime = millis()-SampleTime;" to Initialize (bug)
-
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.
-
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?
-
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.
-
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...
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/
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.