MiniPID icon indicating copy to clipboard operation
MiniPID copied to clipboard

Calculation of Derivative Output

Open Gord1 opened this issue 5 years ago • 0 comments

Hi, I like your code and documentation, but I think that you have a few problems in the calculation of your derivative output for the general PID case.

You have: Doutput= -D*(actual-lastActual); lastActual=actual;

Your method does provide proper feedback, but only in the case were the setpoint in a constant.

For the general PID case the derivative should be based on the change in error, not the change in sensor (actual) feedback.

It should be written (note no -D): Doutput = D * (error - lastError); lastError = error;

If you think about it, if the setpoint changes you want the derivative to kick in and provide more movement to the output. Say the setpoint increases, the change in error increases, therefore the Doutput increases and adds to the output, increasing the motor speed, heating element PWM on time, etc.

Gord_W

Gord1 avatar Jun 18 '20 15:06 Gord1