A MATLAB Approach To Study Different Types of Ziegler-Nichols P-I-D Controller Tuning Algorithm
A MATLAB Approach To Study Different Types of Ziegler-Nichols P-I-D Controller Tuning Algorithm
references: ..................................................................................................................................................................... 23
appendix: ....................................................................................................................................................................... 24
List of tables:
TABLE 1: SUMMARY OF CONTROLLER PERFORMANCE ON SYSTEM DYNAMICS. ..................................................... 11
TABLE 2: SUMMARY CONTROLLER MODES AND APPLICATIONS ..................................................................................... 11
TABLE 3: ZIEGLER–NICHOLS TUNING FORMULAE – STEP RESPONSE METHOD ......................................................... 12
TABLE 4: ZIEGLER–NICHOLS TUNING FORMULAE – SUSTAIN OSCILLATION METHOD ......................................... 13
TABLE 5: COHEN–COON TUNING FORMULAE ................................................................................................................ 13
TABLE 6: CHR TUNING FORMULAE FOR SET-POINT REGULATION. ................................................................................. 14
TABLE 7: CHR TUNING FORMULAE FOR DISTURBANCE REJECTION. ............................................................................... 14
TABLE 8: WANG–JUANG–CHAN TUNING FORMULAE ........................................................................................................... 15
1. Introduction
Today, a number of different controllers are used in industry and in many other fields. In quite
general way those controllers can be divided into two main groups:
Conventional controllers
Unconventional controllers
As conventional controllers we can count a controllers known for years now, such as ON-OFF, P,
PI, PD, PID all their different types and realization. It is a characteristic of all conventional
controllers that one has to know a mathematical model of the process in order to design a
controller.
A Proportional–Integral–Derivative (PID) controller is a three-term controller that has a long
history in the automatic control field, starting from the beginning of the last century. Owing to
its intuitiveness and its relative simplicity, in addition to satisfactory performance which it is able
to provide with a wide range of processes, it has become in practice the standard controller in
industrial settings.
The success of the PID controllers is also enhanced by the fact that they often represent the
fundamental component for more sophisticated control schemes that can be implemented when
the basic control law is not sufficient to obtain the required performance or a more complicated
control task is of concern.
Unconventional controllers utilize a new approaches to the controller design in which
knowledge of a mathematical model of a process generally is not required. Examples of
unconventional controller are a fuzzy controller and neuro or neuro-fuzzy controllers.
I. Scope and Objective:
The scope of this report is to provide a MATLAB approach to understand and simulate
conventional type PID controller and its various realizations with different tuning algorithms.
The Objective of This work is to learn about the PID Controller and A Few Basic Tuning Rules of
It.
To Learn Basic Concepts of MATLAB.
Study the various PID Controller fundamental Parameters and its Characteristics.
Apply the Famous Ziegler-Nichols Tuning Method of PID Tuning.
Study some modifications of Ziegler-Nichols Tuning Method and implement in MATLAB
script.
u (t )
U max
U min
e(t )
Figure 1: Static characteristic of On-off controller
Draw Backs:
On-off controller is very simple since there are only two possible control signal values, no
matter what is the value of control error. So, process is forced to a persistent oscillation
around the set-point value since u (t ) is never zero (it is either U max or U min ).
Despite its simple function and action, there are no parameters to adjust the controller values
according to process.
Actually, in practical cases, the On–Off controller characteristic is modified by inserting a dead
zone (this result a three Position control) or hysteresis in order to cope with measurement noise
and to limit the wear and tear of the actuating device.
On–Off controller is indeed suitable for adoption when no tight performance is required, since it
is very cost-effective in these cases. For this reason it is generally available in commercial
industrial controllers.
IV. The Three Actions of PID Control
PID controllers use a 3 basic behaviour types or modes: P - proportional, I - integrative and D -
derivative. While proportional and integrative modes are also used as single control modes, a
derivative mode is rarely used on it’s own in control systems. Combinations such as PI and PD
control are very often in practical systems. It can be also shown that PID controller is a natural
generalization of a simplest possible controller - On-off controller
V. P Controller
The proportional control action is proportional to the current control error, according to the
expression
u (t ) K p e(t ) K p (r (t ) y (t )),
K p Proportional Gain
2
r (t ) Reference Signal ( SetPo int)
y (t ) Process / Output Signal
P controller control algorithm is given with:
U max ; e(t ) e0
u (t ) u0 K p e(t ) for , e0 e(t ) e0
3
U min ; e(t ) e0
u0 Amplitude of Control Signal whem Error 0
It is worth noting that in commercial products the proportional gain is often replaced by the
proportional band, PB, that is the range of error that causes a full range change of the control
variable,
100
PB=
Kp
u (t )
U max
u0
U min
e0 e0 e(t )
Figure 2: Static characteristic of P controller
As shown in Figure 2, it is observed that the P controller has associated with some offset ( u0 ),
which never makes the error to zero. There is always a steady state error with the controller.
u (t ) u0
There are some modifications required to make e(t ) 0, in e(t )
Kp
Keeping, K p , which makes PB=0 and will serve as a On-Off Control.
The offset values should be correctly chosen at every time, i.e. u (t ) u0
Manual Reset of offset value changes to automatically.
This introduces an integral action to perform automatically reset the offset values.
VI. I Controller
While the Proportional term considers the current size of e(t ) only at the time of the controller
calculation, the integral term considers the history of the error, or how long and how far the
measured process variable has been from the set point over time, and can be expressed as,
t
u (t ) Ki e( )d ,
0
4
Ki Integral Gain
Integration is a continual summing. Integration of error over time means that we sum up the
complete controller error history up to the present time, starting from when the controller was
first switched to automatic.
VII. D Controller
While the proportional action is based on the current value of the control error and the integral
action is based on the past values of the control error, the derivative action is based on the
predicted future values of the control error. An ideal derivative control law can be expressed as:
de(t )
u (t ) K d ,
dt 5
Ki Derivative Gain
The control variable at time t is therefore based on the predicted value of the control error at
time (t td ) . For this reason the derivative action is also called anticipatory control, or rate
action, or pre-act.
A derivative describes how steep a curve is. More properly, a derivative describes the slope or the
rate of change of a signal trace at a particular point in time.
VIII. Combined Control and Choice of Controller.
Insofar was described individuality of proportional, integrative and derivative modes of the
controllers. An introductory concept behind their use was also explained. However, an attention
towards the practical implementation and choice of use different types of controllers yet to be
explained. The following section will add some focus on that particular topic.
PID Controller itself consists of three individual concepts like Proportional, Integral, and
derivative, but the real practical implementations includes combined action of these like, PI,
PD,PI-PD,PID and many more. In whole among these different combinations PID is the best and
mostly used controller in (almost 95%) industrial processes, where PI, PD and other
combinations are perform with a special consideration or use to deal with any extra requirement
needed to a process control.
a. PI Controller
As discussed in earlier section P Controller can only reduce, the steady state error(SSE) to a
extend, beyond that it cannot eliminate SSE due to the Offset(Bias) at control signal. An
automatic reset of this bias value can completely eliminate SSE which is provided by an Integral-
I Controller.
The combined structure of Proportional-Integral (PI) Controller is expressed mathematically by:
Kp t
Ti 0
u (t ) K p e(t ) e( )d ,
6
Kp
Ki and Ti Integral ( Reset ) Time
Ti
Concept of Integrator windup:
A PI controller may create a situation in which it saturates the control variable output.
Saturation occurs when the control variable output remains pegged at its maximum value
(100%). The Control Signal ( u (t ) ) will remain saturated even if the error starts to come down
(see Figure 3). The integral action will not change direction until the overall error becomes zero.
This situation is called integral windup, or reset windup, and it can be damaging to the process.
It occurs when a large error is present in a system with a slow response. In this situation, the
controller will keep increasing the control variable value because the error remains constant due
to the lag’s effect on the integral corrective action. Eventually, the control variable will saturate
at 100%. In other words, the controller’s corrective action continues to occur when the process
takes too long to respond.
Considering the control Structure shown in Figure 4, the close loop response can be found by
calculating the PI Controller and Plant as open loop element with H (s) as Feedback Element.
This report works with Eq.10 as a plant, and we only used Eq. 9 and Eq.13, Controller, for
experimentation, however one can use other realizations of Plant and Controller.
Experiment – 1(Individual Controller response) on a Plant)
Aim: To identify the effects of system characteristics by using a Controller (Individual Controller
response) on a Plant described as in Eq.10.
Simulating The Open loop response of the Plant described as in Eq.10. It can be seen that
the step response output is close to 0.435. The steady state error = 1-0.435 = 0.565. That’s quite
high. Also observe that the settling time is around 6 (See Figure 9).
Proportional Controller Effects:
Now, to examine the effect of proportional element ( K p ) on the system output. Varying the
values of K p = 0.5 to 4 in a step of0.5, and Keeping the values of K i = 0, K d = 0 the step response
of the system is (see Figure 10).
Step Response
0.45
0.4
0.35
0.25
0.2
0.15
0.1
0.05
0
0 2 4 6 8 10 12 14
Time (seconds)
0.8
0.7
0.6
Amplitude
0.5
0.4
0.3
0.2
0.1
0
0 2 4 6 8 10 12
Time (seconds)
1
Amplitude
0.5
0
0 5 10 15 20 25
Time (seconds)
1.2
0.8
Amplitude
0.6
0.4
0.2
0
0 2 4 6 8 10 12 14 16 18 20
Time (seconds)
0.8
Amplitude
0.6
0.4
0.2
0
0 5 10 15 20 25
Time (seconds)
0.4 K
0.35
K=0.4167
0.3 L=0.76 Sec
T=1.96 Sec
Amplitude
0.25
0.2
0.15
0.1
0.05
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 5.5 6 6.5 7 7.5 8 8.5 9 9.5 10 10.5 11 11.5 12 12.5 13 13.5 14
L T Time (seconds)
Figure 14: Finding the K, L and T from ‘S’ Shaped Step response Curve.
Using these values ( K 0.4167, L 0.76 Sec and T 2.72Sec ), the PID Controller can be obtained
using MATLAB function described in (Appendix A).
There is MATLAB function ‘dcgain (system)’, which can give the ‘K’ value of the system
described in transfer function.
b. Sustained Oscillation Method:
Step Response
1.6 Pcr
1.4 Kp=12.2
Kp=12.4
1.2 Kp=12.6
1
Amplitude
0.8
0.6
0.4
0.2
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 5.5 6 6.5 7.0 7.34 7.7 8 8.5 9 9.5 10
Time (seconds)
Figure 15: Obtain The Critical Gain (Kcr) and Period (Pcr) from Sustained Oscillation Curve.
Following the method described in Paragraph (2b) and simulating the system with various valus
of Kp, we obtain the above Figure 16, it can be seen that there is a sustained oscillation at
Kp=12.6, hence the Critical Gain (Kcr) =12.6 and Period (Pcr)=2.84 (approx.).
Another way to find the values of Critical Gain (Kcr) and Period (Pcr) is use of MATLAB Command
‘margin (system)’ function.
However a mathematical approach [7]can also be implemented to find the values as described in
fowling section.
Mathematically Calculation of Critical Gain (Kcr) and Period (Pcr):
Consider the Plant in Eq.10 and P Controller as alone shown in Figure 16.
s3 10 0
s2 30 (24 10 K p )
s1 (42 3.33K p )
s0 (24 10 K p )
From above Routh Array, the Value of K p 12.61 , and the Value of Kcr 12.61 . Next, to find the
Period of oscillation P cr .
Substitute s jw , in the Characteristics Eq.16. we will get,
( jw)4 10( jw)3 35( jw)2 50( jw) 24 0 17
As we know [7], Period of oscillation Pcr 2 w , after solving the Eq.17, we calculate the Pcr 2.23 ,
hence we used this Values ( Kcr 12.6 and Pcr 2.23 )to calculate the Values of PID Controller
using the Table 4.
Observation1: Different Controller Response (P.PI and PID) tuned in Process reaction Curve
Method (Shown in Figure 17) and Sustained Oscillation Method (Shown in Figure 18).
Step Response
1.4
Response of P Controller
1.2 Response of PI Controller
Response of PID Controller
1
Amplitude
0.8
0.6
0.4
0.2
0
0 2 4 6 8 10 12 14 16 18
Time (seconds)
Figure 17: System Response of P,PI & PID Controller tuned with Process Reaction Curve Method
Step Response
1.4
Response of P Controller
1.2 Response of PI Controller
Response of PID Controller
1
Amplitude
0.8
0.6
0.4
0.2
0
0 2 4 6 8 10 12 14 16 18
Time (seconds)
Figure 18: System Response of P,PI & PID Controller Tuned with Sustained Oscillation Method.
Observation 2: Observing the difference between the closed loop response of the system when a
Derivative Controller is used along the Controller and with a derivative Filter (PID tuned in
Process reaction Curve Method (Figure 19) and Sustained Oscillation Method (Figure 20).)
Step Response
1.4
Response of PID Controller
1.2 Response of PID (With Filter)Controller
1
Amplitude
0.8
0.6
0.4
0.2
0
0 2 4 6 8 10 12 14 16 18
Time (seconds)
Figure 19: Comparison of PID and PID with Derivative Filter Controller (Process Reactive Curve Method)
Step Response
1.4
Response of PID Controller
1.2 Response of PID (With Filter)Controller
1
Amplitude
0.8
0.6
0.4
0.2
0
0 1 2 3 4 5 6 7 8 9
Time (seconds)
Figure 20: Comparison of PID and PID with Derivative Filter Controller (Sustained Oscillation Method)
Experiment – 3 (Cohen-Coon PID Controller Tuning Algorithm)
Aim: To Study the Cohen-Coon PID Controller Tuning Algorithm and designing the P, I and D
parameter for the Plant described as in Eq.10.
Step Response
1.4
1.2
1
Amplitude
0.8
0.6
Response of P Controller
0.4 Response of PI Controller
Response of PD Controller
0.2 Response of PID Controller
Response of PID(With Filter) Controller
0
0 2 4 6 8 10 12 14 16 18
Time (seconds)
Figure 21: Closed Loop System response with CohenCoon Tuned Controllers (P,PI,PD,PID,PID-With Filter)
Taking the values of K 0.4167, L 0.76Sec and T 2.72Sec , and using the Table 5 for tuning the
PID Controller, we performed the closed loop response of the system shown in Figure 21.
Experiment – 4 (Chien, Hrones and Reswick Tuning Algorithm)
Aim: To Study the Chien, Hrones and Reswick Tuning Algorithm and designing the P, I and D
parameter for the Plant described as in Eq.10.
Taking the values of K 0.4167, L 0.76Sec and T 2.72Sec , and using the Table 6 for Set Point
regulation tuning method of PID Controller, we performed the closed loop response of the
system shown in Figure 22, similarly using Table 7, for disturbance rejection method the
corresponding closed loop response is shown in Figure 23.
Set Point Regulation With 0% Overshoot Set Point Regulation With 20% Overshoot
1.4 1.4
1.2 1.2
1 1
Amplitude
Amplitude
0.8 0.8
0.6 0.6
0 0
0 2 4 6 8 10 12 14 16 18 0 2 4 6 8 10 12 14 16 18
Time (seconds) Time (seconds)
Figure 22: System response to Chien, Hrones and Reswick Tuning Algorithm based PID Controller
(Setpoint Regulation)
Distrubance Rejection with 0% Overshoot Distrubance Rejection with 20% Overshoot
1.4 1.4
1.2 1.2
1 1
Amplitude
Amplitude
0.8 0.8
0.6 0.6
1
Amplitude
0.8
0.6
0.4
0.2
0
0 5 10 15 20 25
Time (seconds)
Figure 24: Wang-Jung-Chan Tuned PID Controller response of a system with derivative filter.
References:
[1] Ziegler, J.G, Nichols, N.B., "Optimum settings for automatic controllers", Trans.ASME, vol. 64,
pp. 759-768, 1942.
[2] Cohen, G.H., Coon, G.A. "Theoretical consideration of retarded control", Trans. ASME vol. 75,
pp.827-834, 1953.
[3] Netushil at al. Theory of Automatic Control, Mir, Moscow 1978.
[4] Chien, K.L., Hrones, J.A., Reswick, J.B., "On the automatic control of generalized passive
systems", Trans. ASME, 74, 175, 1952.
[5] Åström, K.J., Hägglund, T., PID Control – Theory, Design and Tuning, Instrument Society of
America, Research Triangle Park, NC, 2nd ed., 1995.
[6] Levine, W.S. ed., The control handbook, CRC Press, 1995.
[7] Ogata, K., Third ed, Modern Control Engineering, Prentice-Hall Inc, 1997.
Appendix:
Appendix A: MATLAB Functions for PID Tuning.
function [Gc,Kp,Ti,Td] = myzntune(Ch, data, method)
%% Please Enter a Valid Choice from, P, PI, PID or PIDF Where,
% P="PROPORTIONAL" PI="PROPORTIONAL + INTEGRAL"
% PID="PROPORTIONAL + INTEGRAL + DERIVATIVE"
% PIDF="PROPORTIONAL + INTEGRAL + DERIVATIVE(WITH FILTER)"
%% PLANT DESCRIPTION %%
s=tf('s');
Gp=10/(s+1)/(s+2)/(s+3)/(s+4);
%% PreDefinations %%
s=tf('s');
if length(data)==4
k=data(1); L=data(2); T=data(3); N=data(4);
Y=(k*L);
a=Y/T;
% N=10;
else if length(data)==3
Kcr=data(1);Pcr=data(2);N=data(3);
end
end
elseif strcmp(Ch,'PI')==1
disp('You Have Choosen "PROPORTIONAL + INTEGRAL" Controller')
Kp=0.9/a;
Ti=3.33*L;
Td='Not Reqired';
Gc=Kp*(1+(1/(Ti*s)));
% subplot(4,2,2)
step(feedback(series(Gc,Gp),1))
elseif strcmp(Ch,'PID')==1
disp('You Have Choosen "PROPORTIONAL + INTEGRAL + DERIVATIVE"
Controller')
Kp=1.2/a;
Ti=2*L;
Td=L/2;
Gc=Kp*(1+(1/(Ti*s))+(Td*s));
% subplot(4,2,3)
step(feedback(series(Gc,Gp),1))
elseif strcmp(Ch,'PIDF')==1
disp('You Have Choosen "PROPORTIONAL + INTEGRAL + DERIVATIVE(WITH
FILTER)" Controller')
Kp=1.2/a;
Ti=2*L;
Td=L/2;
Gc=Kp*(1+1/Ti/s+Td*s/(1+Td*s/N));
% subplot(4,2,4)
step(feedback(series(Gc,Gp),1))
% elseif strcmp(Ch,'PIDFF')==1
% disp('You Have Choosen "PROPORTIONAL + INTEGRAL + DERIVATIVE(WITH
FILTER) IN FEEDBACK PATH" Controller')
% Kp=1.2/a;
% Ti=2*L;
% Td=L/2;
% Gc=Kp*(1+1/s/Ti);
% Hs=((1+Kp/N)*Ti*Td*s^2+Kp*(Ti+Td/N)*s+Kp)/(Kp*(Ti*s+1)*(Td/N*s+1));
% step(feedback(series(Gc,Gp),Hs))
else
error('Please Enter a Valid Choice, P, PI, PID or PIDF')
end
%% CLOSED LOOP - SUSTAINED OSCILLATION METHOD %%
case 'closeloop'
if Ch=='P'
disp('You Have Choosen "PROPORTIONAL" Controller Only')
Kp=0.5*Kcr;Ti='Not Reqired';Td='Not Reqired';
Gc=Kp;
% subplot(4,2,5)
step(feedback(series(Gc,Gp),1))
elseif strcmp(Ch,'PI')==1
disp('You Have Choosen "PROPORTIONAL + INTEGRAL" Controller')
Kp=0.45*Kcr;
Ti=(1/1.2)*Pcr;Ki=Kp/Ti;
Td='Not Reqired';
Gc=Kp*(1+(1/(Ti*s)));
% subplot(4,2,6)
step(feedback(series(Gc,Gp),1))
elseif strcmp(Ch,'PID')==1
disp('You Have Choosen "PROPORTIONAL + INTEGRAL + DERIVATIVE"
Controller')
Kp=0.6*Kcr;
Ti=0.5*Pcr;Ki=Kp/Ti;
Td=0.125*Pcr;Kd=Kp*Td;
Gc=Kp*(1+(1/(Ti*s))+(Td*s));
% subplot(4,2,7)
step(feedback(series(Gc,Gp),1))
elseif strcmp(Ch,'PIDF')==1
disp('You Have Choosen "PROPORTIONAL + INTEGRAL + DERIVATIVE(WITH
FILTER)" Controller')
Kp=0.6*Kcr;
Ti=0.5*Pcr;
Td=0.125*Pcr;
Gc=Kp*(1+1/Ti/s+Td*s/(1+Td*s/N));
% subplot(4,2,8)
step(feedback(series(Gc,Gp),1))
% elseif strcmp(Ch,'PIDFF')==1
% disp('You Have Choosen "PROPORTIONAL + INTEGRAL + DERIVATIVE(WITH
FILTER) IN FEEDBACK PATH" Controller')
% Kp=0.6*Kcr;
% Ti=0.5*Pcr;
% Td=0.125*Pcr;
% Gc=((1+Kp/N)*Ti*Td*s^2+Kp*(Ti+Td/N)*s+Kp)/(Kp*(Ti*s+1)*(Td/N*s+1));
% step(feedback(series(Gc,Gp),1))
else
error('Please Enter a Valid Choice, P, PI, PID or PIDF')
end
end
end
%% END OF THE FUNCTION %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function[Gc,Kp,Ti,Td]=myCohenCoon(type,data)
%% Please Enter a Valid Choice from, P, PI, PID or PIDF Where,
% P="PROPORTIONAL" PI="PROPORTIONAL + INTEGRAL"
% PID="PROPORTIONAL + INTEGRAL + DERIVATIVE"
% PIDF="PROPORTIONAL + INTEGRAL + DERIVATIVE(WITH FILTER)"
%% PLANT DESCRIPTION %%
s=tf('s');
Gp=10/(s+1)/(s+2)/(s+3)/(s+4);
% num=input('Please Enter the Numenators of the Plant');
% num=input('Please Enter the Denominators of the Plant');
% Gp=tf([num],[den]);
%%
%% Cohen Coon PID Controller Tuning %%
K=data(1);L=data(2);T=data(3);N=data(4);
Y=(K*L);a=Y/T;
N=10;
tau=L/(L+T);tmo=tau-1;
if type=='P'
disp('You Have Choosen "PROPORTIONAL" Controller Only')
Kp=(1/a)*(1+((0.35*tau)/tmo));
Ti='Not Reqired';Td='Not Reqired';
Gc=Kp;
step(feedback(series(Gc,Gp),1))
elseif strcmp(type,'PI')==1
disp('You Have Choosen "PROPORTIONAL + INTEGRAL" Controller')
Kp=(0.9/a)*(1+((0.92*tau)/tmo));
Ti=((3.33-3*tau)/(1+1.2*tau))*L;
Td='Not Reqired';
% Ki=Kp/Ti;
Gc=Kp*(1+(1/(Ti*s)));
step(feedback(series(Gc,Gp),1))
elseif strcmp(type,'PD')==1
disp('You Have Choosen "PROPORTIONAL + DERIVATIVE" Controller')
Kp=(1.24/a)*(1+((0.13*tau)/tmo));
Td=((0.27-0.36*tau)/(1-0.87*tau))*L;
Ti='Not Reqired';
% Kd=Kp*Td;
Gc=Kp*(1+Td*s);
step(feedback(series(Gc,Gp),1))
elseif strcmp(type,'PID')==1
disp('You Have Choosen "PROPORTIONAL + INTEGRAL + DERIVATIVE"
Controller')
Kp=(1.35/a)*(1+((0.18*tau)/tmo));
Ti=((2.59-2*tau)/(1-0.39*tau))*L;
Td=((0.37-0.37*tau)/(1-0.81*tau))*L;
% Ki=Kp/Ti;
% Kd=Kp*Td;
Gc=Kp*(1+(1/(Ti*s))+(Td*s));
step(feedback(series(Gc,Gp),1))
elseif strcmp(type,'PIDF')==1
disp('You Have Choosen "PROPORTIONAL + INTEGRAL + DERIVATIVE(WITH
FILTER)" Controller')
Kp=(1.35/a)*(1+((0.18*tau)/tmo));
Ti=((2.59-2*tau)/(1-0.39*tau))*L;
Td=((0.37-0.37*tau)/(1-0.81*tau))*L;
Gc=Kp*(1+1/Ti/s+Td*s/(1+Td*s/N));
step(feedback(series(Gc,Gp),1))
else
error('Please Enter a Valid Choice, P, PI, PD, PID or PIDF')
end
%%
end
%% Function Completed %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% PLANT DESCRIPTION %%
s=tf('s');
Gp=10/(s+1)/(s+2)/(s+3)/(s+4);
%% PRE-CALCULATIONS %%
K=data(1);
L=data(2);
T=data(3);
N=data(4);
a=((K*L)/T);
%%
switch method
case 'set'
if strcmp(type,'P')==1 && overshoot==0
disp('You Have Choosen "PROPORTIONAL" Controller of 0% Overshoot')
Kp=0.3/a;
Ti='Not Reqired';
Td='Not Reqired';
Gc=Kp;
step(feedback(series(Gc,Gp),1))
elseif strcmp(type,'P')==1 && overshoot==20
disp('You Have Choosen "PROPORTIONAL" Controller of 20%
Overshoot')
Kp=0.7/a;
Ti='Not Reqired';
Td='Not Reqired';
Gc=Kp;
step(feedback(series(Gc,Gp),1))
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function[Gc,Kp,Ti,Td]=mywjc(type,data)
%% Please Enter a Valid Choice from, P, PI, PID or PIDF Where,
% P="PROPORTIONAL" PI="PROPORTIONAL + INTEGRAL"
% PID="PROPORTIONAL + INTEGRAL + DERIVATIVE"
% PIDF="PROPORTIONAL + INTEGRAL + DERIVATIVE(WITH FILTER)"
%% PLANT DESCRIPTION %%
s=tf('s');
Gp=10/(s+1)/(s+2)/(s+3)/(s+4)
s=tf('s');
K=data(1); L=data(2); T=data(3); N=data(4);
Y=(K*L);
a=Y/T;b=T/L;c=T+0.5*L;
%%
if strcmp(type,'PID')==1
disp('You Have Choosen PID "PROPORTIONAL + INTEGRAL + DERIVATIVE"
Controller')
Kp=((0.7303+0.5307*b)*c)/(K*(T+L));
Ti=c;
Td=(0.5*L*T)/(c);
Kd=Kp*Td;
Ki=((Kp)/(Ti));
Gc=Kp*(1+Ki/s+Kd*s);
step(feedback(series(Gc,Gp),1))
elseif strcmp(type,'PIDF')==1
disp('You Have Choosen "PROPORTIONAL + INTEGRAL + DERIVATIVE(WITH
FILTER)" Controller')
Kp=((0.7303+0.5307*b)*c)/(K*(T+L));
Ti=c;
Td=(0.5*L*T)/(c);
Gc=Kp*(1+1/Ti/s+Td*s/(1+Td*s/N));
step(feedback(series(Gc,Gp),1))
else
error('Please Enter a Valid Choice PID or PIDF')
end
end
%% Function Completed %%
%% IN ORDER TO EXECUTE THESE, PUT ALL THIS FILES IN TO SEPARATE MATLAN FUNCTION
FILES WITH APPROPRIATE FILE NAME AND RUN THE BELOW CODE IN A NEW SCRIPT
%% FILE. REMEMBER TO PULL ALL THESE FILES IN A SINGLE FOLDER.
%% Start The Plot %%
%% Plant
s=tf('s');
Gp=10/(s+1)/(s+2)/(s+3)/(s+4);
%% Step Response Method %%
%% Figure One %%
figure
[Gc_p,Kp_p,Ti_p,Td_p]=myzntune('P',[0.4167,0.76,1.96,10],'openloop')
[Gc_pi,Kp_pi,Ti_pi,Td_pi]=myzntune('PI',[0.4167,0.76,1.96,10],'openloop')
[Gc_pid,Kp_pid,Ti_pid,Td_pid]=myzntune('PID',[0.4167,0.76,1.96,10],'openloop')
step(feedback(series(Gc_p,Gp),1),feedback(series(Gc_pi,Gp),1),feedback(series(G
c_pid,Gp),1))
title('Comparision of P,PI and PID Controllers
(Tuned by Step Response Method)')
legend('Response of P Controller', 'Response of
PI Controller', 'Response of PID Controller')
%% Figure Two %%
figure
% title('Comparision of PID and PID (With Filter )Controllers (Tuned by Step
Response Method)')
[Gc_f,Kp_f,Ti_f,Td_f]=myzntune('PIDF',[0.4167,0.76,1.96,10],'openloop')
[Gcpid,Kppid,Tipid,Tdpid]=myzntune('PID',[0.4167,0.76,1.96,10],'openloop')
% subplot(1,2,2)
step(feedback(series(Gcpid,Gp),1),feedback(series(Gc_f,Gp),1))
title('Comparision of PID and PID (With Filter
)Controllers (Tuned by Step Response Method)')
legend('Response of PID Controller', 'Response
of PID (With Filter)Controller')
step(feedback(series(Gcp,Gp),1),feedback(series(Gcpi,Gp),1),feedback(series(Gcp
id1,Gp),1))
title('Comparision of P,PI and PID Controllers
(Tuned by Sustained Oscillation Method)')
legend('Response of P Controller', 'Response of
PI Controller', 'Response of PID Controller')
%% Figure Four %%
figure
[Gcf,Kpf,Tif,Tdf]=myzntune('PIDF',[12.60,2.80,10],'closeloop')
step(feedback(series(Gcpid1,Gp),1),feedback(series(Gcf,Gp),1))
title('Comparision of PID and PID (With Filter
)Controllers (Tuned by Sustained Oscillation Method)')
legend('Response of PID Controller', 'Response
of PID (With Filter)Controller')
%% Cohen Coon %%
%% Figure Five %%
figure
[Gcp_cc,Kpp_cc,Tip_cc,Tdp_cc]=myCohenCoon('P',[0.4167,0.76,1.96,10]);
[Gcpi_cc,Kppi_cc,Tipi_cc,Tdpi_cc]=myCohenCoon('PI',[0.4167,0.76,1.96,10]);
[Gcpd_cc,Kppd_cc,Tipd_cc,Tdpd_cc]=myCohenCoon('PD',[0.4167,0.76,1.96,10]);
[Gcpid_cc,Kppid_cc,Tipid_cc,Tdpid_cc]=myCohenCoon('PID',[0.4167,0.76,1.96,10]);
[Gcpidf_cc,Kppidf_cc,Tipidf_cc,Tdpidf_cc]=myCohenCoon('PIDF',[0.4167,0.76,1.96,
10]);
step(feedback(series(Gcp_cc,Gp),1),feedback(series(Gcpi_cc,Gp),1),feedback(seri
es(Gcpd_cc,Gp),1),feedback(series(Gcpid_cc,Gp),1),feedback(series(Gcpidf_cc,Gp)
,1))
title('System Response with Cohen Coon Tuned PID Controllers')
legend('Response of P Controller', 'Response of PI Controller', 'Response of PD
Controller','Response of PID Controller','Response of PID(With Filter)
Controller')
[Gcpi0,Kppi0,Tipi0,Tdpi0]=mychrtune('PI',[0.4167,0.76,1.96,10],'set',0)
[Gcpi20,Kppi20,Tipi20,Tdpi20]=mychrtune('PI',[0.4167,0.76,1.96,10],'set',20)
[Gcpid0,Kppid0,Tipid0,Tdpid0]=mychrtune('PID',[0.4167,0.76,1.96,10],'set',0)
[Gcpid20,Kppid20,Tipid20,Tdpid20]=mychrtune('PID',[0.4167,0.76,1.96,10],'set',2
0)
[Gcpidf0,Kppidf0,Tipidf0,Tdpidf0]=mychrtune('PIDF',[0.4167,0.76,1.96,10],'set',
0)
[Gcpidf20,Kppidf20,Tipidf20,Tdpidf20]=mychrtune('PIDF',[0.4167,0.76,1.96,10],'s
et',20)
subplot(1,2,1)
% title('Set Point Regulation with 0% Overshoot ')
step(feedback(series(Gcp0,Gp),1),feedback(series(Gcpi0,Gp),1),feedback(series(G
cpid0,Gp),1),feedback(series(Gcpidf0,Gp),1))
title('System Response with Setpoint Regulation with 0% Overshoot by CHR tune
PID Controller')
legend('Response of P Controller', 'Response of PI Controller','Response of PID
Controller','Response of PID(With Filter) Controller')
subplot(1,2,2)
% title('Set Point Regulation with 20% Overshoot ')
% figure
step(feedback(series(Gcp20,Gp),1),feedback(series(Gcpi20,Gp),1),feedback(series
(Gcpid20,Gp),1),feedback(series(Gcpidf20,Gp),1))
title('System Response with Setpoint Regulation with 20% Overshoot by CHR tune
PID Controller')
legend('Response of P 20%Controller', 'Response of PI Controller','Response of
PID Controller','Response of PID(With Filter) Controller')
%% FIgure Seven %%%
figure
[Gcp_d0,Kpp_d0,Tip_d0,Tdp_d0]=mychrtune('P',[0.4167,0.76,1.96,10],'distrub',0)
[Gcp_d20,Kpp_d20,Tip_d20,Tdp_d20]=mychrtune('P',[0.4167,0.76,1.96,10],'distrub'
,20)
[Gcpi_d0,Kppi_d0,Tipi_d0,Tdpi_d0]=mychrtune('PI',[0.4167,0.76,1.96,10],'distrub
',0)
[Gcpi_d20,Kppi_d20,Tipi_d20,Tdpi_d20]=mychrtune('PI',[0.4167,0.76,1.96,10],'dis
trub',20)
[Gcpid_d0,Kppid_d0,Tipid_d0,Tdpid_d0]=mychrtune('PID',[0.4167,0.76,1.96,10],'di
strub',0)
[Gcpid_d20,Kppid_d20,Tipid_d20,Tdpid_d20]=mychrtune('PID',[0.4167,0.76,1.96,10]
,'distrub',20)
[Gcpidf_d0,Kppidf_d0,Tipidf_d0,Tdpidf_d0]=
mychrtune('PIDF',[0.4167,0.76,1.96,10],'distrub',0)
[Gcpidf_d20,Kppidf_d20,Tipidf_d20,Tdpidf_d20]=mychrtune('PIDF',[0.4167,0.76,1.9
6,10],'distrub',20)
subplot(1,2,1)
step(feedback(series(Gcp_d0,Gp),1),feedback(series(Gcpi_d0,Gp),1),feedback(seri
es(Gcpid_d0,Gp),1),feedback(series(Gcpidf_d0,Gp),1))
title('System Response with Distrubance Rejection with 0% Overshoot by CHR tune
PID Controller')
legend('Response of P Controller', 'Response of PI Controller','Response of PID
Controller','Response of PID(With Filter) Controller')
subplot(1,2,2)
step(feedback(series(Gcp_d20,Gp),1),feedback(series(Gcpi_d20,Gp),1),feedback(se
ries(Gcpid_d20,Gp),1),feedback(series(Gcpidf_d20,Gp),1))
title('System Response with Distrubance Rejection with 20% Overshoot by CHR
tune PID Controller')
legend('Response of P Controller', 'Response of PI Controller','Response of PID
Controller','Response of PID(With Filter) Controller')
step(feedback(series(Gc_wjc,Gp),1),feedback(series(Gcf_wjc,Gp),1))
title('System Response with Wang–Juang–Chan Tuned PID Controllers')
legend('Response of PID Controller','Response of PID(With Filter) Controller')
%% Complete %%