You are on page 1of 23

Lab

09
ECE 329 Automatic Control Lab

Professor: ABC

By:
XYZ

Date:12/07/2018

PID Control System Design, Simulation, and


Implementation (II)
Abstract
Page | 1
In this lab 9, it was about Design a PID Motor position controller for DC motor position with a 1-rad/sec
step reference. we will consider the transient response of the system using a PID controller. We used
MATLAB’s PID controller object to generate an equivalent continuous-time controller. Also, we used
Simulink to make sure about our result. So, this report includes all the procedure that we did for this lab
and the results it contain coding as well as simulations.

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

Abstract ..........................................................................................Error! Bookmark not defined.


Acknowledgment ............................................................................................................................ 3
List of illustrations .......................................................................................................................... 5
Objectives: .....................................................................................Error! Bookmark not defined.
Introduction and Background Theory: ...........................................Error! Bookmark not defined.
PartI Results: ................................................................................................................................. 12
PartII results: ................................................................................................................................. 16
Conclusion: ................................................................................................................................... 21
index.............................................................................................................................................. 22

Page | 4
List of illustrations

Figure number Title Page number


Figure 1 Diagram of a PID 6

Figure 2 Block Diagram 11


Figure 3 Step Response 12
Figure 4 Step Response 13

Figure 5 Step Response for Kd=0.3 14


Figure 6 Simulation Without Noise 12
Figure 7 Results without Noise 16
Figure 8 Simulation Without Noise 16
Figure 9 Results without Noise 17
Figure 10 Step Response 17
Figure 11 Step Response 18
Figure 12 Step Response 19
Figure 13 Step Response 20
Figure 14 Step Response 21

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.

Fig. 1 PID Diagram


Since the PID controller consists of three blocks: proportional, integral, derivative. The equation
governing the PID controller is as follows
𝑑𝑒(𝑡)
𝑢(𝑡) = 𝑃. 𝑒(𝑡) + 𝐼. ∫ 𝑒(𝑡)𝑑𝑡 + 𝐷.
𝑑𝑡
𝑒(𝑡) = 𝑦𝑑𝑒𝑠𝑖𝑟𝑒𝑑 (𝑡) − 𝑦(𝑡)
With the means of the Laplace transform, such a structure can be represented as a transfer function.
1
𝑈(𝑠) = (𝑃 + + 𝐷. 𝑠) . 𝐸(𝑠)
𝑠
𝑈(𝑠) 1
𝐶(𝑠) = = 𝑃 + + 𝐷. 𝑠 = 𝐷𝑠 2 + 𝑃𝑠 + 1
𝐸(𝑠) 𝑠
Each of the PID controller blocks plays an important role. However, for some applications, the integral or
derivative part must be excluded to obtain satisfactory results.

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

Parameter Rise time Overshoot Settling Steady State Stability


Time Error
𝑲𝒑 Decrease Increase Small Change Decrease Degrade
𝑲𝒊 Decrease Increase Increase Eliminate Degrade
𝑲𝒅 Minor Change Decrease Decrease No effect Improve if 𝑲𝒅 small

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.

Effects of the Various Components


PID controllers are very commonly used to control processes, since they offer numerous desirable
improvements in the performance of a process. Some of these are:
• They are a very effective way to adjust the transient performance of a system, as each of the three
parts of the controller has a large effect on the system's time response characteristics.
• They work well to reduce or eliminate any steady state errors in the system.
• This controller class is robust enough to reduce or eliminate the effect of unwanted external noise
in the system output.
A PID controller has three parts; In a closed loop feedback system, we have:
• The proportional controller determined by the KP parameter. The increase in this parameter has
the effect of reducing the rise time, increasing the overshoot, making small changes in the
installation time and reducing (but not generally eliminating) the constant state error of the
system.
• The integrated controller determined by the KI parameter. Increase this parameter has the effect
of reducing the rise time, increasing the overshoot, generally increases the settling time (but at the
cost of adding a certain degree of instability to the system, manifested as an oscillation in the
transient response) and causes the error due to an external disturbance to fall to zero faster. This
term is also used to eliminate the constant state error of the system.
• The differential controller determined by the KD parameter. Increasing this parameter has the
effect of increasing the rise time, reducing overshoot and reducing installation time. This term
generally has little or no effect even on the steady state error of the system and generally causes
small increases in system stability.

Tuning the PID Controller Parameters


The process of establishing the optimal gains for P, I and D to get an ideal response from a control system
is called adjustment. There are several PID regulation techniques. Most of the time Ziegler-Nichols rules
are used or a forwarding experiment is performed. Very often, the roots of the closed loop system are
analyzed and established in the desired position by the appropriate selection of the values P, I and D.
MATLAB provides a root position tool, which helps in such projects.

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.

Additional MATLAB Tools for PID Design


There are several tools available in MATLAB to further aid in the design and regulation of PID circuits.
Some of them are mentioned below; you can consult them more thoroughly using the HELP MATLAB
menu. But we will not use them in this laboratory exercise.
• We can use the MATLAB PID controller object to generate an equivalent continuous time
controller as follows:
Write down the command

𝐶 = 𝑝𝑖𝑑(𝐾𝑝 , 𝐾𝑖 , 𝐾𝑑 );

To find out transfer function, we write


𝐺𝑐 = 𝑡𝑓(𝐶);
As before, the names of the variables used here (C, Gc, etc.) are not correct, and you can use the names of
the variables you want.

 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 + 𝐾𝑃 𝑠 + 𝐾𝐼
𝐶(𝑠) = 𝐾𝑃 + + 𝐾𝐷 𝑠 =
𝑠 𝑠

Figure.2 Block Diagram

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

Figure.3 Step Response

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

Figure.4 Step Response

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

Figure.5 Step Response for Kd=0.3

d. Implement the above PID controller in Simulink with and without


considering torque disturbances and noise. Also, build an emulation
circuit for the PID controller using a PSpice circuit based on your
PID design that meets your design requirement. For a sample of
PSpice implementation, refer to Lab 9 Appendix.

Page | 14
i. With Noise
Simulation

Figure.6 With Noise Simulation

Graph

Figure.7 With Noise Results

Page | 15
ii. Without Noise
Simulation

Figure.8 Without noise Simulation

Graph

Figure.9 Without Noise 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.

Figure.10 Block Diagram

a. Generate the closed-loop transfer function using a proportional


controller with gain ranging from KP = 1, 11 and 21, and plot their step
responses.
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 = 1;
for i = 1:3
C(:,:,i) = pid(Kp);
Kp = Kp + 10;

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

Figure.11 step response for different value ok Kp

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

Figure.13 Step Response

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

Figure.14 Step response for Different Ki

Page | 20
Part-III

Design a PID Motor position controller for DC motor position using


Pspice:

P -Proportional, I - Integral, D - Derivative. These expressions describe three basic


mathematical functions that are applied to the error signal, Ver = Vs - Vsen. This error represents
the difference between the target (Vs) and the actual target (Vsen). The controller performs the
mathematical PID functions for the error and applies the sum to a process (motor, heater, etc.). So
easy and yet so powerful! If tuned correctly, the Vsen signal should approach Vs.
When tuning a system, three multipliers Kp, Ki, and Kd must be adjusted by adding various
functions of these functions to make the system behave as desired. The following table summarizes
the PID conditions and their effects on a tax system.

Figure 15: PID Using P_Spice

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Ω.

Ve = - (Vs / R1 + Vsen / R2) ∙ R3


= (Vs + Vsen) ∙ (10 k / 10 k)
= - ( Vs + Vsen )

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

Figure 16:P_Spice Result


To make the PID controller more realistic, a voltage clamp has been added to the op amp model.
Attaching zener diodes to the model simulates the output with a maximum of ± 10V. Why add this
feature? Without the clamp, the simulated PID terms can generate hundreds of volts to control the
output. This can lead to disappointing results if the actual PID outputs get stuck near the supply
rails. You can see if PID expressions hit the rail by drawing V (6), V (9) and V (11). The circuit is

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

You might also like