98ba59135797356a3482dd8d79a489911be8305e
If you want to use derivative-on-measurement, you will need to negate the 'D'-gain you would typically use in a 'standard derivative-on-error' PID controller - I did not mention that in the video. Since the 'error signal' effectively going into the differentiator does not depend on the setpoint: e[n] = 0 - measurement, and therefore (e[n] - e[n - 1]) = (0 - measurement) - (0 - prevMeasurement) = -Kd * (measurement - prevMeasurement). So, for example, if you require a controller with a D-gain of 10, you would set pid->Kd = -10. This is a slight quirk of the derivative-on-measurement form - however, the code can of course be adapted to include the minus sign.
PID
PID controller implementation written in C.
Note on 'derivative-on-measurement': Since the 'error signal' effectively going into the differentiator does not depend on the setpoint: e[n] = 0 - measurement, and therefore (e[n] - e[n - 1]) = (0 - measurement) - (0 - prevMeasurement) = -Kd * (measurement - prevMeasurement). (Note the minus sign compared to derivative-on-error!) I've included the minus sign in the code, so gains will have the effect as normal.
Description
Languages
C
100%