br3ttb / Arduino-PID-Library

1.93k stars 1.11k forks source link

Changing sign Derivative factor #104

Open DavyEHB opened 4 years ago

DavyEHB commented 4 years ago

I compared different versions of the PID library. I noticed that the sign of the derivative factor changes between the versions. In the code on your website http://brettbeauregard.com/blog/2011/04/improving-the-beginners-pid-introduction/

/*Compute PID Output*/
   Output = kp * error + ki * errSum **+** kd * dErr;

http://brettbeauregard.com/blog/wp-content/uploads/2011/03/pidalgorithm.png Also includes the addition of the derivative.

v 1.2.1 Here you subtract the derivative.

      /*Compute Rest of PID Output*/
      output += outputSum **-** kd * dInput;

Quite confusing to me. Since it is negative, won't it counteract the response? Could you explain the logic for this?

Kind regards.

AnderbergE commented 4 years ago

I think what you are looking for is explained in the following post: http://brettbeauregard.com/blog/2011/04/improving-the-beginner%e2%80%99s-pid-derivative-kick/