0% found this document useful (0 votes)
14 views12 pages

PID Controller Design in MATLAB

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
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views12 pages

PID Controller Design in MATLAB

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
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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([Link])]);
disp(['Overshoot: ', num2str([Link])]);
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([Link])]);
disp(['Overshoot: ', num2str([Link])]);
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([Link])]);
disp(['Overshoot: ', num2str([Link])]);
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([Link])]);
disp(['Overshoot: ', num2str([Link])]);
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

Common questions

Powered by AI

The distinguishing factors between using a PID controller versus a Lag-Lead compensator lie primarily in their approach to optimizing transient and steady-state performance. A PID controller is versatile, incorporating proportional, integral, and derivative terms to control a system's response comprehensively, allowing fine-tuning of rise time, overshoot, and eliminating steady-state error. It is well-suited to applications requiring a balance between all these factors, though it requires careful tuning to avoid overshoot and instability. Conversely, a Lag-Lead compensator offers targeted improvements: the lag part reduces steady-state error by introducing low-frequency poles, and the lead part improves transient response and stability by advancing phase margins at higher frequencies. This compensator is advantageous in systems that need a precise phase adjustment to stabilize and accelerate the response without an extensive tuning process .

The constraints on settling time and overshoot in Lab 10 design problems significantly influence the choice of controller type for the system \( \frac{1}{s^2 + 10s + 20} \). For instance, problems requiring a settling time less than 0.5 seconds and overshoot of less than 10% necessitate a PID controller due to its ability to finely tune rise time, damping, and steady-state error elimination. Conversely, if the design constraints are less stringent, as with a settling time of less than 2 seconds and no specific steady-state error condition, a simpler P or PI controller might suffice. The PID controller's flexibility allows for better handling of complex requirements without compromising stability, making it suitable for stringent conditions .

The Root Locus plays a crucial role in determining the stability and dynamics of a control system during controller design by showing how the system's poles change with variations in a specific parameter, typically the gain. It provides insights into system stability by indicating whether these poles move into the stable region (left half of the complex plane) as the gain changes. By analyzing the Root Locus plot, designers can assess the effects of different controller configurations on pole locations, enabling them to choose appropriate gains that meet desired performance criteria like settling time, overshoot, and stability margins observed in Lab 10's examples. Controller design often uses Root Locus to optimize stability and transient response .

Design problem-specific constraints, such as those in Lab 10 problem statements, dictate the modification of mathematical frameworks or equation forms used in synthesizing controllers like PID. For example, achieving a settling time of less than 0.5 seconds may necessitate adjusting gain values and zero/pole placements within the PID equation. Such constraints influence whether an integral action should be included to eliminate steady-state error or if a derivative term is needed to enhance damping. This guidance results in dynamically adjusting the controller's transfer function, considering the system's open-loop transfer function. This tailored manipulation of mathematical forms ensures that the synthesized controller precisely meets the specified requirements in terms of transient and steady-state performance .

The parallel connection of different PID components (P, I, D) allows for independent tuning of each component, directly impacting the system's ability to meet specified design criteria in Lab 10's five design problems. This configuration permits precise manipulation of each component's effect on the system's performance. The proportional component addresses overall gain and responsiveness. The integral component reduces or eliminates steady-state error, ensuring accuracy. The derivative component anticipates future error by damping oscillations, reducing overshoot and improving settling times. By parallelizing PID components, it is possible to synergistically meet multifaceted design specifications such as short settling times, low overshoot, and zero steady-state error relevant to each problem .

Ensuring zero steady-state error typically involves implementing integral control action in PID controllers (as seen in PI and PID controllers). While achieving zero steady-state error improves accuracy, it can influence system stability and performance criteria specified in Lab 10, such as settling time and overshoot. Integral action drives the error to zero over time, which can introduce additional poles. These poles necessitate careful tuning to prevent instability, such as increased overshoot or prolonged settling time. Therefore, achieving this balance means iteratively adjusting controller gains to meet specified performance requirements like settling time less than two seconds and overshoot less than 20% while maintaining system stability .

Adjusting the gains of a PID controller affects the system's transient response characteristics differently for each parameter. Increasing the proportional gain (Kp) generally decreases the rise time and increases overshoot, with minimal effects on the settling time. It tends to make the system more responsive but at the risk of potential instability. The integral gain (Ki) reduces the steady-state error and affects the rise time minimally, but can increase the overshoot and settling time significantly, as it introduces an additional pole. The derivative gain (Kd) helps in reducing the overshoot and settling time while having a negligible impact on the rise time. It anticipates future errors by considering the rate of error change, hence improving system stability by damping oscillations.

The placement of zeros in PD and PI controllers significantly influences the system's transient response. For a PD controller, strategically placing zeros (e.g., using zero_loc = -20) allows for damping of the system, thereby reducing overshoot and improving settling time by providing a quick corrective action to the error signal. This effectively adds gain at higher frequencies, helping in achieving a faster transient response. In contrast, zeros in a PI controller (e.g., zero_loc = -2) are used to improve the transient response by placing them near the origin. This configuration helps to speed up the response and reduce the overshoot, while also ensuring zero steady-state error, as the integral component addresses errors over time .

Using a MATLAB tool like pidtune simplifies the PID controller design process by automating the tuning of controller parameters based on specified performance criteria like rise time, settling time, and overshoot. This approach contrasts with manual tuning methods, which require iterative trial-and-error adjustments of Kp, Ki, and Kd gains to meet performance specifications often based on empirical rules and transient response plots. The potential benefits of using pidtune include increased efficiency, consistency, and accuracy in achieving stable controller settings quickly, as it mathematically determines the optimal parameters based on the plant model and desired performance characteristics, thereby minimizing the risk of human error .

In a control system, a Lag-Lead compensator is designed to reduce steady-state error while simultaneously improving the response speed. The lag component reduces the steady-state error by shifting the system poles to achieve a more favorable balance of phase and gain, usually by placing a zero far to the left of the imaginary axis. However, the introduction of additional poles can initially slow the response. The lead component helps to counteract this by advancing the phase margin, which improves stability and allows for faster system response. The balance between speed and accuracy is achieved by carefully tuning the compensator parameters to meet the overall design specifications .

You might also like