Control-System-Lab-6 New
Control-System-Lab-6 New
Key MATLAB commands used are: tf , step , pid , feedback , pidtool , pidtune
The transfer function of a PID controller is found by taking the Laplace transform of Eq.(1).
(2)
We can define a PID controller in MATLAB using the transfer function directly, for example:
Kp = 1;
Ki = 1;
Kd = 1;
s = tf('s');
C = Kp + Ki/s + Kd*s
C =
s^2 + s + 1
-----------
s
Alternatively, we may use MATLAB's pid controller object to generate an equivalent contin
C = pid(Kp,Ki,Kd)
C =
1
Kp + Ki * --- + Kd * s
s
with Kp = 1, Ki = 1, Kd = 1
The control signal ( ) to the plant is equal to the proportional gain ( ) times the magnitude of
the error plus the integral gain ( ) times the integral of the error plus the derivative gain ( )
times the derivative of the error.
This control signal ( ) is sent to the plant, and the new output ( ) is obtained. The new output ( )
is then fed back and compared to the reference to find the new error signal ( ). The controller
takes this new error signal and computes its derivative and its integral again, ad infinitum.
The transfer function of a PID controller is found by taking the Laplace transform of Eq.(1).
(2)
We can define a PID controller in MATLAB using the transfer function directly, for example:
Kp = 1;
Ki = 1;
Kd = 1;
s = tf('s');
C = Kp + Ki/s + Kd*s
C =
s^2 + s + 1
-----------
s
Alternatively, we may use MATLAB's pid controller object to generate an equivalent contin
C = pid(Kp,Ki,Kd)
C =
1
Kp + Ki * --- + Kd * s
s
with Kp = 1, Ki = 1, Kd = 1
Let's convert the pid object to a transfer function to see that it yields the same result as above:
tf(C)
ans =
s^2 + s + 1 -----------
s
Note that these correlations may not be exactly accurate, because , , and are dependent on
each other. In fact, 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
, and .
Example Problem
Suppose we have a simple mass, spring, and damper problem.
(3)
Taking the Laplace transform of the modeling equation, we get
(4)
The transfer function between the displacement and the input then becomes
(5)
Let
M = 1 kg
b = 10 N s/m
k = 20 N/m
F = 1 N
(6)
The goal of this problem is to show you how each of , and contributes to obtain
s = tf('s');
P = 1/(s^2 + 10*s + 20);
step(P)
The DC gain of the plant transfer function is 1/20, so 0.05 is the final value of the output to an
unit step input. This corresponds to the 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. Let's
design a controller that will reduce the rise time, reduce the settling time, and eliminate the
steady-state error.
Proportional Control
From the table shown above, we see that the proportional controller (Kp) reduces the rise time,
increases the overshoot, and reduces the steady-state error.
The closed-loop transfer function of the above system with a proportional controller is:
(7)
Let the proportional gain ( ) equal 300 and change the m-file to the following:
Kp = 300;
C = pid(Kp)
T = feedback(C*P,1)
t = 0:0.01:2;
step(T,t)
C =
Kp = 300
P-only controller.
T =
300
----------------
s^2 + 10 s + 320
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
Proportional-Derivative Control
Now, let's take a look at a PD control. From the table shown above, we see that the derivative
controller (Kd) reduces both the overshoot and the settling time. The closed-loop transfer
function of the given system with a PD controller is:
(8)
Let equal 300 as before and let equal 10. Enter the following commands into an m-file and
run it in the MATLAB command window.
Kp = 300;
Kd = 10;
C = pid(Kp,0,Kd)
T = feedback(C*P,1)
t = 0:0.01:2;
step(T,t)
C =
Kp + Kd * s
with Kp = 300, Kd = 10
T =
10 s + 300
----------------
s^2 + 20 s + 320
Proportional-Integral Control
Now, let's take a look at a PD control. From the table shown above, we see that the derivative
controller (Kd) reduces both the overshoot and the settling time. The closed-loop transfer
function of the given system with a PD controller is:
(8)
Let equal 300 as before and let equal 10. Enter the following commands into an m-file and
run it in the MATLAB command window.
Kp = 300;
Kd = 10;
C = pid(Kp,0,Kd)
T = feedback(C*P,1)
t = 0:0.01:2;
step(T,t)
C =
Kp + Kd * s
with Kp = 300, Kd = 10
T =
10 s + 300
----------------
s^2 + 20 s + 320
This plot shows that the derivative controller reduced both the overshoot and the settling time,
and had a small effect on the rise time and the steady-state error
Proportional-Integral-Derivative Control
v 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. For the given system, the closed-loop transfer function with
a PI control is:
(9)
Let's reduce the to 30, and let equal 70. Create an new m-file and enter the following
commands.
Kp = 30;
Ki = 70;
C = pid(Kp,Ki)
T = feedback(C*P,1)
t = 0:0.01:2;
step(T,t)
C =
1
Kp + Ki * ---
s
with Kp = 30, Ki = 70
T =
30 s + 70
------------------------
s^3 + 10 s^2 + 50 s + 70
For the original problem setup and the derivation of the above equations,
please refer to the Modeling a DC Motor page.
Now let's design a PID controller and add it into the system. First create a
new m-file and type in the following commands (refer to the Modeling page
for the details of getting these commands).
J=0.01;
b=0.1;
K=0.01;
R=1;
L=0.5;
num=K;
den=[(J*L) ((J*R)+(L*b)) ((b*R)+K^2)];
Recall that the transfer function for a PID controller is:
Proportional control
Let's first try using a proportional controller with a gain of 100. Add the
following code to the end of your m-file:
Kp=100;
numa=Kp*num;
dena=den;
Note that numac and denac are the numerator and the denominator of the
overall closed-loop transfer function.
Now let's see how the step response looks, add the following to the end of
your m-file, and run it in the command window:
t=0:0
step(numac,denac,t)
title('Step response with Proportion Control')
J=0.01;
b=0.1;
K=0.01;
R=1;
L=0.5;
num=K;
den=[(J*L) ((J*R)+(L*b)) ((b*R)+K^2)];
Kp=100;
Ki=1;
Kd=1;
numc=[Kd, Kp, Ki];
denc=[1 0];
numa=conv(num,numc);
dena=conv(den,denc);
[numac,denac]=cloop(numa,dena);
step(numac,denac)
title('PID Control with small Ki and Kd')
Tuning the gains
Now the settling time is too long. Let's increase Ki to reduce the settling
time. Go back to your m-file and change Ki to 200. Rerun the file and you
should get the plot like this:
Now we see that the response is much faster than before, but the large Ki
has worsened the transient response (big overshoot). Let's increase Kd to
reduce the overshoot. Go back to the m-file and change Kd to 10. Rerun it
and you should get this plot:
So now we know that if we use a PID controller with
Kp=100,
Ki=200,
Kd=10,