CMU
UM


PID Tutorial

The three-term controller
Open-loop step response
Proportional control
PD control
PI control
PID control

In this tutorial, we will consider the following unity feedback system:


The three-term controller

The transfer function of the PID controller looks like the following:


where Kp is the proportional gain, Ki is the integral gain, and Kd is the derivative gain. First, let's take a look at the effect of a PID controller on the closed-loop system using the schematic above. To begin, the variable e is the tracking error or the difference between the desired reference value (r) and the actual output (y). The controller takes this error signal and computes both its derivative and its integral. The signal which is sent to the actuator (u) is now equal to the proportional gain (Kp) times the magnitude of the error plus the integral gain (Ki) times the integral of the error plus the derivative gain (Kd) times the derivative of the error.

Generally speaking, for an open-loop transfer function which has the canonical second-order form of:


a large Kp will have the effect of reducing the rise time and will reduce (but never eliminate) the steady-state error. Integral control (Ki) will have the effect of eliminating the steady-state error, but it will make the transient response worse. If integral control is to be used, a small Ki should always be tried first. Derivative control will have the effect of increasing the stability of the system, reducing the overshoot, and improving the transient response. The effects on the closed-loop response of adding to the controller terms Kp, Ki and Kd are listed in table form below.

CL RESPONSE
RISE TIME
OVERSHOOT
SETTLING TIME
S-S ERROR
Kp
Decreases
Increases
No Change
Decreases
Ki
Decreases
Increases
Increases
Eliminates
Kd
No Change
Decreases
Decreases
No Change

Note that these correlations are not exactly accurate, because Kp, Ki, Kd are related to each other. Changing one of these variables can change the effect of the other two. For this reason, the table should only be used as a reference when you are determining the values for Ki, Kp and Kd by trial & error.

Open-loop step response

Many PID controllers are designed by the trial & error selection of the variables Kp, Ki, and Kd. There are some rules of thumb that you can consult to determine good values to start from; see your controls book for some explanations of these recommendations.

Suppose we have a second-order plant transfer function:


Let's first view the open-loop step response. To model this system into Matlab, create a new m-file and add in the following code:

The DC gain of the plant transfer function is 1/20, so 0.05 is the final value of the output for a unit step input. This corresponds to a steady-state error of 0.95, quite large indeed. Furthermore, the rise time is about one second, and the settling time is about 1.5 seconds. Most likely, this response will not be adequate. Therefore, we need to add some control.

Proportional control

From the chart above we see that Kp will help us to reduce the steady-state error. Let's first add a proportional controller into the system, by changing your m-file to look like the following: The cloop command in Matlab is used to convert the open loop transfer function into a closed-loop one. Since the cloop command only accepts one transfer function, the plant and controller transfer functions have to be multiplied together before the loop is closed. It should also be noted that it is not a good idea to use proportional control to reduce the steady-state error, because you will never be able to eliminate the error completely. This fact will become evident below. If you rerun you m-file, you should get the following plot:

Now, the rise time has been reduced and the steady-state error is smaller, if we use a greater Kp, the rise time and steady-state error will become even smaller. Change the Kp value in the m-file:

Rerun the m-file and you should get the following plot:

This time we see that the rise time is now about 0.1 second and the steady-state error is much smaller. But the overshoot has gotten very large. From this example we see a large proportional gain will reduce the steady-state error but at the same time, worsen the transient response. If we want a small overshoot and a small steady-state error, a proportional gain alone is not enough.

PD control

The rise time is now probably satisfactory (rise time is about 0.1 second). Now let's add a derivative controller to the system to see if the overshoot can be reduced. Add another variable, Kd, to the m-file, set it equal to 10 and rerun the m-file:

The overshoot is much less then before. It is now only twenty percent instead of almost forty-five percent. We can now try to improve that even more. Try increasing Kd to 100, you will see the overshoot eliminated completely.

We now have a system with a fast rise time and no overshoot. Unfortunately, there is still about a 5 percent steady-state error. It would seem that a PD controller is not satisfactory for this system. Let's try a PI controller instead.

PI control

As we have seen, proportional control will reduce the steady-state error, but at the cost of a larger overshoot. Furthermore, proportional gain will never completely eliminate the steady-state error. For that we need to try integral control. Let's implement a PI controller and start with a small Ki. Go back to the m-file and change it so it looks like the following (note the t input is removed from the step command so more of the response can be seen):

The Ki controller really slows down the response. The settling time becomes more than 500 seconds. To reduce the settling time, we can increase Ki, but by doing this, the transient response will get worse (e.g. large overshoot). Try Ki=10, by changing the Ki variable. The plot can be see better if an axis command is added after the step response. Your m-file should now look like the following:

Now we have a large overshoot again, while the settling time is still long. To reduce both settling time and overshoot, a PI controller by itself is not enough.

PID control

From the two controllers above, we see that if we want a fast response, small overshoot, and no steady-state error, neither a PI nor a PD controller will suffice. Let's implement both controllers and design a PID controller to see if combining the two controllers will yield the desired response. Recalling that our PD controller gave us a pretty good response, except for a little steady-state error. Let's start from there, and add a small Ki (1). Change your m-file to the following to implement the PID controller and plot the closed-loop response:

The settling time is still very long. Increase Ki to 100.

The settling time is much shorter, but still not small enough. Increase Ki to 500 and change the step command to step(numCL, denCL,t):

Now the settling time reduces to only 1.5 seconds. This is probably an acceptable response for this system. To design a PID controller, the general rule is to add proportional control to get the desired rise time, add derivative control to get the desired overshoot, and then add integral control (if needed) to eliminate the steady-state error. You may have to go back and readjust all three variables to fine-tune the response.


User Survey
Your anonymous answers to the following questions will help us to improve future versions of these tutorials.
How useful was this tutorial?
Very useful Useful Somewhat useful Not very useful A waste of time
How was the level of the tutorial?
Too simple About right Too difficult
How much time did you spend on it?
Less than 30 mins. 30 - 60 mins. More than 60 mins.
How much of the Matlab code did you run?
None Some Most

We would like to hear about suggestions you have for improvement, difficulties you had with the tutorials, errors that you found, or any other comments that you have. This feedback is anonymous.

If you would like to receive a response, send your comments or questions to ctm-feedback@umich.edu


PID Examples
Cruise Control | DC Motor | Bus Suspension | Inverted Pendulum

Tutorials
Basics | Modeling | PID | Root Locus | Frequency Response | State Space | Examples

HOME INDEX COMMANDS

8/26/1996 YS