EEE 4706 Expt 5
EEE 4706 Expt 5
Here, plant is the system under study. Controller provides necessary excitation to the plant so as to control
the overall closed loop system.
A PID controller has a general three-term transfer function as follows:
( )= + +
+ +
( )=
Here,
=
=
=
First, let's take a look at how the PID controller works in a closed-loop system using the schematic shown
above. The signal e(t) represents the tracking error, the difference between the desired input signal R(t) and
the actual output Y(t). This error signal e(t) will be sent to the PID controller, and the controller computes
both the derivative and the integral of this error signal. The signal u(t) just past the controller 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.
Mathematically, the signal u(t) fed to the plant by the controller is given by following time-domain
expression.
( )
( )= ( )+ ( ) +
This signal u(t) will be sent to the plant, and the new output (Y) will be obtained. This new output
(Y) will be sent back again to find the new error signal (e). The controller takes this new error
signal and computes its derivative and its integral again. This process goes on and on.
Note: You can also have P controller, I controller, D controller, PI controller and PD controller.
A proportional controller (Kp) will have the effect of reducing the rise time and will reduce, but
never eliminate, the steady-state error. An integral control (Ki) will have the effect of eliminating
the steady-state error, but it may make the transient response worse. A derivative control (Kd)
will have the effect of increasing the stability of the system, reducing the overshoot, and
improving the transient response. Effects of each of controllers Kp, Kd, and Ki on a closed-loop
system are summarized in the table shown below.
Note: These correlations may not be exactly accurate, because Kp, Ki, and Kd are dependent of
each other. In fact, changing one of these variables can change the effect of the other two. Thus,
instead of treating this table as a verdict, you should use it as a heuristic guide when you perform
simulation to find the values of Kp, Ki and Kd.
Many of the observations in the above table are empirical (experimental). However, some of them
can be explained by the theory you have studied in EEE 4705. Try to verify the table wherever
possible. For example, insertion of Ki eliminates S-S error. You can verify this observation.
Insertion of Ki term essentially adds a pole in the system. What would happen to steady-state error
when a pole is inserted to the system? Can you explain it from the order-of-system point of view?
Some of the observations in this table can be explained using root-locus theory.
Example Problem
( ) ( )
( )= + + ( )
( ) 1
=
( ) + +
First, let us see the response of the system using the following simulation code.
num = 1;
M = 1; b = 10; k = 20;
den = [M b k];
step(num,den)
title('respose of the open loop system')
Now, you can check the rise time, steady-state error and other parameters from the diagram. To
do this, right click on any white segment of the plot. Select ‘characteristics’ and select your desired
parameter. For example, if you wish to compute the rise time, select ‘rise time’ and you will see
that a pair of grid-lines has appeared in the diagram. Take your cursor over the blue dot and it will
show the value of rise-time. (This lab note was prepared using MATLAB r2010a, for other
versions this might differ)
0.045
System: sys
0.04 Rise Time (sec): 0.884
0.035
0.03
Amplitude
0.025
0.02
0.015
0.01
0.005
0
0 0.5 1 1.5 2 2.5
Time (sec)
Using this technique, we see that 0.05 is the final value of the output to a unit step input. This
corresponds to the steady-state error of 0.95 which is significantly huge (95%). Furthermore, the
rise time is about one second, and the settling time is about 1.5 seconds. Let's design a controller
that will reduce the rise time, reduce the settling time, and eliminates the steady-state error.
0.045
0.04
0.035
0.03
Amplitude
0.025
0.02
0.015
0.01
0.005
0
0 0.5 1 1.5 2 2.5
Time (sec)
We see that some of the parameters, in fact, got worsened. So, we will insert a controller in the
forward path of the system. First, we use a proportional controller.
Insertion of a proportional term in the forward path changes the overall open loop transfer function
to
( ) 1
=
( ) + +
Assume that we are using a gain of 300. At this point, we are using arbitrary gains values. Later,
we will move to more sophisticated method.
Kp = 300;
num = Kp;
M = 1; b = 10; k = 20;
den = [M b k];
1.2
0.8
Amplitude
0.6
0.4
0.2
0
0 0.2 0.4 0.6 0.8 1 1.2 1.4
Time (sec)
The above plot shows that the proportional controller reduced both the rise time and the steady-
state error, increased the overshoot, and decreased the settling time by small amount.
To reduce the overshoot, we insert a derivative term in our controller. So, now we have a
proportional-derivative controller in our system.
( ) 1
=( + )
( ) + +
Kp = 300;
Kd = 10;
num = [Kd Kp];
M = 1; b = 10; k = 20;
den = [M b k];
1.2
0.8
Amplitude
0.6
0.4
0.2
0
0 0.1 0.2 0.3 0.4 0.5 0.6
Time (sec)
This plot shows that the derivative controller reduced both the overshoot and the settling time,
and had small effect on the rise time and the steady-state error.
Before going into a PID control, let's take a look at a PI control. From the table, we see that an
integral controller (Ki) decreases the rise time, increases both the overshoot and the settling
time, and eliminates the steady-state error.
( ) 1
=( + )
( ) + +
( ) +
=
( ) + +
Assume an integral gain of 70.
Kp = 300;
Ki = 70;
num = [Kp Ki];
M = 1; b = 10; k = 20;
den = [M b k 0];
1.2
0.8
Amplitude
0.6
0.4
0.2
0
0 0.5 1 1.5 2 2.5 3 3.5
Time (sec)
We have reduced the proportional gain (Kp) because the integral controller also reduces the
rise time and increases the overshoot as the proportional controller does (double effect). The
above response shows that the integral controller eliminated the steady-state error.
Now, we will add all terms of a PID controller in our system. So, the overall open loop transfer
function of the system will be as follows:
( ) 1
=( + + )
( ) + +
( ) 2
+ + 1
=( )
( ) + +
( ) 2
+ +
=
( ) + +
We will use the values of Kp=350, Ki=300, and Kd=50. These value were obtained using many
trials and errors. In later sections, we will use a better method.
Kp = 350;
Ki = 300;
Kd = 50;
num = [Kd Kp Ki];
M = 1; b = 10; k = 20;
den = [M b k 0];
0.9
0.8
0.7
0.6
Amplitude
0.5
0.4
0.3
0.2
0.1
0
0 0.5 1 1.5 2 2.5
Time (sec)
When you are designing a PID controller for a given system, follow the steps shown below to
obtain a desired response.
Note: please keep in mind that you do not need to implement all three controllers (proportional,
derivative, and integral) into a single system, if not necessary. For example, if a PI controller gives
a good enough response (like the above example), then you don't need to implement derivative
controller to the system. Keep the controller as simple as possible.
You need to perform many rounds of trails to select the appropriate values of Kp, Kd and Ki.
Instead of running the codes separately over and over again, you can automate the process and
make it user-friendly.
M = 1; b = 10; k = 20;
Kd = 100; Kp = 100; Ki = 100;
while(1)
num = [Kd Kp Ki];
den = [M b k 0];
step(num,den)
The process of selection of parameters in PID is tedious. Using Simulink this task can be
accomplished in a much easier way.
2. Now, double click the PID controller box. Following window will appear.
Here, the default value of the controller gains are given. You can also change the controller to a PI
or PD as needed.
3. Click on the “Tune” button to for graphical tuning of the parameters. A new window will
appear. Click on the arrow sign next to ‘Show parameters’ on window.
This window shows the parameters of the system such as rise time, overshoot etc along with Kp,
Kd, Ki values of the PID controller on the right side. You can tune the system by using the
interactive tuner on the bottom.
4. You can change the shape of the response by interactive tuning. You will see the responses
without tuning (“block response” with default PID parameters) and with the tuned
parameters. Corresponding controller gain values are seen on the right.
5. If you have found a desired and controlled response, select ‘Apply’. Now, again double-
click on the PID controller block in your model to see that the appropriate gain values have
been selected. Finally, from the scope see that the response is indeed the selected response.
1. Using a PID controller, control a DC motor system (see previous class lecture) for less than
5% overshoot, less than 1 second rise time, less than 5 second settling time and less than
1% S-S error. Perform this task by manual method using MATLAB coding. Report the
controller gain values. Then use Simulink to perform the same task and report the values.
2. Discuss the reason of reduction (or elimination) of steady-state error when a Ki term is
added to the controller function.
Optional Project
We have semi-automated the trial and error process of finding the controller gain values using a
rudimentary code containing a while loop. Can you build a MATLAB GUI that does the following
tasks?
a. Receives the numerator and denominator coefficients of the transfer function from the
user. It should be flexible enough to take the coefficients in the factored format as well
e.g.: (s+1)/(s+2)(s+3). In that case, it will perform the convolution in the background
to expand the factors.
b. It will accept the values of desired overshoot, rise time, settling time and steady-state
error.
c. It will plot the step response of the system in closed loop inserting a PID controller in
the forward path. It will also show the current values of overshoot, rise time, settling
time and steady-state error.
d. It will compare the values in step b and step c and use the table in the page 2 of this lab
note to guide the user with such instructions: “increase Kp”, “decrease Ki” etc.
e. It will keep repeating the step d until the design requirements are met.
f. Feel free to insert any number of features/ modifications to the GUI.
You must NOT use Simulink for this purpose. It might not be possible to design such a system
with perfection since the table in page 2 is not accurate all the time. But, try your best.
Rifat Ahmed
Lecturer
EEE, IUT