Control Systems Lab 10
Control Systems Lab 10
Lab Viva
Student name Reg. No. report Marks Total/15
Marks / 10 Marks / 5
Muhammad Saad 403474
Kashif
(Prepared and
uploaded by)
Abdullah Munir 413132
1. Objectives
We will illustrate the process of designing a PID controller with the help of an example.
The system that we will consider is given below:
1
(1)
(s2 + 10s + 20)
Settling time less than 2 seconds, %OS<20, and no conditions on the steady state error
for a step input.
Code:
clear clc
%% open loop system
sys= tf([1],[1 10 20]);
%% open loop system properties
stepinfo(sys) %step response information of the open loop system
abs(1-dcgain(sys)) %steady state error for a step input to the open
%loop system
Settling time less than 1 seconds, %OS<10, and no conditions on the steady state error
for a step input.
Code:
clear; clc;
%% Open loop system
sys = tf([1], [1 10 20]);
%% Root locus for Proportional Controller
figure;
rlocus(sys);
title('Root Locus of Open Loop System');
grid on;
%% Choose Kp based on root locus analysis
Kp = 8; % Adjust this value to meet design criteria
%% Define Proportional Controller
ctrl = zpk([], [], Kp);
sys_cl = feedback(series(ctrl, sys), 1); % Closed-loop system
%% Step response analysis
stepinfo(sys_cl)
ess = abs(1 - dcgain(sys_cl));
disp(['Steady-state error: ', num2str(ess)])
%% Plot step response
figure;
step(sys_cl);
title('Closed-Loop Step Response with Proportional Controller');
grid on;
Settling time less than 0.5 second, %OS<10, and no conditions on the steady state
error for a step input.
EE-379: Control Systems, Lab 10 Page 4
Prepared by: Dr. Ammar Hasan
Code:
clear; clc;
%% Open loop system
sys = tf([1], [1 10 20]);
%% Root Locus for PD Controller
figure;
rlocus(sys);
title('Root Locus of Open Loop System');
grid on;
%% Choose PD controller parameters
zero_loc = -20; % Adjusted to optimize overshoot and settling time
Kd = 5; % Adjusted to reduce overshoot
Kp = -Kd * zero_loc; % Maintain stability
%% Define PD Controller
ctrl_p = zpk([], [], Kp); % Proportional part
ctrl_d = zpk(0, [], Kd); % Derivative part
ctrl = parallel(ctrl_p, ctrl_d); % Combined PD Controller
%% Closed-loop system
sys_cl = feedback(series(ctrl, sys), 1);
%% Step response analysis
info = stepinfo(sys_cl);
ess = abs(1 - dcgain(sys_cl));
%% Display only required response properties
disp(['Settling Time: ', num2str(info.SettlingTime)]);
disp(['Overshoot: ', num2str(info.Overshoot)]);
disp(['Steady-state error: ', num2str(ess)]);
%% Plot response
figure;
step(sys_cl);
title('PD Controller Step Response');
grid on;
Output:
Settling time less than 2 second, %OS<20, and zero steady state error for a step input.
Code:
clear; clc;
%% Open loop system
sys = tf([1], [1 10 20]);
%% Root Locus for PI Controller
figure;
rlocus(sys);
title('Root Locus of Open Loop System');
grid on;
Output:
Settling time less than 0.5 second, %OS<10, and zero steady state error for a step
input.
Code:
clear; clc;
%% Open loop system
sys = tf([1], [1 10 20]);
%% Choose PID controller parameters
zero_loc_pi = -1; % Choose close to origin
zero_loc_pd = -15; % Adjust based on trial
Kd = 30; % Adjust based on root locus
Kp = -(zero_loc_pd + zero_loc_pi) * Kd;
Ki = zero_loc_pd * zero_loc_pi * Kd;
%% Define PID Controller
ctrl_p = zpk([], [], Kp); % Proportional part
ctrl_i = zpk([], 0, Ki); % Integral part
ctrl_d = zpk(0, [], Kd); % Derivative part
ctrl = parallel(parallel(ctrl_p, ctrl_i), ctrl_d); % Combined PID Controller
%% Closed-loop system
sys_cl = feedback(series(ctrl, sys), 1);
%% Step response analysis
stepinfo(sys_cl)
ess = abs(1 - dcgain(sys_cl));
disp(['Steady-state error: ', num2str(ess)])
Output:
Code:
clear; clc;
%% Open loop system
sys = tf([1], [1 10 20]);
EE-379: Control Systems, Lab 10 Page 9
Prepared by: Dr. Ammar Hasan
%% Initial PID controller parameters (adjust these manually)
Kp = 40; % Adjusted for better performance
Ki = 100; % Increased to ensure zero steady-state error
Kd = 10; % Adjusted to reduce overshoot and improve stability
%% Define PID Controller
ctrl_p = zpk([], [], Kp); % Proportional part
ctrl_i = zpk([], 0, Ki); % Integral part
ctrl_d = zpk(0, [], Kd); % Derivative part
ctrl = parallel(parallel(ctrl_p, ctrl_i), ctrl_d); % Combined PID Controller
%% Closed-loop system
sys_cl = feedback(series(ctrl, sys), 1);
%% Step response analysis
info = stepinfo(sys_cl);
ess = abs(1 - dcgain(sys_cl));
%% Display only required response properties
disp(['Settling Time: ', num2str(info.SettlingTime)]);
disp(['Overshoot: ', num2str(info.Overshoot)]);
disp(['Steady-state error: ', num2str(ess)]);
%% Plot response
figure;
step(sys_cl);
title('Fine-Tuned PID Controller Step Response');
grid on;
Output:
Code:
clear; clc;
%% Open loop system
sys = tf([1], [1 10 20]);
%% Optimized Lag Compensator Design
zero_lag = -1; % Shift zero further left for better phase margin
pole_lag = -0.1; % Adjust pole to reduce steady-state error
gain = 100; % Increased gain for faster response
%% Define Lag Compensator
lag_compensator = zpk([zero_lag], [pole_lag], gain);
%% Closed-loop system with compensator
sys_cl = feedback(series(lag_compensator, sys), 1);
%% Step response analysis
info = stepinfo(sys_cl);
ess = abs(1 - dcgain(sys_cl)); % Steady-state error
%% Display required response properties
disp(['Settling Time: ', num2str(info.SettlingTime)]);
disp(['Overshoot: ', num2str(info.Overshoot)]);
disp(['Steady-state error: ', num2str(ess)]);
%% Plot response
figure;
step(sys_cl);
title('Optimized Lag Compensator Step Response');
grid on;
Output:
sisotool() %PID, lag lead or any other compensator desing. Also automatic PID design.
pidtune() %Automatic PID design. Only in newer versions of MATLAB
pidtool %Graphical tool for PID tuning. Only in newer versions of MATLAB
Conclusion:
In this lab, we focused on settling time, overshoot, and steady-state error while designing and
analyzing PI, PID, and Lag-Lead compensators to enhance system performance. We improved
the controllers' transient and steady-state performance by iteratively adjusting them after some of
the first designs failed to meet the necessary requirements. Lag compensators decreased steady-
state error but initially slowed the reaction, lag-lead compensators successfully balanced speed
and accuracy, and PID control increased response time but needed to be carefully adjusted to
prevent overshoot. This lab illustrated how crucial good controller design is to obtaining
accuracy, fast reaction, and stability in control systems.