PID control
So far, we have seen P, I, and PI control strategies. We will now discuss PID control, which also includes a derivative term.
PID control¶
A PID controller in transfer function form looks like
The parameters , , and are the proportional, integral, and derivative gains, respectively. Depending on which gains are nonzero we have:
P control:
PI control:
PD control:
PID control:
We can also write the PID control law in the time domain:
Present-past-future interpretation¶
The proportional term looks at the present error and provides a corrective action based on the current error.
The integral term looks at the past error (accumulated over time) and provides a corrective action based on the accumulated error over time.
The derivative term looks at the future error (predicted based on the current rate of change of the error) and provides a corrective action based on this prediction.
Example: drone altitude control¶
In this example, we look at the qualitative effects of adjusting proportional, integral, and derivative gains in a PID controller for controlling the altitude of a drone. No numbers or equations for now!
The user provides a reference altitude , and the drone should adjust its thrust to achieve the desired altitude based on the feedback error .
Proportional gain. A P-controller uses only. This drives the drone towards the desired altitude, but there will be steady-state error due to gravity. The drone will hover at an altitude slightly below the reference altitude, which is not ideal. Increasing can reduce the steady-state error, but it can also increase overshoot and oscillation, and it won’t eliminate the steady-state error entirely.
Integral gain. To eliminate the steady-state error, we can add an integral term, so we have PI control. The integral term will accumulate the error over time and drive the steady-state error to zero. However, we have introduced a new pole, which is not ideal either. Increasing typically reduce the steady-state error faster, but it can also increase overshoot and oscillation, and can increase the settling time.
Derivative gain. To reduce oscillation, we can add a derivative term and obtain a PID controller. The derivative term looks at the rate of change of the error, and provides a corrective action that is proportional to this rate. So if we are approaching the desired altitude too quickly, the derivative term will reduce the input, helping to reduce overshoot. Increasing has a similar effect to adding damping. This can help reduce overshoot and oscillation, but if is too large it can make the system overdamped and sluggish.
Interactive demonstration. The interactive demo below shows the step response for the drone altitude PID controller. The drone starts on the ground and is trying to reach the reference altitude (dashed line). You can tune , , and by moving the sliders.
Start by increasing . The steady-state error decreases and the response is faster, but overshoot and oscillation increase. Pick about half-way up the slider.
Now increase . Notice the steady-state error goes to zero, but the integral gain introduces even more overshoot and oscillation, and the settling time gets longer. Let’s pick about half-way up the slider as well.
Now increase . Notice the damping effect; overshoot and oscillation decrease, and the settling time gets shorter. Try increasing all the way up and see what happens! The system becomes overdamped and sluggish, so we don’t want to go that far. Let’s pick about half-way up the slider as well.
Try experimenting with different combinations of , , and to see how they affect the transient response and steady-state error.
Video explanations of PID¶
The two videos below provide excellent explanations of PID control in the context of a drone and a self-driving car, respectively. They also provide intuitive explanations of the roles of the proportional, integral, and derivative terms in a PID controller.
Video explaining PID in the context of the drone example.
Video explaining PID in the context of a self-driving car.
PID control of second-order systems¶
Consider the second-order plant
The transfer function of a PID controller can be written as
So a PID controller introduces an integrator (pole at the origin) and two zeros (the roots of the numerator) to the loop transfer function. The closed-loop transfer function is:
Pole placement¶
If we know where we want to place the poles of the closed-loop system (for example, to achieve a desired settling time, percent overshoot, or peak time), we can do it directly by finding the characteristic polynomial we want and matching coefficients to find the corresponding , , and values.
For example, suppose our open-loop plant had and . Substituting these values into the closed-loop transfer function (6), we have
If we want to place the poles at -1, -2, and -3, then the characteristic polynomial is
Matching coefficients, we have
Canceling the plant poles¶
As we saw with PI control of a first-order system, we can use the zeros of the PID controller to cancel out the poles of the plant if they are stable. If we use a PID controller of the form:
then the loop transfer function is
which is a first-order system with a single pole at the origin. This means we have successfully canceled the two poles of the second-order plant, and we have a much simpler system to analyze and control. The closed-loop transfer function is
so the closed-loop system is a first-order system with DC-gain 1 and time constant . This means we can make the response arbitrarily fast by increasing and there will never be overshoot.
2-DOF PID controller (bonus)¶
One way to get around the issue of the zeros is to use a 2-DOF PID (two degree-of-freedom PID) controller, which introduces additional tuning parameters and . The time-domain control law is
Remember that , so the proportional term is now instead of , and the derivative term is now instead of . This is more complicated than standard PID because the controller needs independent access to and , not just the error . If we pick and , we recover the standard PID controller.
Let’s see what this additional complexity buys us. In the Laplace domain, the 2-DOF PID controller and plant equations look like:
Eliminating and simplifying, we obtain the closed-loop transfer function:
Compare this to the closed-loop transfer function for the standard PID controller in (6). The DC gain is still 1 (zero steady-state error), so the integral term is doing its job. The denominator is unchanged, but the numerator now includes and . Adjusting these parameters allows us to place the zeros of the controller independently of the poles, so we have ultimate flexibility in placing the poles and zeros anywhere we like! We can even pick to eliminate the zeros entirely if we so choose.
The trade-off here is that 2-DOF PID controllers are more complex to implement and tune, since we now have five knobs to adjust instead of three, and we need independent access to and , which may not always be possible.
Example: inverted pendulum¶
Consider an inverted pendulum. The equations of motion look like
where represents the upright position and is the torque applied at the pivot. Linearizing around and making all the coefficients equal to 1 for simplicity, we obtain the transfer function
The poles are located at , so the system is unstable (of course!). Let’s design a controller step by step, adding more complexity only when necessary.
Control architecture¶
Let’s start with the standard unity feedback control architecture, but we’ll add an additional input , which represents a disturbance. The disturbance occurs at the input because it is a force/torque. For example, it could be a person tapping the pendulum with their finger, or a constant wind force pushing the pendulum.
Figure 3:Block diagram of a feedback control system with a disturbance input.
Our goal is not to track a reference signal . We just want to stabilize the pendulum at the upright position. So we will use . Rather, our goal is to reject the disturbance . In other words, when is nonzero, we want the output to stay as close to zero as possible. We might have:
This is a common control problem known as disturbance rejection. Let’s redraw the block diagram to reflect this goal.
Figure 4:Modification of Figure 3 with and the disturbance treated as the reference.
The closed-loop transfer function from the disturbance to the output is
P control¶
With proportional control, the closed-loop transfer function is
Depending on the value of , the poles of the closed-loop system can be in different locations. Remembering our definitions of stability:
If , the poles are at , so we have a pole with a positive real part and the system is unstable.
If , both poles are at , so we have a repeated pole on the imaginary axis and the system is unstable.
If , the poles are at , so both poles are on the imaginary axis and the system is marginally stable (undamped oscillation). Better than instability, but still not good enough.
The usual next step is to add an integral term to eliminate the steady-state error, but this is a different controller architecture so we shouldn’t blindly apply our previous results from the table on steady-state errors. From Eq. (19) and the FVT, the output we are trying to drive to zero is given by
Let’s look at the two disturbance cases.
Impulsive disturbance: If , then . We also know that has no integrators, so is constant. We find:
So the system can perfectly reject an impulsive disturbance for any PID compensator, as long as the closed-loop system is stable.
Step disturbance: If , then . We find:
In this case, need an integrator in our compensator to perfectly reject a step disturbance. Otherwise, we would have a finite steady-state error (our pendulum would lean in the wind instead of standing upright). Maybe this is acceptable; so let’s skip the integrator for now.
PD control¶
With proportional-derivative control, the closed-loop transfer function is
Using our stability tests, we will have a stable system whenever and . We can place the closed-loop poles anywhere we like!
What if we wanted to reject a step disturbance perfectly? We would need an integrator, which means we would need to use a PID controller instead of a PD controller.
PID control¶
With proportional-integral-derivative control, the closed-loop transfer function is
Using our stability tests, we will have a stable system whenever and and and . Again, we can place the closed-loop poles anywhere we like by tuning , , and .
Interactive demonstration¶
The demo below shows the impulse or step response of the inverted pendulum system with PID control. You can adjust the gains and see how they affect the transient response and steady-state error. The axes on the right also show the pole locations of the closed-loop system.
Verify that with only P control, the system is unstable for and marginally stable for .
Add a derivative term and verify that the system is stable for and , has zero error to an impulse input, but finite error to a step input.
Add an integral term and verify that the system has zero error to both impulse and step inputs.
Practical considerations¶
When implementing PID control in practice, there are a few details worth knowing about. We will mention them briefly here so you are aware of them, but we won’t go into too much detail.
Integrator windup¶
In an ideal scenario, the integral term in a PID controller helps eliminate steady-state error. However, some things can go wrong in practice. Here is an example:
Suppose we are holding the drone in our hands and we turn on the controller. We get distracted and end up waiting a few minutes before releasing the drone. During this time, the error is very large because the drone is far from the reference altitude, so the integral term starts accumulating a large value. This is called integrator windup. By the time we release the drone, the integrator has accumulated an enormous value, which saturates the thrusters. The drone shoots up but by the time it reaches the desired altitude, the integral term is still very large, so it keeps shooting up and overshoots the target altitude by a lot. We then get a highly oscillatory response with massive overshoot, or worse, the drone crashes into the ground on the way back down!
To prevent this, we can use an anti-windup strategy, which typically involves limiting the value of the integral term to prevent it from growing too large. This can be done by introducing a saturation limit on the integral term, or by using a conditional integration approach where the integral term is only updated when the control input is not saturated.
Noise sensitivity¶
The PID controller looks like this in the time domain:
The derivative term can be problematic since differentiation amplifies high-frequency noise. The error signal is typically measured using sensors, and these measurements can be noisy. There are several ways to mitigate this issue:
Filtered derivative. Use a filtered derivative term itself, so instead of the transfer function , we use something like , where is a time constant that determines the cutoff frequency of the filter. Equivalently, you can filter the error signal first and then differentiate it. We will learn more about filtering later!
Use a “dirty derivative”. Approximate the derivative using a difference equation, such as , which can help reduce noise sensitivity.
Use a different sensor. Measure the derivative directly using a sensor. For example, if we are trying to control the position of a robot, we can use an encoder to measure the velocity directly, which is the derivative of position. This way, we can avoid differentiating a noisy signal altogether.
Test your knowledge¶
Solution to Exercise 1 #
A PID controller can be written as
To cancel the stable plant poles at and , choose the controller numerator to be proportional to , i.e.
Matching coefficients with gives
Now compute the loop transfer function:
So the closed-loop transfer function is first-order:
This has DC gain , so the step steady-state error is zero.
For a first-order system with pole at , the settling time is approximately
Setting gives . Therefore,
Solution to Exercise 2 #
The loop gain is
Thus the closed-loop characteristic polynomial is the denominator of , which is
Collecting powers of , we have
Because the leading coefficient is , we match this polynomial to . Since
coefficient matching yields
Now substitute . From we get
From ,
From ,
Answer
(yes, the derivative gain is negative! This is a consequence of the derivative filter, which adds a zero to the controller that can affect the transient response. The negative derivative gain helps to counteract this effect and achieve the desired closed-loop pole placement.)