Control Tutorials For MATLAB and Simulink - Introduction - PID Controller Design
Control Tutorials For MATLAB and Simulink - Introduction - PID Controller Design
MO DELING
Introduction: PID
ANALYSIS Controller Design
SIMULINK
MO DELING
Related
C O NTR O L
Tutorial
Links
RC
Circuit
Control
Activity
Temperature
Control
Activity
Motor
Speed
Control
Activity
Related
External
Links
MATLAB
PID
Control
Video
PID
PID
Control
Intro
Video
Contents
PID Overview
Example Problem
Proportional Control
Proportional-Derivative Control
Proportional-Integral Control
Proportional-Integral-Derivative Control
PID Overview
The output of a PID controller, equal to the control input to the plant, in
(1)
First, let's take a look at how the PID controller works in a closed-loop
represents the tracking error, the difference between the desired input
value ( ) and the actual output ( ). This error signal ( ) will be sent to
the PID controller, and the controller computes both the derivative and
the PID controller, and the controller computes both the derivative and
the integral of this error signal. The control signal ( ) to the plant is
plus the integral gain ( ) times the integral of the error plus the
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.
(2)
Kp = 1;
Ki = 1;
Kd = 1;
s = tf('s');
C = Kp + Ki/s + Kd*s
C=
s^2 + s + 1
-----------
C = pid(Kp,Ki,Kd)
C=
1
Kp + Ki * --- + Kd * s
with Kp = 1, Ki = 1, Kd = 1
Let's convert the pid object to a transfer function to see that it yields
tf(C)
ans =
s^2 + s + 1
-----------
time and will reduce but never eliminate the steady-state error. An
error for a constant or step input, but it may make the transient
response slower. A derivative control ( ) will have the effect of
Small
Kp Decrease Increase Decrease
Change
Small No
Kd Decrease Decrease
Change Change
reason, the table should only be used as a reference when you are
Example Problem
(3)
(4)
then becomes
then becomes
(5)
Let
M = 1 kg
b = 10 N s/m
k = 20 N/m
F=1N
(6)
contributes to obtain
Minimum overshoot
No steady-state error
Let's first view the open-loop step response. Create a new m-file and
s = tf('s');
step(P)
The DC gain of the plant transfer function is 1/20, so 0.05 is the final
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
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.
(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
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
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
overshoot and the settling time, and had a small effect on the rise
Proportional-Integral Control
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-
(9)
Let's reduce the to 30, and let equal 70. Create an new m-file
Kp = 30;
Ki = 70;
C = pid(Kp,Ki)
T = feedback(C*P,1)
t = 0:0.01:2;
step(T,t)
C=
Kp + Ki * ---
s
with Kp = 30, Ki = 70
Continuous-time PI controller in parallel form.
T=
30 s + 70
------------------------
s^3 + 10 s^2 + 50 s + 70
Run this m-file in the MATLAB command window, and you should get
the following plot. 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
Proportional-Integral-Derivative Control
(10)
After several trial and error runs, the gains = 350, = 300, and
= 50 provided the desired response. To confirm, enter the
Kp = 350;
Ki = 300;
Kd = 50;
C = pid(Kp,Ki,Kd)
T = feedback(C*P,1);
t = 0:0.01:2;
step(T,t)
C=
Kp + Ki * --- + Kd * s
s
When you are designing a PID controller for a given system, follow the
5. Adjust each of Kp, Ki, and Kd until you obtain a desired overall
response. You can always refer to the table shown in this "PID
Tutorial" page to find out which controller controls what
characteristics.
Lastly, please keep in mind that you do not need to implement all
enough response (like the above example), then you don't need to
implement a derivative controller on the system. Keep the controller
as simple as possible.
phase margin.
Let's explore these automated tools by first generating a proportional
pidtool(P,'p')
The pidtool GUI window, like that shown below, should appear.
Notice that the step response shown is slower than the proportional
the figure below. The response does indeeed speed up, and we can
see Kp is now closer to the manual value. We can also see all the
Now let's try designing a PID controller for our system. By specifying
pidtool(P,C)
the Design Mode: Extended option at the top, which reveals more
tuning parameters.
Now type in Bandwidth: 32 rad/s and Phase Margin: 90 deg to
results in a faster rise time, and a higher phase margin reduces the
overshoot and improves the system stability.
Finally we note that we can generate the same controller using the
command line tool pidtune instead of the pidtool GUI
opts = pidtuneOptions('CrossoverFrequency',32,'PhaseMargin'
C=
1
Kp + Ki * --- + Kd * s
s
info =
Stable: 1
CrossoverFrequency: 32
PhaseMargin: 90