Professional Documents
Culture Documents
CEP - Report - CS (LAB) FA18-BCE-112-032-B
CEP - Report - CS (LAB) FA18-BCE-112-032-B
CEP - Report - CS (LAB) FA18-BCE-112-032-B
2. Objectives
• Implement the given Open Loop System on MATLAB / SIMULINK
• Plot the step response of the provide system
• Measure the performance parameters (tr, tp, ts, P.O, sse)
• Design P, PI and PID controllers according to given conditions, plot their response and
measure its parameters (tr, tp, ts, P.O, sse).
• Construct the Bode plot of the Open / Closed Loop systems also find their gain and phase
margin
• Construct the root locus of all the systems
• Design a compensator for the Open Loop System to improve the stability of the system.
3. Expected Outcomes
• The system should meet the given requirements i.e. The settling time should be ≤ 5 and
Percentage Overshoot (P.O) ≤ 5%
• All three controllers will have different outcomes since they have vastly different step
responses
• Bode Plots and Root Loci should be different across the three controllers
• System stability will be achieved through SISO tool using the compensator GUI.
4. Block Diagram
5. Methodology
• We Implement the given Open Loop system in MATLAB to calculate its transfer function
and plot its step response.
• Using the calculated Step Info and Steady State Error Formula we can then find parameters
like Settling Time, Rise Time, Percentage Overshoot, Steady State Error and Peak Time of
the Open Loop System
• To achieve the given criteria we had to implement the three controllers i.e Proportional (P)
Controller, Proportional Integral (PI) Controller and Proportional Integral Derivative (PID)
controller.
• We use the P-Controller to decrease our steady state error, but its only able to reduce the error
instead of eliminating it.
• Using the PI controller next we are able to eliminate the Steady State Error but in doing
so we increase the settling time
• Finally using the PID controller we are able to get the required results since it eliminates
the Steady State Error, decreases the Settling Time and provides the right overshoot.
• We then calculate the Step Response of all the implemented controllers (P, PI, PID) and the
closed loop system
• We calculate the root locus and bode plot of all the controllers i.e. P, PI and PID and the
close loop system.
• We then find the Gain and Phase margins of Open and Closed loop systems
• Finally, we use the SISO tool to improve the stability of the Open Loop System by designing
a Lead Compensator. We had to use a Lead compensator since there are no breakaway /
break in points in the root locus due to which K becomes unstable.
Here, we can see the open loop step response of the system with some presence steady-
state error and more Percentage-Overshoot exists.
Simulink:
Here, We perform pid tuning to get our desired criteria and hence we recognized values ,
Kp = 1199.57 , Ki = 590.57 , Kd = 1109.81
Controllers:
Step Response:
Step Response:
Root locus: PID Controller Loop before tuning
Step Response:
Compensator Design:
Theoretical Work:
7. Conclusion
We designed and implemented three different controllers P, PI, PID. These controllers were
designed to help meet the required criteria. P-Controller was the first to be implemented but it
wasn't useful for our purpose since it will decrease rise time but it will also increase overshoot, So it
will not achieve the criteria for Settling Time and P.O, with that done we switched to a PI-Controller
implementation and recognized that steady-state error is removed but it will not give any other
performance parameters but it helps to decrease the settling time and still it is not achieving our
desired criteria, then we had to switch to a PID-Controller by doing Comparative Analysis it helps us
to reduce overshoot, decrease settling time and remove steady-state error but, It was not in the
desired range so we need to perform little bit tuning. After tuning, it achieved all the given criteria,
decreasing the overshoot and eliminating the Steady State Error. To stabilize the Open Loop System,
The Lead compensator is then used in sisotool.
8. References
Bose, V. (2020, February 10). Introduction to PID Controller With Detailed P,PI,PD & PD Control.
Retrieved from https://vivekbose.com/introduction-to-pid-controller-with-detailed-ppipd-pd-
control
Libretexts. (2021, March 05). 9.2: P, I, D, PI, PD, and PID control. Retrieved from
https://eng.libretexts.org/Bookshelves/Industrial_and_Systems_Engineering/Book:_Chemical_Proce
ss_Dynamics_and_Controls_(Woolf)/09:_Proportional-Integral-
Derivative_(PID)_Control/9.02:_P,_I,_D,_PI,_PD,_and_PID_control
9. Code
% % CS LAB CEP
% % NAME = FARHAN AMIN , REG NO = FA18-BCE-112-B
% % NAME = SADEED WASEEM , REG NO = FA18-BCE-032-B
clc;
clear all;
close all;
% given
Cdo=0.4;
Cd12=0.6;
A=100;
Ho=3;
g=980;
Qo=2.5;
Q12=2.5;
% derived
a12 = pi*((0.635/2)^2)+pi*((0.317/2)^2)
a0 = pi*((0.635/2)^2)
H2 = ((Qo^2)/((Cdo^2)*(a0^2)*2*g))+Ho
H1 = ((Q12^2)/((Cd12^2)*(a12^2)*2*g))+H2
k1 = (Cd12*a12*sqrt(2*g))/(2*sqrt(H1-H2))
k2 = (Cdo*a0*sqrt(2*g))/(2*sqrt(H2-Ho))
% PART (C) : Design P,PI,PID controller to make P.O <= 5%,Ts <=5sec
length = 4;
Kp(1:length) = [578.57 1199.57 1199.57 322.20];
Ki(1:length) = [0 590.27 590.27 16.79];
Kd(1:length) = [0 0 1109.815 1083.32];
for loop=1:length
num = [Kd(loop) Kp(loop) Ki(loop)];
den = [0 1 0];
PID_Controller = tf(num,den);
G_Closed = feedback(G_OPEN*PID_Controller,1)
if loop == 4
fprintf('Closed Loop TF after Tuning');
else
fprintf('Closed Loop TF before Tuning');
end
end
% PART (D) : Design P,PI,PID controller to make P.O <= 5%,Ts <=5sec
for loop=1:length
num = [Kd(loop) Kp(loop) Ki(loop)];
den = [0 1 0];
PID_Controller = tf(num,den);
G_Closed = feedback(G_OPEN*PID_Controller,1)
fprintf('Closed Loop Controllers Response before Tuning');
figure;
step(G_Closed)
switch loop
case 1
title('Step for P-Controller');
case 2
title('Step for PI-Controller');
case 3
title('Step for PID-Controller before Tuning');
case 4
title('Step for PID-Controller after Tuning');
end
end
% PART (F) : Bode plot of Open & Closed loop System in Part (A) & Part (C)
% For Open - Loop System
figure;
bode(G_OPEN)
title('Bode Plot for Open Loop tf G(s)');
[Gm1,Pm1] = margin(G_OPEN);
fprintf('Gain Margin Open loop tf G(s): %.2f\n\n', Gm1); % Gm = Gain Margin
fprintf('Phase Margin Open loop tf G(s): %.2f\n\n', Pm1); % Pm = Phase Margin
% For Closed - Loop System
for loop=1:length
num = [Kd(loop) Kp(loop) Ki(loop)];
den = [0 1 0];
PID_Controller = tf(num,den);
G_Closed = feedback(G_OPEN*PID_Controller,1)
fprintf('Closed Loop Controllers Bode Plot before Tuning');
figure;
bode(G_Closed)
switch loop
case 1
title('Bode Plot for P-Controller');
[Gm1,Pm1] = margin(G_Closed);
fprintf('Gain Margin of P-Controller G(s): %.2f\n\n', Gm1); % Gm = Gain
Margin
fprintf('Phase Margin of P-Controller G(s): %.2f\n\n', Pm1); % Pm = Phase
Margin
case 2
title('Bode Plot for PI-Controller');
[Gm1,Pm1] = margin(G_Closed);
fprintf('Gain Margin of PI-Controller G(s): %.2f\n\n', Gm1); % Gm = Gain
Margin
fprintf('Phase Margin of PI-Controller G(s): %.2f\n\n', Pm1); % Pm =
Phase Margin
case 3
title('Bode Plot for PID-Controller before Tuning');
[Gm1,Pm1] = margin(G_Closed);
fprintf('Gain Margin of PID-Controller before tuning G(s): %.2f\n\n',
Gm1); % Gm = Gain Margin
fprintf('Phase Margin of PID-Controller before tuning G(s): %.2f\n\n',
Pm1); % Pm = Phase Margin
case 4
title('Step for PID-Controller after Tuning');
[Gm1,Pm1] = margin(G_Closed);
fprintf('Gain Margin of PID-Controller after tuning G(s): %.2f\n\n',
Gm1); % Gm = Gain Margin
fprintf('Phase Margin of PID-Controller after tuning G(s): %.2f\n\n',
Pm1); % Pm = Phase Margin
end
end
% PART (G) : Root - Locus plot of Open & Closed loop System in Part (A) &
Part (C)
% For Open - Loop System
figure;
rlocus(G_OPEN)
title('Root-Locus Plot for Open Loop G(s)');
axis([-2 3 -1.5 1.5])
sgrid(0.69,1.14) %zeeta = 0.69 , Wn = 1.14
[K,poles]=rlocfind(G_OPEN)
Closed_System=feedback(K*G_OPEN,1)
step(Closed_System)
title('Roots Location Step for Open Loop tf G(s)');
% For Closed - Loop System
for loop=1:length
num = [Kd(loop) Kp(loop) Ki(loop)];
den = [0 1 0];
PID_Controller = tf(num,den);
G_Closed = feedback(G_OPEN*PID_Controller,1)
figure;
rlocus(G_Closed)
switch loop
case 1
title('Root-Locus Plot for Closed Loop G(s) for P-Controller');
case 2
title('Root-Locus Plot for Closed Loop G(s) for PI-Controller');
case 3
title('Root-Locus Plot for Closed Loop G(s) for PID-Controller before
Tuning');
case 4
title('Root-Locus Plot for Closed Loop G(s) for PID-Controller after
Tuning');
end
axis([-2 3 -1.5 1.5])
sgrid(0.69,1.14) %zeeta = 0.69 , Wn = 1.14
[K,poles]=rlocfind(G_Closed)
Closed_System=feedback(K*G_Closed,1)
step(Closed_System)
switch loop
case 1
title('Roots Location Step for Closed Loop tf G(s) for P-Controller');
case 2
title('Roots Location Step for Closed Loop tf G(s) for PI-Controller');
case 3
title('Roots Location Step for Closed Loop tf G(s) for PID-Controller
before Tuning');
case 4
title('Roots Location Step for Closed Loop tf G(s) for PID-Controller
after Tuning');
end
end