2
Most read
v1.0 
Misr University for Science and Technology 
College of Engineering 
Mechatronics Lab 
PROCESS CONTROL MODULE 
PID TUNING AND STABILITY 
(MATLAB Simulation) 
Prof. Farid A. Tolbah 
Eng. Waleed A. El-Badry
v1.0 
1. Objective 
The experiment is aimed to make student acquainted with the preliminary steps to manually tune a PID controller for a plant model by means of MATLAB. 
2. Outcome 
 Writing mathematical models of plants under investigation in Laplace form using MATLAB. 
 Developing the mathematical Laplace representation of Ziegler-Nicholas PID controller in MATLAB. 
 Finding the critical gain (Kc) and the ultimate period (Pu) to calculate PID gains. 
3. Prerequisite 
Student should be familiar with the following terms: 
 Closed loop system. 
 System response. 
 PID controller 
 Ziegler-Nicholas tuning method. 
Also basic understanding of MATLAB syntax is preferred. 
4. The Closed loop system 
The below figure represents the generic closed loop system. 
Figure 1 Closed loop system 
For implementation in this experiment, we are given the following plant model Wp(s): 푊푝(푠)= 1(10푠+1)3= 11000푆3+300푠2+30푠+1 
And the Ziegler-Nicholas PID is formulated as: 푊푐(푠)=퐾푐(1+ 1 푇푖푠 +푇푑푠) 
Controller 
Plant 
Feedback 
FCE 
Set 
Point 
e(t) 
y(t) 
wc 
Current 
Level
v1.0 
Assuming unity feedback, redrawing the block diagram: 
Figure 2 Problem block diagram 
5. Developing MATLAB functions (Plant, Controller and Closed Loop) 
a. Launch MATLAB software. 
b. From the Home tab, select New -> Function. 
c. Write down the generic plant function as shown in the following snippet: 
function [ Wp ] = CreatePlant( num,den ) 
%CreatePlant Creates plant transfer function. 
% The returned value is the system in numerator/denomerator format 
%% Parameters 
% num : Numerator vector (starting from highest order of coefficients) 
% den : Denomerator vector (starting from highest order of coefficients) 
% plant : Plant transfer function 
%% EXAMPLE 
% num=[1]; 
% den=[1 0 1]; 
% sys=CreatePlant(num,den) 
%% Result is 
% 1 
% sys= --------------- 
% S^2+1 
%% Function implementation 
syms s; 
Wp=tf(num,den); 
end 
Snippet 1 CreatePlant function 
d. Save the file. 
e. Close the function file. 
퐾푐(1+ 1 푇푖푠 +푇푑푠) 
1(10푠+1)3 
Set 
Point 
E(S) 
X(S) 
Current 
Level 
Y(S)
v1.0 
f. Repeat steps b-e for creating the following snippet for Ziegler-Nicholas generic function: 
function Wc = ZieglerNicholasPID( Kc,Ti,Td ) 
% ZieglerNicholasPID function to generate the PID controller transfer 
%% Parameters 
% Kc : Critical gain 
% Ti : Reset time (minutes) 
% Td : Derivative time (minutes) 
%% Function implementation 
s=tf('s'); 
Wc=Kc*(1+(1/(Ti*s))+Td*s); 
end 
Snippet 2 Ziger-Nicholas PID implementation 
g. The final function bonds the two functions (plant and controller) to build the closed loop system: 
function sys = CLS( Wp,Wc ) 
%CLS Closed loop system function 
%% Parameters 
% Wp : Plant transfer function 
% Wc : Controller transfer function 
% sys : Closed Loop transfer function with assuming unity feedback. 
%% Function implementation 
CLS=feedback(series(Wp,Wc),1); 
end 
Snippet 3 Closed loop system bonding
v1.0 
6. Open loop system response 
Figure 3 Open loop system 
To plot the open loop response, perform the following steps: 
a. From MATLAB command window, we will call the function CreatePlant to create the transfer function mentioned in shown: 
sys=CreatePlant(1,[1000 300 30 1]); 
step(sys) 
b. From the figure opened, right click on it and select characteristics -> Settling Time, Rise Time and Steady State. Fill in the table: 
Figure 4 Characteristics of Open loop system 
 
Table 1 Characteristics of open loop system 
Rise Time (sec) 
42.2 
Settling Time (sec) 
75.2 
Steady State (sec) 
120 
1(10푠+1)3 
Set 
Point 
Y(s)
v1.0 
7. Finding the critical gain (Kc) via Nyquist plot 
a. To plot the Nyquist of frequency response of the plant, write down the following code: 
Wp=CreatePlant(1,[1000 300 30 1]); 
nyquist(Wp); 
b. Right click on the plot and select characteristics -> Minimum Stability Margins as shown in figure 
Figure 5 Nyquist plot (Open loop) 
c. Write down the gain margin Gm (in dB) and convert it to magnitude. Write down the margin frequency Wc . 
d. Calculate 퐾푐=퐺푚= 8.0011 , and 푃푢= 2휋 휔푐 = 2휋 0.173=36.32 푠푒푐 and consequently 푇푖=
v1.0 
e. Check that Kc is the critical gain by writing down the following MATLAB code: 
t=0:0.01:200; 
Wp=CreatePlant(1,[1000 300 30 1]); 
%Setting Kc=8, Ki=~0 and Kd=0 
Wc=ZieglerNicholasPID(8,100000,0); 
sys=CLS(Wp,Wc); 
%plotting step response from t0=0 to tf=200 sec 
step(sys,t) 
Snippet 4 Plotting the system response at critical gain 
Figure 6 Step response at Kc=8 
8. Calculating P, PI and PID control gains 
After obtaining the critical gain from the previous step, we are able to calculate the P,I and D parameters and perform comparison of each controller type. According to Ziegler Nicholas table: 
Table 2 Ziegler Nicholas Tuning Chart Controller Type Kp Ti (sec) Td (sec) P 
0.5*Kc = 0.5*8=4 
100000 
0 PI 
0.45*Kc = 0.45*8=3.6 
0.83*Pu=0.83*36.32=30.1 
0 PID 
0.59* Kc = 0.59*8=4.7 
0.5*Pu=0.5*36.32=18.2 
0.12*Pu =0.12*36.32=4.4
v1.0 
Plot the step response of each controller over the plant by writing the following code: 
Wp=CreatePlant(1,[1000 300 30 1]); 
Wcp=ZieglerNicholasPID(4,100000,0); 
Wcpi=ZieglerNicholasPID(3.6,30.1,0); 
Wcpid=ZieglerNicholasPID(4.7,18.2,4.4); 
t=0:0.01:500; 
sys=CLS(Wp,Wcp); 
step(sys,t) 
hold on 
sys=CLS(Wp,Wcpi); 
step(sys,t) 
sys=CLS(Wp,Wcpid); 
step(sys,t) 
legend('P','PI','PID') 
Figure 7 step response of P, PI and PID controller

More Related Content

PPT
Chapter 7 1
PDF
STATE_SPACE_ANALYSIS.pdf
PPTX
Proportional integral and derivative PID controller
PPTX
Pid controllers
PPTX
Simulation and Comparison of P, PI, PID Controllers on MATLAB/ Simulink
PDF
Types of Controllers PID PD I PD
PPTX
Week 14 pid may 24 2016 pe 3032
Chapter 7 1
STATE_SPACE_ANALYSIS.pdf
Proportional integral and derivative PID controller
Pid controllers
Simulation and Comparison of P, PI, PID Controllers on MATLAB/ Simulink
Types of Controllers PID PD I PD
Week 14 pid may 24 2016 pe 3032

What's hot (20)

PDF
Modern Control - Lec 06 - PID Tuning
PPTX
PID Control Basics
PPTX
PID Controller and its design
PPTX
Industrial automation (PLC, SCADA, VFD & HMI)
PDF
Lecture 2 timers, pwm, state machine IN PIC
PDF
Modern Control - Lec 01 - Introduction to Control System
PPTX
Control systems engineering
PPTX
Lecture 13 14-time_domain_analysis_of_1st_order_systems
PDF
Class 19 pi & pd control modes
PDF
Model Matematis untuk Rangkaian Elektrik
PDF
Modern Control - Lec 03 - Feedback Control Systems Performance and Characteri...
PDF
Lecture 10.cont,11 (plc)
PPTX
Block Diagram Algebra
PPTX
Root locus compensation
PPTX
Lecture 8-9 block-diagram_representation_of_control_systems
PPTX
Lecture 14 15-time_domain_analysis_of_2nd_order_systems
PDF
Inertial measurement unit (IMU) and Global Positioning System (GPS)
PDF
Schneider twido suite training
PPTX
PLC LADDER DIAGRAM
PDF
Timer dan counter
Modern Control - Lec 06 - PID Tuning
PID Control Basics
PID Controller and its design
Industrial automation (PLC, SCADA, VFD & HMI)
Lecture 2 timers, pwm, state machine IN PIC
Modern Control - Lec 01 - Introduction to Control System
Control systems engineering
Lecture 13 14-time_domain_analysis_of_1st_order_systems
Class 19 pi & pd control modes
Model Matematis untuk Rangkaian Elektrik
Modern Control - Lec 03 - Feedback Control Systems Performance and Characteri...
Lecture 10.cont,11 (plc)
Block Diagram Algebra
Root locus compensation
Lecture 8-9 block-diagram_representation_of_control_systems
Lecture 14 15-time_domain_analysis_of_2nd_order_systems
Inertial measurement unit (IMU) and Global Positioning System (GPS)
Schneider twido suite training
PLC LADDER DIAGRAM
Timer dan counter
Ad

Viewers also liked (6)

PPTX
PID Controller
PDF
Level Control of Tank System Using PID Controller-A Review
PDF
Controller Tuning Method for Non-Linear Conical Tank System
PPT
Controller ppt
PPTX
Water level controller
PPTX
Pid controllers
PID Controller
Level Control of Tank System Using PID Controller-A Review
Controller Tuning Method for Non-Linear Conical Tank System
Controller ppt
Water level controller
Pid controllers
Ad

Similar to PID Tuning using Ziegler Nicholas - MATLAB Approach (20)

PDF
Applications of MATLAB in Control Part II.pdf
PPTX
BALLANDBEAM_GROUP7.pptx
DOCX
MODELLING, ANALYSIS AND SIMULATION OF DYNAMIC SYSTEMS USING CONTROL TECHNIQUE...
PPTX
air craft Pitch
DOCX
Ece 415 control systems, fall 2021 computer project 1
PPTX
pc-lec4.1.pptx pid controller presentation
PPTX
Design of imc based controller for industrial purpose
PPTX
PID Controllers
PDF
Control de nivel de agua
PPT
Modelling Simulation and Control of a Real System
PDF
Control tutorials for matlab and simulink introduction pid controller desig...
PDF
Matlab For Control System Engineers Second Edition Dukkipati
PDF
Modeling, simulation and control of a robotic arm
DOCX
Mballa_Weiss_Lab6
PDF
Katsuhiko Ogata _ Modern Control Engineering 5th Edition.pdf
PPTX
06 control.systems
PDF
Sistemas de control modernos 13.ª edición por Richard C. Dorf.pdf
PPTX
Aifcraft pitch
PDF
Kx3618681871
Applications of MATLAB in Control Part II.pdf
BALLANDBEAM_GROUP7.pptx
MODELLING, ANALYSIS AND SIMULATION OF DYNAMIC SYSTEMS USING CONTROL TECHNIQUE...
air craft Pitch
Ece 415 control systems, fall 2021 computer project 1
pc-lec4.1.pptx pid controller presentation
Design of imc based controller for industrial purpose
PID Controllers
Control de nivel de agua
Modelling Simulation and Control of a Real System
Control tutorials for matlab and simulink introduction pid controller desig...
Matlab For Control System Engineers Second Edition Dukkipati
Modeling, simulation and control of a robotic arm
Mballa_Weiss_Lab6
Katsuhiko Ogata _ Modern Control Engineering 5th Edition.pdf
06 control.systems
Sistemas de control modernos 13.ª edición por Richard C. Dorf.pdf
Aifcraft pitch
Kx3618681871

More from Waleed El-Badry (8)

PPTX
Design of mechatronics systems team #4
PPSX
Mechatronics design team project v2
DOCX
Instructions on how to configure NI SoftMotion with SOLIDWORKS
PPTX
Motion Control with LabVIEW and SOLIDWORKS
PDF
The Development of Mechatronic Machine Vision System for Inspection of Cerami...
PPTX
The Development of Mechatronic Machine Vision System for Inspection Of Cerami...
PDF
Design and Implementation of DC Motor Speed Control using Fuzzy Logic
PPTX
Dc motor speed control
Design of mechatronics systems team #4
Mechatronics design team project v2
Instructions on how to configure NI SoftMotion with SOLIDWORKS
Motion Control with LabVIEW and SOLIDWORKS
The Development of Mechatronic Machine Vision System for Inspection of Cerami...
The Development of Mechatronic Machine Vision System for Inspection Of Cerami...
Design and Implementation of DC Motor Speed Control using Fuzzy Logic
Dc motor speed control

Recently uploaded (20)

PDF
Hazard Identification & Risk Assessment .pdf
PPTX
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
PDF
Uderstanding digital marketing and marketing stratergie for engaging the digi...
PDF
1.3 FINAL REVISED K-10 PE and Health CG 2023 Grades 4-10 (1).pdf
PPTX
Share_Module_2_Power_conflict_and_negotiation.pptx
PPTX
CHAPTER IV. MAN AND BIOSPHERE AND ITS TOTALITY.pptx
PDF
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
PDF
HVAC Specification 2024 according to central public works department
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
PDF
CISA (Certified Information Systems Auditor) Domain-Wise Summary.pdf
PPTX
ELIAS-SEZIURE AND EPilepsy semmioan session.pptx
PDF
David L Page_DCI Research Study Journey_how Methodology can inform one's prac...
PDF
Empowerment Technology for Senior High School Guide
PDF
Practical Manual AGRO-233 Principles and Practices of Natural Farming
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PDF
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 2).pdf
PPTX
A powerpoint presentation on the Revised K-10 Science Shaping Paper
PPTX
20th Century Theater, Methods, History.pptx
PDF
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
Hazard Identification & Risk Assessment .pdf
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
Uderstanding digital marketing and marketing stratergie for engaging the digi...
1.3 FINAL REVISED K-10 PE and Health CG 2023 Grades 4-10 (1).pdf
Share_Module_2_Power_conflict_and_negotiation.pptx
CHAPTER IV. MAN AND BIOSPHERE AND ITS TOTALITY.pptx
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
HVAC Specification 2024 according to central public works department
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
CISA (Certified Information Systems Auditor) Domain-Wise Summary.pdf
ELIAS-SEZIURE AND EPilepsy semmioan session.pptx
David L Page_DCI Research Study Journey_how Methodology can inform one's prac...
Empowerment Technology for Senior High School Guide
Practical Manual AGRO-233 Principles and Practices of Natural Farming
Paper A Mock Exam 9_ Attempt review.pdf.
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 2).pdf
A powerpoint presentation on the Revised K-10 Science Shaping Paper
20th Century Theater, Methods, History.pptx
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)

PID Tuning using Ziegler Nicholas - MATLAB Approach

  • 1. v1.0 Misr University for Science and Technology College of Engineering Mechatronics Lab PROCESS CONTROL MODULE PID TUNING AND STABILITY (MATLAB Simulation) Prof. Farid A. Tolbah Eng. Waleed A. El-Badry
  • 2. v1.0 1. Objective The experiment is aimed to make student acquainted with the preliminary steps to manually tune a PID controller for a plant model by means of MATLAB. 2. Outcome  Writing mathematical models of plants under investigation in Laplace form using MATLAB.  Developing the mathematical Laplace representation of Ziegler-Nicholas PID controller in MATLAB.  Finding the critical gain (Kc) and the ultimate period (Pu) to calculate PID gains. 3. Prerequisite Student should be familiar with the following terms:  Closed loop system.  System response.  PID controller  Ziegler-Nicholas tuning method. Also basic understanding of MATLAB syntax is preferred. 4. The Closed loop system The below figure represents the generic closed loop system. Figure 1 Closed loop system For implementation in this experiment, we are given the following plant model Wp(s): 푊푝(푠)= 1(10푠+1)3= 11000푆3+300푠2+30푠+1 And the Ziegler-Nicholas PID is formulated as: 푊푐(푠)=퐾푐(1+ 1 푇푖푠 +푇푑푠) Controller Plant Feedback FCE Set Point e(t) y(t) wc Current Level
  • 3. v1.0 Assuming unity feedback, redrawing the block diagram: Figure 2 Problem block diagram 5. Developing MATLAB functions (Plant, Controller and Closed Loop) a. Launch MATLAB software. b. From the Home tab, select New -> Function. c. Write down the generic plant function as shown in the following snippet: function [ Wp ] = CreatePlant( num,den ) %CreatePlant Creates plant transfer function. % The returned value is the system in numerator/denomerator format %% Parameters % num : Numerator vector (starting from highest order of coefficients) % den : Denomerator vector (starting from highest order of coefficients) % plant : Plant transfer function %% EXAMPLE % num=[1]; % den=[1 0 1]; % sys=CreatePlant(num,den) %% Result is % 1 % sys= --------------- % S^2+1 %% Function implementation syms s; Wp=tf(num,den); end Snippet 1 CreatePlant function d. Save the file. e. Close the function file. 퐾푐(1+ 1 푇푖푠 +푇푑푠) 1(10푠+1)3 Set Point E(S) X(S) Current Level Y(S)
  • 4. v1.0 f. Repeat steps b-e for creating the following snippet for Ziegler-Nicholas generic function: function Wc = ZieglerNicholasPID( Kc,Ti,Td ) % ZieglerNicholasPID function to generate the PID controller transfer %% Parameters % Kc : Critical gain % Ti : Reset time (minutes) % Td : Derivative time (minutes) %% Function implementation s=tf('s'); Wc=Kc*(1+(1/(Ti*s))+Td*s); end Snippet 2 Ziger-Nicholas PID implementation g. The final function bonds the two functions (plant and controller) to build the closed loop system: function sys = CLS( Wp,Wc ) %CLS Closed loop system function %% Parameters % Wp : Plant transfer function % Wc : Controller transfer function % sys : Closed Loop transfer function with assuming unity feedback. %% Function implementation CLS=feedback(series(Wp,Wc),1); end Snippet 3 Closed loop system bonding
  • 5. v1.0 6. Open loop system response Figure 3 Open loop system To plot the open loop response, perform the following steps: a. From MATLAB command window, we will call the function CreatePlant to create the transfer function mentioned in shown: sys=CreatePlant(1,[1000 300 30 1]); step(sys) b. From the figure opened, right click on it and select characteristics -> Settling Time, Rise Time and Steady State. Fill in the table: Figure 4 Characteristics of Open loop system Table 1 Characteristics of open loop system Rise Time (sec) 42.2 Settling Time (sec) 75.2 Steady State (sec) 120 1(10푠+1)3 Set Point Y(s)
  • 6. v1.0 7. Finding the critical gain (Kc) via Nyquist plot a. To plot the Nyquist of frequency response of the plant, write down the following code: Wp=CreatePlant(1,[1000 300 30 1]); nyquist(Wp); b. Right click on the plot and select characteristics -> Minimum Stability Margins as shown in figure Figure 5 Nyquist plot (Open loop) c. Write down the gain margin Gm (in dB) and convert it to magnitude. Write down the margin frequency Wc . d. Calculate 퐾푐=퐺푚= 8.0011 , and 푃푢= 2휋 휔푐 = 2휋 0.173=36.32 푠푒푐 and consequently 푇푖=
  • 7. v1.0 e. Check that Kc is the critical gain by writing down the following MATLAB code: t=0:0.01:200; Wp=CreatePlant(1,[1000 300 30 1]); %Setting Kc=8, Ki=~0 and Kd=0 Wc=ZieglerNicholasPID(8,100000,0); sys=CLS(Wp,Wc); %plotting step response from t0=0 to tf=200 sec step(sys,t) Snippet 4 Plotting the system response at critical gain Figure 6 Step response at Kc=8 8. Calculating P, PI and PID control gains After obtaining the critical gain from the previous step, we are able to calculate the P,I and D parameters and perform comparison of each controller type. According to Ziegler Nicholas table: Table 2 Ziegler Nicholas Tuning Chart Controller Type Kp Ti (sec) Td (sec) P 0.5*Kc = 0.5*8=4 100000 0 PI 0.45*Kc = 0.45*8=3.6 0.83*Pu=0.83*36.32=30.1 0 PID 0.59* Kc = 0.59*8=4.7 0.5*Pu=0.5*36.32=18.2 0.12*Pu =0.12*36.32=4.4
  • 8. v1.0 Plot the step response of each controller over the plant by writing the following code: Wp=CreatePlant(1,[1000 300 30 1]); Wcp=ZieglerNicholasPID(4,100000,0); Wcpi=ZieglerNicholasPID(3.6,30.1,0); Wcpid=ZieglerNicholasPID(4.7,18.2,4.4); t=0:0.01:500; sys=CLS(Wp,Wcp); step(sys,t) hold on sys=CLS(Wp,Wcpi); step(sys,t) sys=CLS(Wp,Wcpid); step(sys,t) legend('P','PI','PID') Figure 7 step response of P, PI and PID controller