PID Control System Design, Simulation, and Implementation (II)
PID Control System Design, Simulation, and Implementation (II)
PID Control System Design, Simulation, and Implementation (II)
09
ECE 329 Automatic Control Lab
Professor: ABC
By:
XYZ
Date:12/07/2018
Page | 2
Acknowledgment
I would like to thank Dr. Manzak for providing help during the lab and correct our mistakes. Also, I would
like to thank my classmate Kusa for his help to get the right results.
Page | 3
Contents
Page | 4
List of illustrations
Page | 5
Objective
The main objective of this lab is to learn how to design, simulate, and implement a Proportional/ Integral/
Differential (PID) controller to meet design criteria for a control system. MATLAB and Simulink are used
to simulate various gains/coefficients for the proportional, Integral, and derivative terms of the PID
controller.
Introduction
A proportional / integral / derived controller (PID / three-term controller) is a control loop feedback
mechanism widely used in industrial control systems and in a variety of other applications requiring
continuous modulation control and has been universally accepted in the industry control. A PID controller
continuously calculates an error value and (t) as the difference between a desired set point (SP) and a
measured process variable (PV) and applies a correction based on proportional, integral and derived terms,
as shown in the following figure.
Page | 6
P Response
The proportional block is mainly responsible for the reaction speed of the system. The proportional
component depends only on the difference between the set point and the process variable. This difference
is known as the error term. The proportional gain (Kc) determines the relationship between the output
response and the error signal. For example, if the error term has a value of 10, a proportional gain of 5 will
produce a proportional response of 50.
In general, increasing the proportional gain will increase the response speed of the control system.
However, if the proportional gain is too large, the process variable will start to oscillate. If Kc increases
further, the oscillations will become larger and the system will become unstable and may even oscillate
without control.
I Response
The integral part is very important and guarantees a zero error value in the steady state, which means that
the output will be exactly what we want it to be. The integral component adds the error term over time. The
result is that even a small mistake will cause a slow increase in the integral component. The integral
response will continuously increase over time unless the error is zero, so the effect is to bring the steady
state error to zero. The steady state error is the final difference between the process variable and the set
point.
A phenomenon called integral winding occurs when the integral action saturates a controller without the
driver guiding the error signal to zero. However, the integral action of the controller causes the system to
respond more slowly to the desired value changes and for the systems, if the reaction is very rapid, it is
important that it be omitted. Some non-linearities will also cause problems for the integration action.
D Response
The derivative part was introduced to speed up the response. The derived component decreases the output
if the process variable increases rapidly. The derived response is proportional to the rate of variation of the
process variable. By increasing the derived time parameter (Td), the control system will react more strongly
to changes in the error term and will increase the speed of the overall response of the control system. The
most practical control systems use a very small derivative time (Td), since the derived response is highly
sensitive to noise in the process variable signal.
If the sensor feedback signal is disturbed or if the control circuit speed is too slow, the derived response
may make the control system unstable. However, it is very sensitive to noise and can make the system react
very nervously. Therefore, it is often omitted in the controller design.
Filtering the output of the derived part can reduce the nerve reaction, but it also slows down the response
of the controller and sometimes undermines the feeling of using the derived part. Proper filtering can help
reduce high frequency noise without compromising the performance of the control system in the lower
frequency band.
By Increasing P, I and D
Page | 7
Effects of increasing a parameter independently with different aspects are shown in table below
The popularity of PID controllers can be attributed in part to their high performance in a wide range of
operating conditions and partly to their functional simplicity, which allows engineers to manage them
simply and directly. The idea behind a PID controller is to read a sensor, then calculate the desired output
of the actuator by calculating the proportional, integral and derivative responses and adding these three
components to calculate the output. The components of a PID controller are briefly described below.
Page | 8
Optimizing a PID controller is something of a learned art, but there are consistent ways in which one can
deal with the task. A common way (but not the only one) is to follow these steps:
• Measure the transient response of the open circuit of the open process system and determine what
needs to be improved.
• First of all, add a proportional control to improve the rise time.
• Add a derivative control, to improve overshoot.
• Next, add an integral check to eliminate the steady state error.
• Now, start going back and forth between the three controller variables (KP, KI and KD), adjusting
each until the desired response from the system is achieved.
Keep in mind that you do not need to implement the three controllers to better implement a given task. For
example, a PI controller (without part D, or KD = 0) is commonly used in many systems and will comply
with all the desired transient performance characteristics of a given system. In general, it is a good idea to
keep the controller as simple as possible. Many tasks can be implemented correctly using only a
proportional controller (KP).
Another commonly used method uses the following steps:
• Set KP to reduce the error until the output starts to overtake and sound. These are signs that the
system is becoming unstable.
• Set KD to reduce overshoot until it is acceptable, and then "control" this call effect. Note that an
incorrect KD value will cause the system to become unstable again.
• Set KI to bring the steady state error to zero.
• Continue to "adjust" these variables until the overall system performance is acceptable.
There are other methods in general, as mentioned above, tuning is an art and every professional develops
his own favorite methods. Feel free to experiment with changing the order of these steps.
𝐶 = 𝑝𝑖𝑑(𝐾𝑝 , 𝐾𝑖 , 𝐾𝑑 );
The MATLAB FEEDBACK function can be used to configure the transfer function of a closed
loop system. However, it has some limitations. Consult the HELP to find out how to implement
this command.
Page | 9
There are commands to help you tune a PID circuit. Use the HELP menu to review the
'PIDTUNE' commands (a menu-driven user interface) or 'PIDTOOL' (a graphical user interface).
Useful for both is the "PIDTUNEOPTIONS" command, which allows you to define many
different performance criteria with which to limit the system.
It is not specific for PID control, but the SISO tool tool toolbox, which is called by the
"SISOTOOL" command, is useful in all types of controller designs. Therefore, you can open a
closed step response from the "Analysis charts" window in the "Control and estimation tools
management" window. If you check the "Update in real time" box, you can change the revenue
using the "Compensator Editor" tab.
Applications
In theory, a controller can be used to control any process that has a measurable output (PV), an ideal
value known for that output (SP) and an input for the process (MV) that will affect the relative PV. The
controllers are used in the industry to regulate temperature, pressure, force, feed speed, flow rate,
chemical composition (component concentrations), weight, position, speed and virtually any other
variable for what a measurement exists.
Page | 10
Part 1
Design a PID controller for DC motor speed with a 1-rad/sec step reference and
the design criteria are the following:
Settling time less than 2 seconds
Overshoot less than 5%
Steady-state error less than 1%
The structure of the control system has the form shown in below. The open-loop transfer functions of the
DC Motor system are given as follows:
𝑄(𝑠) 𝐾 𝑟𝑎𝑑/𝑠𝑒𝑐
𝑃(𝑠) = = [ ]
𝑉(𝑠) (𝐽𝑠 + 𝑏)(𝐿𝑠 + 𝑅) + 𝐾 2 𝑉
And
𝐾𝐼 𝐾𝐷 𝑠 2 + 𝐾𝑃 𝑠 + 𝐾𝐼
𝐶(𝑠) = 𝐾𝑃 + + 𝐾𝐷 𝑠 =
𝑠 𝑠
a. For the proportional controller with a gain of KP =100, that is, C(s) =
100. Determine the closed-loop transfer function. Using MATLAB,
plot the step response (overshoot, settling time, steady state) for
proportional controller KP = 100.
Code
clc;
close all;
clear all;
J = 3.2284E-6;
b = 3.5077E-6;
k = 0.0274;
Page | 11
R = 4;
L = 2.75E-6;
s = tf('s');
Kp = 100;
C(:,:,1) = pid(Kp);
t = 0:0.001:0.2;
P_motor = k/(s*((J*s+b)*(L*s+R)+k^2));
sys_cl = feedback(C*P_motor,1);
step(sys_cl,t)
Graph
Page | 12
b. Add an integral term that will eliminate the steady-state error to a
step reference and also a derivative term that will reduce the
overshoot. Show the resulting PID controller with small KI and KD.
Code
clc;
close all;
clear all;
Kp = 100;
Ki = 10;
Kd = 0.3;
C(:,:,1) = pid(Kp,Ki,Kd);
sys_cl = feedback(C*P_motor,1);
t = 0:0.001:0.1;
step(sys_cl(:,:,1), t)
ylabel('Position, \theta (radians)')
title('Step Response with K_p = 100, K_i = 10 and K_d = 0.3')
legend('Kd=0.3 ')
Graph
c. Increase the integral gain to eliminate the steady state for tuning the
gains. Did you get the overshoot increased or not? Justify. How can
Page | 13
you reduce overshoot? Explain if your PID controller design has met
your requirements or not. If met, specify KP, KI, and KD.
Code
clc;
close all;
clear all;
Kp = 100;
Ki = 500;
Kd = 0.3;
C(:,:,1) = pid(Kp,Ki,Kd);
sys_cl = feedback(C*P_motor,1);
t = 0:0.001:0.1;
step(sys_cl(:,:,1), t)
ylabel('Position, \theta (radians)')
title('Step Response with K_p = 100, K_i = 10 and K_d = 0.3')
legend('Kd=0.3 ')
Graph
Page | 14
i. With Noise
Simulation
Graph
Page | 15
ii. Without Noise
Simulation
Graph
Page | 16
Part 2
Design a PID Motor position controller for DC motor position with a 1-
rad/sec step reference and the design criteria are the following:
Settling time less than 0.040 seconds
Overshoot less than 16%
No steady-state error, even in the presence of a step disturbance input
The structure of the control system has the form shown in Figure 2 below. The open-loop transfer
functions of the DC Motor system are the same as above in part I.
Page | 17
end
P_motor = k/(s*((J*s+b)*(L*s+R)+k^2));
sys_cl = feedback(C*P_motor,1);
t = 0:0.001:0.2;
step(sys_cl(:,:,1), sys_cl(:,:,2), sys_cl(:,:,3), t)
ylabel('Position, \theta (radians)')
title('Response to a Step Reference with Different Values of K_p')
legend('Kp = 1', 'Kp = 11', 'Kp = 21')
Graph
Page | 18
b.
i. Consider the system's response to a step disturbance. For this, the
feedback command can still be employed for generating the
closed-loop transfer function where there is still negative
feedback, however, now only the plant transfer function P(s) is in
the forward path and the controller C(s) is considered to be in the
feedback path. Plot the step response for P K = 1, 11, and 21.
Code
clc;
close all;
clear all;
J = 3.2284E-6;
b = 3.5077E-6;
k = 0.0274;
R = 4;
L = 2.75E-6;
s = tf('s');
Kp = 6;
Ki = 2;
C(:,:,1) = pid(Kp,Ki);
t = 0:0.001:0.2;
P_motor = k/(s*((J*s+b)*(L*s+R)+k^2));
sys_cl = feedback(1,C*P_motor);
step(sys_cl,t)
Graph
ii. Design PI controller to get rid of the steady-state error due to the
disturbance. Consider P K = 21 and test integral gains I K
Page | 19
ranging from 100, 300, and 500. Plot the step disturbance
response and explain the results.
Code
Kp = 21;
Ki = 100;
for i = 1:5
C(:,:,i) = pid(Kp,Ki);
Ki = Ki + 200;
end
sys_cl = feedback(C*P_motor,1);
t = 0:0.001:0.4;
step(sys_cl(:,:,1), sys_cl(:,:,2), sys_cl(:,:,3), t)
ylabel('Position, \theta (radians)')
title('Response to a Step Reference with K_p = 21 and Different Values of K_i')
legend('Ki = 100', 'Ki = 300', 'Ki = 500')
Graph
Page | 20
Part-III
Page | 21
ERROR AMPLIFIER. A classic circuit for calculating the error is a summing op amp. In the
controller, performs the error calculation. Remembering that the summing amp is an inverting
amp, we calculate its output using R1 = R2 = R3 = 10 kΩ.
But how does the summer calculate a difference. Well, it does require that your sensor circuit
produce a negative output voltage. Assuming that Vsensor is the negative of the actual sensor
voltage Vsen = - Vsen you get the difference.
Ve = -( Vs - Vsen )
We can look at the error amp's function this way. When Vsen is exactly the negative of Vs, the
currents through R1 and R2, equal and opposite, cancel each other as they enter the op amps's
summing junction. We end up with zero current through R3 and of course 0V, or zero error, at the
output. Any difference between Vs and -Vsen, results in an error voltage at the output that the PID
controller can act upon.
Result:
15V
10V
5V
0V
-5V
-10V
-15V
0s 0.5ms 1.0ms 1.5ms 2.0ms 2.5ms 3.0ms 3.5ms 4.0ms 4.5ms 5.0ms 5.5ms 6.0ms 6.5ms 7.0ms 7.5ms 8.0ms 8.5ms 9.0ms 9.5ms 10.0ms
V(U5A:OUT) V(R1:2) V(Vin) V(R9:2)
Time
Page | 22
inherently a high pass filter. It can amplify unwanted noise and noise that causes an erratic drive
signal. To reduce this undesirable effect, the resistor RC limits the high frequency gain to Gmax =
RD / RC. To further reduce high frequency amplification, many circuits include a feedback cap
CF over RD. With CF, the circuit looks like a low-pass filter at higher frequencies. For a good
starting point, select CF = CD / 10. The derivative circuit keeps it stable. The classic differential
amplifier for operational amplifiers can ring or oscillate if the resistor is not present. This resistance
reduces the phase shift caused by RD and CD, especially at high frequencies where circuit stability
can be compromised. The capacitor CF offers an additional advantage in providing stability to the
differentiator. In addition, CF helps the differentiator to recover if its output to the supply rails is
overdriven.
Conclusion:
In this lab we can see that the signal increase or decrease of the signal or the step response of the
signal depends on the values of Kp, Ki and Kd. By adding noise we can see that there is no
stationary state, but without noise there is a stable state. , The reason why PID is preferred is that
both functions are provided simultaneously. A number of practical questions were discussed.
Simple controllers such as the PI and PID controllers are of course not suitable for all processes.
The PID controller is suitable for processes with almost monotonous step responses, provided the
requirements are not too stringent.
Page | 23