0% found this document useful (0 votes)
5 views

Control Systems Lab 10

This document outlines Lab 10 for EE-379: Control Systems, focusing on PID controller design and implementation using MATLAB and LabVIEW. It details five design problems with specific performance criteria, provides MATLAB code for each design, and discusses the effects of tuning PID parameters. The conclusion emphasizes the importance of effective controller design for achieving desired system performance in terms of accuracy, response time, and stability.

Uploaded by

Saad Kashif
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Control Systems Lab 10

This document outlines Lab 10 for EE-379: Control Systems, focusing on PID controller design and implementation using MATLAB and LabVIEW. It details five design problems with specific performance criteria, provides MATLAB code for each design, and discusses the effects of tuning PID parameters. The conclusion emphasizes the importance of effective controller design for achieving desired system performance in terms of accuracy, response time, and stability.

Uploaded by

Saad Kashif
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

NUST School of Electrical Engineering and Computer Science

Faculty Member: Maam Neelma Naaz Date: 6-3-2025

Semester: 6th Section: BEE-14-A

Department of Electrical Engineering

EE-379: Control Systems

LAB 10: PID controller design

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

Rayyan Naeem 414044


Muzaffar

Sudais Akbar 403965


Khan

EE-379: Control Systems, Lab 10 Page 1


Prepared by: Dr. Ammar Hasan
LAB 10: PID controller design and implementation

1. Objectives

• Learn how to design a PID controller using MATLAB


• Learn how to implement a PID controller in LabVIEW

1.1 PID controller design

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)

We will look at five controller design problems


1) Settling time less than 2 seconds, %OS<20, and no conditions on the steady state
error for a step input.
2) Settling time less than 1 seconds, %OS<10, and no conditions on the steady state
error for a step input.
3) Settling time less than 0.5 second, %OS<10, and no conditions on the steady
state error for a step input.
4) Settling time less than 2 second, %OS<20, and zero steady state error for a step
input.
5) Settling time less than 0.5 second, %OS<10, and zero steady state error for a step
input.

Stability is required in all design problems

1.1.1 Design problem 1

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

EE-379: Control Systems, Lab 10 Page 2


Prepared by: Dr. Ammar Hasan
Output:

1.1.2 Design problem 2

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;

EE-379: Control Systems, Lab 10 Page 3


Prepared by: Dr. Ammar Hasan
Output:

1.1.3 Design problem 3

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:

EE-379: Control Systems, Lab 10 Page 5


Prepared by: Dr. Ammar Hasan
1.1.4 Design problem 4

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;

EE-379: Control Systems, Lab 10 Page 6


Prepared by: Dr. Ammar Hasan
%% Choose PI controller parameters
zero_loc = -2; % Adjusted for faster response
Kp = 25; % Increased to improve transient response
Ki = -Kp * zero_loc; % Ensures zero steady-state error
%% Define PI Controller
ctrl_p = zpk([], [], Kp); % Proportional part
ctrl_i = zpk([], 0, Ki); % Integral part
ctrl = parallel(ctrl_p, ctrl_i); % Combined PI 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('PI Controller Step Response');
grid on;

Output:

EE-379: Control Systems, Lab 10 Page 7


Prepared by: Dr. Ammar Hasan
1.1.5 Design problem 5

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)])

EE-379: Control Systems, Lab 10 Page 8


Prepared by: Dr. Ammar Hasan
%% Plot response
figure;
step(sys_cl);
title('PID Controller Step Response');
grid on;

Output:

1.1.6 Fine tuning your PID controller

Gain Rise time Overshoot Settling time Steady-state error


Kp Decrease Increase Small change Decrease
Ki Decrease Increase Increase Eliminate
Kd Minor Decrease Decrease No effect in theory
change
Table 1: Effects of increasing different gains of a PID controller

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:

EE-379: Control Systems, Lab 10 Page 10


Prepared by: Dr. Ammar Hasan
2. Lag lead compensator design
Exercise
Using MATLAB, design a lag lead compensator to meet the specifications of design
problem 5.

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:

EE-379: Control Systems, Lab 10 Page 11


Prepared by: Dr. Ammar Hasan
3. Some other ways to design controllers in MATLAB
MATLAB also offers some other commands and tools to design a controller. We will list
some of them here but we will not discuss how to use them. If you are interested, you
can refer to the MATLAB help for further details.

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.

EE-379: Control Systems, Lab 10 Page 12


Prepared by: Dr. Ammar Hasan

You might also like