CEP - Report - CS (LAB) FA18-BCE-112-032-B

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 27

COMSAT University Islamabad, Lahore campus

Department of Electrical and Computer Engineering

Control Systems LAB


“The Coupled Tanks Apparatus’’

Complex Engineering Problem

Submitted By: Farhan Amin, Sadeed Waseem

Registration No: FA18-BCE-112, FA18-BCE-032

Submitted To: Sir Sarmad Hassan

Submission Date: 21/06/2021


Table of Contents
1. Introduction ........................................................................................................................... 3
2. Objectives ............................................................................................................................... 3
3. Expected Outcomes ............................................................................................................... 3
4. Block Diagram ....................................................................................................................... 4
5. Methodology ........................................................................................................................... 4
6. Experiments & Results .......................................................................................................... 5
7. Conclusion ............................................................................................................................ 22
8. References............................................................................................................................. 22
9. Code ...................................................................................................................................... 22
1. Introduction
The coupled tanks apparatus consists of a transparent container divided into two tanks by a
center partition. Water is pumped from the reservoir into the first tank by a variable speed pump.
Holes at the base of the partition allow fluid flow between the two tanks. Some or all of the hole
can be blocked using the rubber bungs provided to change the degree of coupling between the
two tanks. The water which flows into the second tank is allowed to drain out through an
adjustable tap.

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

Figure 1: Coupled Tanks Apparatus

Figure 2: Simulink 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.

6. Experiments & Results


Results of all the performed experiments are as follows

Open loop Step response & Parameters:

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:

P-Controller Step Response & Parameters:


After Performing Theoretical Values of implementing P-Controller, We can see that it
achieves risetime earlier as compared to open loop transfer function but also It results in more
Overshoots as we can see in Performance Parameters

PI-Controller Step Response & Parameters:

After Performing Calculation & Implementing PI Controller in Open-Loop Transfer


function the gain of Integral (Ki) helps us to reduce the steady state error but also, It leads us to
the unstable system As Nan Percentage Overshoot in performance parameter.

PID-Controller Step response & Parameters before Tuning:


Here, We just added theoretical values of PID and checked its response before tuning ,
and Observed that we get our steady-state error completely removed meanwhile Settling time is
also reduced to 70.7sec to 6.19sec and Risetime reduced from 13.2 to 0.51 but still it is not
achieving our required criteria. So, we need to perform some tuning.

PID-Controller Step response & Parameters after Tuning:


Here, After Performing PID Tuning we achieved our required criteria which was of
Percentage Overshoot <= 5% ; Settling Time <= 5sec So, It best Meets our achieved criteria.

Bode plot: Open loop:


Bode plot: P controller:

Bode plot: PI controller:


Bode plot: PID controller before tuning:

Bode plot: PID controller after tuning:


Root locus: Open Loop

Step Response:

Root locus: P Controller Loop


Step Response:

Root locus: PI Controller Loop

Step Response:
Root locus: PID Controller Loop before tuning

Step Response:

Root locus: PID Controller Loop after 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

COUPLED TANKS APPARATUS. (n.d.). Retrieved from https://www.tecquipment.com/coupled-tanks-


apparatus

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 (A) : Find Transfer Function & Step Response of System


s = tf('s');
G_OPEN=((1/k2)/(((A^2)/(k1*k2))*s^2+((A*((0.2*k1)+k2))/(k1*k2))*s+1)); %
open-loop transfer function G(s)
step(G_OPEN)
title('Step for Open Loop tf G(s)');

% PART (B) : Find Performance Parameter of G_Open in Part (A),


(tr,ts,tp,P.O,SSE)
G = stepinfo(G_OPEN);
fprintf('Rise Time: %.2f\n',G.RiseTime); % tr = Rise Time
fprintf('Peak Time: %.2f\n',G.PeakTime); % tp = Peak Time
fprintf('Settling Time: %.2f\n',G.SettlingTime); % ts = Settling Time
fprintf('Percent Overshoot: %.2f\n', G.Overshoot);% P.O = Percentage
Overshoot
fprintf('Steady State Error: %.2f\n\n', abs(dcgain(1-G_OPEN))); % SSE =
Steady-State Error

% 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 (E) : Find Performance Parameter of Closed Loop tf in Part (C),


(tr,ts,tp,P.O,SSE)
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)
switch loop
case 1
fprintf('Parameters For P-Controller :-');
case 2
fprintf('Parameters For PI-Controller :-');
case 3
fprintf('Parameters For PID-Controller before Tuning:-');
case 4
fprintf('Parameters For P-Controller after Tuning:-');
end
Closed = stepinfo(G_Closed);
fprintf('Rise Time: %.2f\n',Closed.RiseTime); % tr = Rise Time
fprintf('Peak Time: %.2f\n',Closed.PeakTime); % tp = Peak Time
fprintf('Settling Time: %.2f\n',Closed.SettlingTime); % ts = Settling Time
fprintf('Percent Overshoot: %.2f\n', Closed.Overshoot);% P.O = Percentage
Overshoot
fprintf('Steady State Error: %.2f\n\n', abs(dcgain(1-G_Closed))); % SSE =
Steady-State Error
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

% PART (H) : Design compensator of Open Loop G(s) to improve stability of


System
%(to make P.O <= 5%,Ts <=5sec)
% We Will perform implementation of compensator design on sisotool
sisotool(G_OPEN)

You might also like