1
$\begingroup$

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:

  1. 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.
  2. 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?

$\endgroup$
1
  • $\begingroup$ "Why is the derivative part making the same adjustment for two situations that are so different?" Short answer: because the rate of change is constant. (This is because your controller isn't controlling.) Long answers below. $\endgroup$ – Transistor Jan 24 at 15:56
1
$\begingroup$

The derivative is the rate of change of the error, $ \frac {de}{dt} $.

The current position (at t = Ns) is 80 m, and the previous position (at t = (N-1) s) was 60 m. ... this gives a derivative error of (20 - 40)/1s = -20 m/s.

Correct error is negative.

As you pass through the target position (with the figures you've given us) the error will be zero but still changing at -20 m/s.

The current position (at t = Ms) is 140 m, and the previous position (at t = (M-1) s) was 120 m. ... this gives a derivative error of ... -20 m/s.

Yes. You haven't managed to reduce the speed so the derivative of the error is a constant.

In both cases, the derivative has the same value, so the controller 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 it is the opposite. Why is the derivative part making the same adjustment for two situations that are so different?

The job of the derivative action is to react to a disturbance - usually a rapid change in either setpoint or actual, either of which will increase the derivative term. If you're still travelling at the same speed as you go through the target point then I suspect that your proportional term isn't working correctly.


From the comments:

So, D term's role is not to care about the setpoint, but just to calm things down?

No, D introduces excitement! (And that's its problem.) Consider a car's cruise control. You're set and running at 80 kph and all is fine. Then you come to a hill. Speed drops to 76 kph.

  • With P only there will be a change in throttle. If your proportional band is 10 kph then a 4 kph error should cause the throttle to go to 40%.
  • If you have I activated then this will eventually reduce the error to zero.
  • With D activated you can give the system a big boost if the error suddenly changes. In a car you can feel this if you raise the setpoint suddenly.

Derivative control is susceptible to noise on the feedback as it tries to compensate for a rapidly changing error.

Have a read of my answer to Understanding the flow of a PI controller where the OP had got rather confused. It doesn't address the derivative function but may give you some pointers.

$\endgroup$
7
  • $\begingroup$ I ignored proportional and integral terms in my example, to focus only on the derivative. You're right that on a complete PID, P would react and probably prevent case #2 from happening. So, D term's role is not to care about the setpoint, but just to calm things down? $\endgroup$ – lrntgr Jan 23 at 16:04
  • $\begingroup$ No. See the update. $\endgroup$ – Transistor Jan 23 at 16:16
  • $\begingroup$ The D term does not add “excitement”. Quite the opposite. Derivative feedback add dampening and can reduce overshoot and ringing. $\endgroup$ – Eric S Jan 23 at 19:33
  • $\begingroup$ Hi, @EricS. Sure! If the parameters are set up correctly then the three will contribute to a well behaved system. In my limited experience D can be most difficult to get right and in many cases can be omitted and satisfactory performance achieved with PI and maybe a little D. $\endgroup$ – Transistor Jan 23 at 20:24
  • $\begingroup$ Ok, let me rephrase. D term's role is to show resistance towards the current evolution of the error: if the error is decreasing, D tries to push it up; if the error is increasing, D tries to push it down? $\endgroup$ – lrntgr Jan 24 at 14:59
2
$\begingroup$

TL;DR: Use only the things/concepts you need for an application.

First I'll just say, that the D term is not recommended for the particular system that you are describing. A PI control would be much more appropriate.

I'll try to reiterate some points already made here from my point of view.

In order for a control system to work properly the time between measurements and adjustments needs to be small. (In the example you are describing the time intervals are too large for the control to work appropriately).

You need to remember that the three terms are related to the error at each point in time:

  • Proportionate $K_p e(t)$
  • Integral $\int K_i e(t)dt$ :
  • Derivative $K_D\frac{d}{dt}e(t)$

That means that only the I term has some memory of what is happening in previous states. The D term (at least in the vanilla flavour) uses information from only to the previous state, and then the value is discarded.

Each one of them has a separate role:

  • P: If I am far from target then I should speed up
  • I: If I am away from target for too long then I should speed up
  • D: ... this doesn't reason too well. If I had to describe it for your system, it would be something like: If my position changes too fast (e.g. teleportation) then make some adjustment.

So, in the example you are describing, (as other have suggested/hinted) the problem is that your P and I term are not configured properly. In the end what you are trying to do, is control a system with a term that it's not relevant. Most mechanical (as opposed to electrical) are just fine with just PI control.

$\endgroup$
5
  • 1
    $\begingroup$ The example is actually not relevant, I picked a simple one just to illustrate that the derivative term outputs the same value for opposite situations. From what I understand now, the derivative is here to calm down the pace, to impose some resistance on the current motion (no matter the direction considering the setpoint). Is that right? $\endgroup$ – lrntgr Jan 23 at 15:40
  • $\begingroup$ Most mechanical systems include a damping factor in the mechanical part. $\endgroup$ – joojaa Jan 23 at 17:24
  • $\begingroup$ Following from joojaa comment that means that you don't see abrupt changes that would warrant the use of d. Abrupt changes in most meclanical systems are usually associated with some sort of catastrophic failure. $\endgroup$ – NMech Jan 23 at 19:25
  • $\begingroup$ Yes, but forget the mechanical aspect, my question was more on the PID theory and how the derivative contributeds to the regulation process (the example could have been anything, a mechanic-less model for instance). $\endgroup$ – lrntgr Jan 24 at 15:04
  • $\begingroup$ I had already +1 to your first comment . so yes the D part is to mitigate any abrupt changes. $\endgroup$ – NMech Jan 24 at 15:06
0
$\begingroup$

The derivative term acts like a dampener. It provides a reduction in signal as a function of velocity. As long as you are going in the same direction at the same velocity the controlling effect of the derivative term will be the same. it doesn't care how far away from the set point you are. The proportional term will be significantly different however and is dependent on distance from the set point.

$\endgroup$
3
  • $\begingroup$ Say Kd=1 in my question example, so that the derivative term is a speed of -20m/s. In the 1st case, error is positive so the proportional term will be a positive speed: the derivative part does act like a dampener (slowing speed down). But in the 2nd case, error is negative so the proportional term will be a negative speed: there the derivative pushes the speed even more in the same direction, so not being a dampener? $\endgroup$ – lrntgr Jan 22 at 21:57
  • $\begingroup$ @lrntgr You need to have negative feedback or things get unstable. I'm not sure I understand how you are calculating velocity as it is only (position_now - position_last)/time. No error from set point term is in this calculation. $\endgroup$ – Eric S Jan 22 at 22:02
  • $\begingroup$ My example is confusing because I use the term "speed" for the actuator (the PID output), while the derivative is also a velocity. $\endgroup$ – lrntgr Jan 23 at 15:28
0
$\begingroup$

The "D" in PID is often used when PI response produces overshoot in step response. Sometimes, definitely not always, there is misunderstanding of the problem.

I don't really know how to explain this in time domain. Here is the frequency domain explanation: For the most common case of plant, "single dominant pole" (also includes a plant which is an integrator), the PI controller itself introduces an unwanted "closed loop zero" in the passband, which means overshoot in time domain. The D term in PID is a somewhat clumsy way to correct for this.

There are other options to eliminate the zero from PI. The set point signal can simply be low-pass filtered, to directly cancel the unwanted zero. Rate limits on set point do this to a degree as well. A more involved option is the much maligned PDF control, or a mathematically equivalent arrangement, such as putting the zero in feedback path, rather than forward path as PI would do. (an additional higher frequency feedback pole may be necessary too, in practice, because can't have infinite high freq gain). You don't see this often, but it's not hard in software. The benefit is more intuitive tuning, compared to PID.

The implementation, compared to PID, is as follows: instead d/dt of error, compute d/dt of both the set-point input and plant output. Give them both their own Td coefficients, Td_i and Td_o, and throw them into the integrator along with the error term. (yes, we are integrating something we just differentiated). Often, both the P term and the d/dt(input) term are unnecessary (Kp=0 and Td_i=0), leaving just Ki * integral(error - Td_o * deriv(output))

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.