I'm having trouble understanding the derivative part of a PID controller, because it sometimes seems to react the opposite way that I would like.
Let's use a simple example where :
- the controlled variable is a vehicle position, on a 1 dimension axis (in m)
- the actuator signal is the vehicle speed (in m/s)
- the setpoint is 100 m
- the sampling time is 1 s
Now let's analyze two cases:
- The current position (at t = Ns) is 80 m, and the previous position (at t = (N-1) s) was 60 m.
Hence, we've made 20 m of progress toward the setpoint of 100 m (we're going the right way).
The current error is (100 - 80) = 20 m, while the previous error was (100 - 60) = 40 m: this gives a derivative error of (20 - 40)/1s = -20 m/s.
- The current position (at t = Ms) is 140 m, and the previous position (at t = (M-1) s) was 120 m.
Hence, we've made 20m of regress from the setpoint (we're going the wrong way!).
The current error is (100 - 140) = -40 m, while the previous error was (100 - 120) = -20 m: this gives a derivative error of (-40 - (-20))/1s = (-40 + 20)/1s = -20 m/s.
In both cases, the derivative has the same value, so the controller's derivative behavior will be the same. But the situations are very different: in the first case we're getting closer to the goal, while in the second we're getting away from it.
Why is the derivative part making the same adjustment for two situations that are so different?