Sie sind auf Seite 1von 61

MCT-431L: Control Systems II

Lab Report

SUBMITTED TO: Mrs.Sumaira


SUBMITTED BY: 2016-R/2015-MC-40
Section : A

DEPARTMENT OF MECHATRONICS & CONTROL ENGINEERING


University of Engineering & Technology, Lahore.
January 08, 2020.
Lab Session 01
Title
1. To study the compensation of control systems using frequency response Method
2. To study the lead compensator design

Apparatus
MATLAB Software

Introduction
In this lab session we discuss the compensation of control systems using frequency response methods. We
examine both the compensator. Let us consider the rotor winder control system shown in Figure

The design objective is to achieve high steady-state accuracy to a ramp input. The steady state error to a
unit ramp input R(s) = 1⁄𝑠 2 is
1
𝑒𝑠𝑠 =
𝑘𝑣
Where
𝐺𝑐 (𝑠)
𝐾𝑣 = lim
𝑠→0 50

The performance specification of overshoot and settling time must be considered, as must the steady-state
tracking error. In all likelihood, a simple gain will not be satisfactory, so we will also consider compensation
utilizing lead compensator, using both Bode diagram method. Our approach is to develop a series of m-file
scripts to aid in the compensator designs.

Consider a simple gain controller


𝐺𝑐 (𝑠) = 𝑘
Then the steady-state error is
50
𝑒𝑠𝑠 =
𝑘
MATLAB Code:

K=[50 100 200 500];


numg=[1]; deng=[1 15 50 0];
sysg=tf(numg,deng);
t=[0:0.1:5];
for i=1:4
sys=feedback(K(i)*sysg,[1]);
y=step(sys,t);
Ys(:,i)=y;
end
plot(t,Ys(:,1),t,Ys(:,2),t,Ys(:,3),t,Ys(:,4))
xlabel('Time (s)'); ylabel('y(t)')

The larger we make K, the smaller is the steady-state


error 𝑒𝑠𝑠 . However, we must consider the effect that
increasing K has on the transient response, as shown in Figure. When K = 500, our steady-state error for a
ramp is 10%, but the overshoot is 70%, and the settling time is approximately 8 seconds for a step input.
We consider this to be unacceptable performance and thus turn to compensation. The two important
compensator types that we consider are lead and lag compensators.

Lead Compensator
The general transfer function of lead compensator is given below
𝐾(𝑠 + 𝑧)
𝐺𝑐 (𝑠) =
(𝑠 + 𝑝)
Where | z | < | p |. The lead compensator will give us the capability to improve the transient response. We
will use a frequency-domain approach to design the lead compensator.
We want a steady-state error of less than 10% to a ramp input and 𝐾𝑣 = 10. In addition to the steady-state
specifications, we want to meet certain performance specifications

1. settling time (with a 2% criterion) 𝑇𝑠 ≤ 3s


2. percent overshoot for a step input ≤10%. Solving for 𝜁 and 𝜔𝑛 using

yields 𝜁 = 0.59 and 𝜔𝑛 = 2.26. We thus obtain the phase margin requirement:
The steps leading to the final design are as follows:

1. Obtain the uncompensated system Bode diagram with K = 500, and compute the phase
margin.
2. Determine the amount of necessary phase lead ∅𝑚
3. Evaluate α from sin ∅𝑚 = (α − 1)⁄(α + 1)
4. Compute 10 log α and find the frequency 𝜔𝑚 on the uncompensated Bode diagram where
the magnitude curve is equal to -10 log α.
5. In the neighborhood of 𝜔𝑚 on the uncompensated Bode diagram, draw a line through the
0-dB point at 𝜔𝑚 with slope equal to the current slope plus 20 dB/decade. Locate the
intersection of the line with the uncompensated Bode diagram to determine the lead
compensation zero location. Then calculate the lead compensator pole location as p = αz
6. Obtain the compensated Bode diagram and check the phase margin. Repeat any steps if
necessary.
7. Raise the gain to account for the attenuation 1/ α.
8. Verify the final design with simulation using step function inputs, and repeat any design
steps if necessary.

We use three m-file in the design. The m-files are given below
Bode diagram of the uncompensated System

K=500;
numg=[1]; deng=[1 15 50 0]; sysg=tf(numg,deng);
sys=K*sysg;
[Gm,Pm,Wcg,Wcp]=margin(sys);
Phi=(60-Pm)*pi/180;
alpha=(1+sin(Phi))/(1-sin(Phi))
[mag,phase,w]=bode(sys);
mag_save(1,:)=mag(:,1,:);
M=-10*log10(alpha)*ones(length(w),1);
semilogx(w,20*log10(mag_save),w,M),
grid
xlabel('Frequency (rad/s)'),
ylabel('Magnitude (dB)')
title('Uncompensated Bode Plot')
hold on
semilogx([0.93462 9.3462 93.462
934.62],[20 0 -20 -40],'--')
Detailed Bode diagram of the compensated system

K=1800;
numg=[1]; deng=[1 15 50 0];
numgc=K*[1 3.5]; dengc=[1 25];
sysg=tf(numg,deng);
sysgc=tf(numgc,dengc);
sys=series(sysgc,sysg);
margin(sys)
where K = 1800 was selected after iteratively using the MATLAB script.

The step response analysis

K=1800;
numg=[1]; deng=[1 15 50 0];
sysg=tf(numg,deng);
numgc=K*[1 3.5]; dengc=[1 25];
sysgc=tf(numgc,dengc);
syso=series(sysgc,sysg);
sys=feedback(syso,[1]);
t=[0:0.01:2];
step(sys,t)
ylabel ('y(t)')

The final lead compensator design is

Where K = 1800 was selected after iteratively using


the m-file it should be clear that the lead compensator
has added phase margin and improved the transient
response as anticipated. To reduce the steady-state
error, we can consider the lag compensator.
Task
Consider the system in Figure

Design the lead compensator to meet the following specifications:

1. settling time (with a 2% criterion) to a unit step less than 2 seconds


2. Percent overshoot less than 10%.

Observations

MATLAB Code:
K=500;
numg1=[-10]; deng1=[1 10];
sysg1=tf(numg1,deng1);
numg2=[-10 -10.1 -0.1]; deng2=[1 2.02 2.0501
0.0602 0.0202]; sysg2=tf(numg2,deng2);
sys=K*series(sysg1,sysg2);
[Gm,Pm,Wcg,Wcp]=margin(sys);
Phi=(60-Pm)*pi/180;
alpha=(1+sin(Phi))/(1-sin(Phi));
[mag,phase,w]=bode(sys);
mag_save(1,:)=mag(:,1,:);
M=-10*log10(alpha)*ones(length(w),1);
semilogx(w,20*log10(mag_save),w,M), grid
xlabel('Frequency (rad/s)'), ylabel('Magnitude
(dB)')
title('Uncompensated Bode Plot')
hold on
semilogx([0.93462 9.3462 93.462 934.62],[20
0 -20 -40],'--')

MATLAB Plot:
Lab Session 2
Title
1. To study the compensation of control systems using s plane Method
2. To study the lag compensator design

Apparatus
MATLAB Software

Introduction
In this lab session we discuss the compensation of control systems using s-plane method. We examine lag
compensator. Let us consider the rotor winder control system shown in Figure

The design objective is to achieve high steady-state accuracy to a ramp input. The steady state error to a
unit ramp input R(s) = 1⁄𝑠 2 is
1
𝑒𝑠𝑠 =
𝑘𝑣
Where
𝐺𝑐 (𝑠)
𝐾𝑣 = lim
𝑠→0 50

The performance specification of overshoot and settling time must be considered, as must the steady-state
tracking error. In all likelihood, a simple gain will not be satisfactory, so we will also consider compensation
utilizing lag compensator, using root locus plot design method. Our approach is to develop a series of m-
file scripts to aid in the compensator designs

Lag compensator
The lag compensator which has the form
𝐾(𝑠 + 𝑧)
𝐺𝑐 (𝑠) =
(𝑠 + 𝑝)
Where | p | < | z |. We will use a root locus approach to design the lag compensator, although it can be done
using a Bode diagram as well. The desired root location region of the dominant roots is specified by
𝜁 = 0.59 𝑎𝑛𝑑 𝜔𝑛 = 2.26
The steps in the design are as follows:

1. Obtain the root locus of the uncompensated system.


2. Locate suitable root locations on the uncompensated system that lie in the region defined
by 𝜁 = 0.59 and 𝜔𝑛 = 2.26.
3. Calculate the loop gain at the desired root location and the system error constant,𝐾𝑣,𝑢𝑛𝑐
4. Compute α = 𝐾𝑣,𝑐𝑜𝑚𝑝 ⁄𝐾𝑣,𝑢𝑛𝑐 where 𝐾𝑣,𝑐𝑜𝑚𝑝 = 10
5. With α known, determine suitable locations of the compensator pole and zero so that the
compensated root locus still passes through the desired location.
6. Verify with simulation and repeat any steps if necessary.

The design methodology is illustrated in given m files using the rlocfind function, we can compute the gain
K associated with the roots of our choice on the uncompensated root locus that lie in the performance region.
We then compute α to ensure that we achieve
the desired 𝐾𝑣 . We place the lag compensator
pole and zero to avoid affecting the
uncompensated root locus.
Uncompensated root locus

numg=[1]; deng=[1 15 50 0];


sysg=tf(numg,deng);
clf; rlocus(sysg); hold on
zeta=0.5912; wn=2.2555;
x=[-10:0.1 :-zeta*wn]; y=-(sqrt(1-
zeta^2)/zeta)*x;
xc=[-10:0.1 :-zeta*wn]; c=sqrt(wn^2-
xc.^2);
plot(x,y,':',x,-y,':')
axis([-15,1,-10,10]);

Compensated root locus

numg=[1]; deng=[1 15 50 0];


sysg=tf(numg,deng);
numgc=[1 0.1]; dengc=[1 0.01];
sysgc=tf(numgc,dengc);
sys=series(sysgc,sysg);
clf; rlocus(sys); hold on
zeta=0.5912; wn=2.2555;
x=[-10:0.1 :-zeta*wn]; y=-(sqrt(1-
zeta^2)/zeta)*x;
xc=[-10:0.1 :-zeta*wn];c=sqrt(wn^2-
xc.^2);
plot(x,y,':',x,-y,':',xc,c,':',xc,-c,':')
axis([-15,1,-10,10]);
Step response

K=100;
numg=[1]; deng=[1 15 50 0]; sysg=tf(numg,deng);
numgc=K*[1 0.1]; dengc=[1 0.01]; sysgc=tf(numgc,dengc);
syso=series(sysgc,sysg);
sys=feedback(syso,[1]);
step(sys)

The settling time and overshoot specifications are not satisfied, but 𝐾𝑣 = 10, as desired. It is possible to
continue the design iteration and refine the compensator somewhat, although it should be clear that the lag
compensator has improved the steady-state errors to a ramp input relative to the lead compensator design.
The final lag compensator design is
100(𝑠 + 0.1)
𝐺𝑠 (𝑠) =
𝑠 + 0.01
The resulting performance is summarized in Table
Task
Consider the control system shown in Figure.

a) Design a lag compensator using root locus methods to meet the following specifications:
1. steady state error less than 10% for a step input,
2. phase margin greater than 45°, and
3. settling time (with a 2% criterion) less than 5 seconds for a unit step input.
b) Test the controller developed in part (a) by simulating the closed-loop system response to
unit step input. Provide the time histories of the output y(t).
c) Compute the phase margin using the margin function.

Observations

MATLAB codes:

%% Lab Task

% uncompensated
clear all
numg=[1 10]; deng=[1 2 20];
sysg=tf(numg,deng);
clf; rlocus(sysg); hold on
zeta=0.5912; wn=2.2555;
x=[-20:0.1 :-zeta*wn]; y=-(sqrt(1-zeta^2)/zeta)*x;
plot(x,y,':',x,-y,':')
rlocfind(sysg)
axis([-25,1,-20,20]);

%compensated
clear all
numg=[1 10]; deng=[1 2 20]; sysg=tf(numg,deng);
numgc=10*[1 .6]; dengc=[1 .3]; sysgc=tf(numgc,dengc);
sys=series(sysgc,sysg);
sys1=feedback(sys,1);
step(sys1)
clf; rlocus(sys);
hold on
zeta=0.5912; wn=2.2555;
x=[-10:0.1 :-zeta*wn]; y=-(sqrt(1-zeta^2)/zeta)*x;
xc=[-10:0.1 :-zeta*wn];c=sqrt(wn^2-xc.^2);
plot(x,y,':',x,-y,':',xc,c,':',xc,-c,':')
axis([-15,1,-10,10]);

MATLAB Plots:

Compensated Plant: Uncompensated Plant:


Lab Session 3
Title
3. To study the controllability and observability
4. To study the full state feedback control design.

Apparatus
MATLAB Software

Introduction
Controllable system: A linear system is (completely) controllable if and only if the controllability matrix
𝐏𝐜 = [𝐁 𝐀𝐁 𝐀𝟐 𝐁 … . 𝐀𝐧−𝟏 𝐁] has full rank, where A is an n x n matrix. For single-input, single-output linear
systems, the system is controllable if and only if the determinant of the n x n controllability matrix is nonzero
Observable: A linear system is (completely) observable if and only if the observability matrix 𝐏𝟎 =
[𝐂 ; 𝐂𝐀 ; 𝐂𝐀𝟐 … . 𝐂𝐀𝐧−𝟏 ] has full rank, where A is an n x n matrix. For single-input, single-output linear
systems, the system is observable if and only if the determinant of the n x n observability matrix P() is
nonzero.
Full-state feedback control law: A control law of the form u = -Kx where x is the state of the system
assumed known at all times.
In the state variable feedback form controllability and observability can be checked using the functions
“ctrb” and” obsv”, respectively. The inputs to the ctrb function are the system matrix A and the input matrix
B; the output of ctrb is the controllability matrix Pc. Similarly, the input to the obsv function, shown in
Figure, is the system matrix A and the output matrix C; the output of obsv is the observability matrix Po.
The controllability matrix Pc is a function only of A and B, while the observability matrix Po is a function
only of A and C.
Example: Consider the system given below check the controllability and observability of the system.
−6 2 0 5
𝑥̇ = [ 4 0 7 ] 𝑥 + [0] 𝑢
−10 1 11 1
𝑦 = [1 2 1]𝑥

Solution:

clear all,clc
A=[-6 2 0;4 0 7;-10 1 11];
B=[5;0;1];
C=[1 2 1];
Pc=ctrb(A,B);
Po=obsv(A,C)
detPc=det(Pc)
detPo=det(Po)
if detPc==0
disp('system is not controllable')
else
disp('system is controllable')
end
if detPo==0
disp('system is not observable')
else
disp('system is observable')
end
MATLAB Result:
Po =

1 2 1
-8 3 25
-190 9 296
detPc =
-84933
detPo =
-3.6030e+03
system is controllable
system is observable
Now we discussed Ackermann's formula to place the poles of the system at desired locations. The function
acker calculates the gain matrix K to placle the closed-loop poles at the desired locations. The acker function
is illustrated in Figure

Example: Consider the third-order system with the differential equation

𝑑3 𝑦 𝑑2 𝑦 𝑑1 𝑦
+ 5 + 3 + 2𝑦 = 𝑢
dt 3 dt 2 dt
The state space form is
0 1 0 0
𝑥̇ = [ 0 0 1 ] 𝑥 + [0] 𝑢
−2 −3 −5 1
𝑦 = [1 0 0]𝑥
Solution:

A=[0 1 0;0 0 1;-2 -3 -5];


B=[0;0;1];
C=[1 0 0];
Pc=ctrb(A,B);
Po=obsv(A,C)
detPc=det(Pc)
detPo=det(Po)
P=[-1+j;-1-j;-5];
K=acker(A,B,P)

MATLAB Result
Po =

1 0 0
0 1 0
0 0 1
detPc =
-1
detPo =
1
K =

8 9 2
Using Simulink
Or you can use ODE45 or ODE23 for simulation of system.
Step 1: Define the differential equation as a MATLAB function (mydiff.m):

function ydot=mydiff(t,y)
ydot=zeros(3,1);
ydot(1)=y(2);
ydot(2)=y(3)
ydot(3)= -7*y(3)-12*y(2)-10*y(1);
end
Step 2: Use one of the built-in ODE solver (ode23, ode45, ...) in a Script

clear all,clc
xo=[5 0 0];
tspan = [0 20];
[t y]=ode45('mydiff',tspan,xo);
plot(t,y(:,1),'g',t,y(:,2),'r',t,y(:,3),'b')

Task:
Design the Full-State Feedback Control Law for Inverted Pendulum for settling
time half second.
The system matrices are given below

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

System parameters are

• l = 0.098 m
• g=9.8 m/𝑠 2
• m=0.825 kg
• M=8.085 kg
Observations

MATLAB Code:
%% Task
clear all
clc
g=9.8; l=.098; m=.825; M=8.085;
s=tf('s');
wn=sqrt(g/l);
z=8/wn;
a=30; b=180;
A=[0 1 0 0;0 0 -m*g/M 0; 0 0 0 1;0 0 g/l 0];
B=[0;1/M;0;-1/(M*l)]; C=[1 0 0 0]; D=[0];
eq=(s^2+2*z*wn*s+wn^2)*(s^2+a*s+b)
r=roots([1 46 760 5880 18000]);
k=place(A,B,r);
A1=A-B*k;
system= ss(A1,B,C,D);
% step(system)
stepinfo(system)

MATLAB Plot:

Conclusion

As it can be seen, using the Ackermann’s formula available in MATLAB, full state feedback controller is
designed, which helps stabilize the system in given time. Stepinfo gives the exact transient response
values for the system.
Lab Session 4
Objective
The objective of this Lab is to learn the estimator design and implement it with full state feedback
control for regulator.
Apparatus
MATLAB Software
Introduction
The basic estimator design involves the creating the states using the output of the system. The simplest
form of observer is the Luenberger Observer which uses the system mathematical model and compare the
output of the system and the mathematical model and the difference is amplified and fed back to estimate
the correct value of the state.
The differential equation of the observer is
𝑋̂̇ = 𝐴𝑋̂ + 𝐵𝑈 + 𝐿(𝑌 − 𝑌̂)
Here 𝑋̂ 𝑎𝑛𝑑 𝑌̂ represent estimated states and L is the observer gain. The gain is decided on the basis of
poles of the observer and how fast the error needs to be eliminated.
The goal of the observer is to provide an estimate x so that 𝑥 → 𝑥̂ as 𝑡 → ∞ Remember that we do not know
𝑥(𝑡0 ) precisely; therefore, we must provide an initial estimate 𝑥̂(𝑡0 ) to the observer. Define the observer
estimation error as
𝑒(𝑡) = 𝑥(𝑡) − 𝑥̂(𝑡)
The observer design should produce an observer with the property that 𝑒(𝑡) → 0 as 𝑡 → 0. One of the
main results of systems theory is that if the system is completely observable, we can always find L so that
the tracking error is asymptotically stable as desired. Taking the time-derivative of the estimation error
yields

𝑒̇ = 𝑥̇ − 𝑥̂̇
and using the system model and the observer we obtain
𝑒̇ = 𝐴𝑥 + 𝐵𝑢 − 𝐴𝑥̂ − 𝐵𝑢_𝐿(𝑦 − 𝐶𝑥̂)
𝑒̇ (𝑡) = (𝐴 − 𝐿𝐶)𝑒(𝑡)
The characteristic equation is

det(𝜆𝐼 − (𝐴 − 𝐿𝐶)) = 0

the observer design process reduces to finding the matrix L such that the roots of the characteristic equation
lie in the left half-plane. This can always be accomplished if the system is completely observable.
Example:
Consider the Inverted pendulum the system matrix is

System parameters are

• l = 0.098 m
• g=9.8 m/𝑠 2
• m=0.825 kg
• M=8.085 kg

A=[0 1 0 0;0 0 -1 0;0 0 0 1;0 0 100 0];

B=[0;0.1237;0;-1.2621];
C=[1 0 0 0];
D=[0;0;0;0];
Pc=ctrb(A,B);
Po=obsv(A,C);
detPc=det(Pc)
detPo=det(Po)
P=[-3+2i;-3-2i;-5;-6]
Q=[-30+20i,-30-20i,-50,-60];
K=acker(A,B,P)
L=acker(A',C',Q)

MATLAB Result
detPc =

196.5402

detPo =

P =

-3.0000 + 2.0000i
-3.0000 - 2.0000i
-5.0000 + 0.0000i
-6.0000 + 0.0000i

K =

-35.1101 -29.0784 -169.0382 -16.3196

L =

170 11000 -340000 -5000000


TASK
Using given Simulink diagram, design observer controller

Observations

The given Simulink model was recreated in the environment and the values of K and L were implemented
in the gain matrices, which helps get the desired response.

Conclusion
The given Simulink model was recreated in the environment and the values of K and L were implemented
in the gain matrices, which helps get the desired response.
Lab Session 05
Objective
Implement Compensator Design by pole placement using SISO tool in MATLAB.

Apparatus
 MATLAB

Introduction to Compensator
In redesigning a control system to alter the system response, an additional component is inserted
within the structure of the feedback system. It is this additional component or device that equalizes
or compensates for the performance deficiency. The compensating device may be electric,
mechanical, hydraulic, pneumatic, or some other type of device or network and is often called a
compensator.

Types of Compensation
 Cascade Compensation
 Feedback Compensation
 Output, or Load Compensation
 Input Compensation

Introduction to SISO Toolbox MATLAB


The Single Input Single Output Design Tool is a graphical-user interface (GUI) that allows you to
use root-locus, Bode diagram, and Nichols plot techniques to design compensators. Using SISO
Design Tool, you can graphically tune gains and dynamics of the compensator (C) and pre-filter
(F). In SISO Tool, plots are dynamically linked; for example, if you change the gain in the root
locus, it immediately affects the Bode diagrams as well.

Procedure
Let us consider Lead-compensator example, where the uncompensated loop transfer function is
1
G(s) 
s2

The specifications for the system are


 Settling time (with a 2% criterion), Ts ≤ 4 s
 Percent overshoot for a step input P.O. < 35%
 Enter the transfer function for the plant, G(s), in MATLAB command window or M-File.
sys=tf(1,[1 0 0])

 Type ‘sisotool’ in command prompt


sisotool

SISO Design Tool window appear as shown in figure 1.

Figure 1: SISO Design Tool

You can select control architecture based on controller position and number of feedback loops
as shown in figure 1. Here we select basic control architecture i.e. Cascade compensation (C)
with pre-filter (F).

 Click ‘System data’ to import data for compensation. Following window appear as shown
in figure 2
o G represent Plant TF
o H represent Feedback TF
o C represent Compensator TF
o F represent Pre-Filter TF
By selecting ‘Browser’ option, you can import system TF as shown in figure 2 < sys >.

Figure 2: Import Data


 After clicking OK, following window appear representing root locus and bode plot of G(s)
TF. As we can see, two poles at origin and corresponding bode plot.

Figure 3: Root Locus and Bode Plot

 Multiple plots can be shown at a time as we select root locus and bode plot only. We can
also plot Nichlos graph.

Figure 4: Graphical Tuning


 Now we can add pole/zero at desired location simply by selecting pole/zero and place it
using bar as shown in figure 5. We can also add complex pole and zero depend on
requirement.

Figure 5: Pole/zero placement

 We will choose desired location at


s  1  j 2

Now place zero and pole in LHP in such a way that root locus pass through desired
location. In case of lead compensator, |zero| < |pole|.

 By adding pole and zero, root locus pass through desired location as shown by circle in
figure 6.

Figure 6: Compensated System Root locus

 Compensator TF can be represented now as


Figure 7: Compensator Editor

 Step response to compensated system can be plot by selecting ‘Analysis Plot’ option and
Tick step response

Figure 8: Step Response


Task
Design a lag compensator for following TF using SISO Tool MATLAB
1
G(s) 
s ( s  2)

Design specs:
 Velocity Constant Kv should be equal to 20
 ζ = 0.45

Observations

Compensated Root Locus:


Compensated Step Response:

Conclusions
Using SISO tool for designing a compensator is easier than the conventional method of
calculating the locations of the poles and zeroes. Using this tool, a lag compensator can be
designed, which falls under the requirements.
Lab Session 06
Objective
Linear quadratic regulator design and analysis

Introduction
The theory of optimal control is concerned with operating a dynamic system at minimum cost.
The case where the system dynamics are described by a set of linear differential equations and the cost is
described by a quadratic function is called the LQ problem. One of the main results in the theory is that
the solution is provided by the linear–quadratic regulator (LQR), a feedback controller whose equations
are given below. The LQR is an important part of the solution to the LQG (linear–quadratic–Gaussian)
problem. Like the LQR problem itself, the LQG problem is one of the most fundamental problems in
control theory.
The LQR algorithm reduces the amount of work done by the control systems engineer to optimize
the controller. However, the engineer still needs to specify the cost function parameters and compare the
results with the specified design goals. Often this means that controller construction will be an iterative
process in which the engineer judges the "optimal" controllers produced through simulation and then
adjusts the parameters to produce a controller more consistent with design goals.
From the main problem, the dynamic equations of the inverted pendulum system in state-space form are
the following
𝑥̇ 0 1 0 0 𝑥 0
𝑥̈ 0 −0.1818 2.6727 0 𝑥̇ 1.8181
[ ̇] = [ ] [∅] + [ ]𝑢
∅ 0 0 0 1 0
∅̈ 0 −0.4545 31.1818 0 ∅̇ 4.5455

To see how this problem was originally set up and the system equations were derived, consult the
Inverted Pendulum: System Modeling page. For this problem the outputs are the cart's displacement (x in
meters) and the pendulum angle ( 𝜋 in radians) where 𝜋 represents the deviation of the pedulum's position
from equilibrium, that is, 𝜃 = 𝜋 + ∅.
The design criteria for this system for a 0.2-m step in desired cart position $x$ are as follows:

 Settling time for x and theta of less than 5 seconds


 Rise time for x of less than 0.5 seconds
 Pendulum angle theta never more than 20 degrees (0.35 radians) from the vertical
 Steady-state error of less than 2% for x and theta

Open-loop poles
The first step in designing a full-state feedback controller is to determine the open-loop poles of the
system. Enter the following lines of code into an m-file. After execution in the MATLAB command
window, the output will list the open-loop poles (eigenvalues of A) as shown below.
M = 0.5;
m = 0.2;
b = 0.1;
I = 0.006;
g = 9.8;
l = 0.3;
p = I*(M+m)+M*m*l^2; %denominator for the A and B matrices
A = [0 1 0 0;
0 -(I+m*l^2)*b/p (m^2*g*l^2)/p 0;
0 0 0 1;
0 -(m*l*b)/p m*g*l*(M+m)/p 0];
B=[ 0;
(I+m*l^2)/p;
0;
m*l/p];
C = [1 0 0 0;
0 0 1 0];
D = [0;
0];
states = {'x' 'x_dot' 'phi' 'phi_dot'};
inputs = {'u'};
outputs = {'x'; 'phi'};
sys_ss = ss(A,B,C,D,'statename',states,'inputname',inputs,'outputname',outputs);
poles = eig(A)
poles =
0
-0.1428
-5.6041
5.5651
As you can see, there is one right-half plane pole at 5.5651. This should confirm your intuition that the
system is unstable in open loop.
Linear Quadratic Regulation (LQR)
The next step in the design process is to find the vector of state-feedback control gains K
assuming that we have access (i.e. can measure) all four of the state variables. This can be accomplished
in a number of ways. If you know the desired closed-loop pole locations, you can use the MATLAB
commands place or acker. Another option is to use the lqr command which returns the optimal controller
gain assuming a linear plant, quadratic cost function, and reference equal to zero (consult your textbook
for more details).
Before we design our controller, we will first verify that the system is controllable. Satisfaction of
this property means that we can drive the state of the system anywhere we like in finite time (under the
physical constraints of the system). For the system to be completely state controllable, the controllability
matrix must have rank n where the rank of a matrix is the number of linearly independent rows (or
columns). The controllability matrix of the system takes the form shown below. The number n
corresponds to the number of state variables of the system. Adding additional terms to the controllability
matrix with higher powers of the matrix A will not increase the rank of the controllability matrix since
these additional terms will just be linear combinations of the earlier terms.

Since our controllability matrix is 4x4, the rank of the matrix must be 4. We will use the
MATLAB command ctrb to generate the controllability matrix and the MATLAB command rank to test
the rank of the matrix. Adding the following additional commands to your m-file and running in the
MATLAB command window will produce the following output.
co = ctrb(sys_ss);
controllability = rank(co)
controllability =
4
Therefore, we have verified that our system is controllable and thus we should be able to design a
controller that achieves the given requirements. Specifically, we will use the linear quadratic regulation
method for determining our state-feedback control gain matrix $K$. The MATLAB function lqr allows
you to choose two parameters, R and Q, which will balance the relative importance of the control effort
(u) and error (deviation from 0), respectively, in the cost function that you are trying to optimize. The
simplest case is to assume R=1, and Q = C'C. The cost function corresponding to this R and Q places
equal importance on the control and the state variables which are outputs (the pendulum's angle and the
cart's position). Essentially, the lqr method allows for the control of both outputs. In this case, it is pretty
easy to do. The controller can be tuned by changing the nonzero elements in the Q matrix to achieve a
desirable response. To observe the structure of Q, enter the following into the MATLAB command
window to see the output given below.
Q = C'*C
Q=
1 0 0 0
0 0 0 0
0 0 1 0
0 0 0 0

The element in the (1,1) position of represents the weight on the cart's position and the element in the

(3,3) position represents the weight on the pendulum's angle. The input weighting will remain at 1.

Ultimately what matters is the relative value of and , not their absolute values. Now that we know

how to interpret the matrix, we can experiment to find the matrix that will give us a "good"

controller. We will go ahead and find the matrix and plot the response all in one step so that changes
can be made in the control and seen automatically in the response. Add the following commands to the
end of your m-file and run in the MATLAB command window to get the following value for and the
response plot shown below.
Q = C'*C;
R = 1;
K = lqr(A,B,Q,R)
Ac = [(A-B*K)];
Bc = [B];
Cc = [C];
Dc = [D];
states = {'x' 'x_dot' 'phi' 'phi_dot'};
inputs = {'r'};
outputs = {'x'; 'phi'};
sys_cl = ss(Ac,Bc,Cc,Dc,'statename',states,'inputname',inputs,'outputname',outputs);
t = 0:0.01:5;
r =0.2*ones(size(t));
[y,t,x]=lsim(sys_cl,r,t);
[AX,H1,H2] = plotyy(t,y(:,1),t,y(:,2),'plot');
set(get(AX(1),'Ylabel'),'String','cart position (m)')
set(get(AX(2),'Ylabel'),'String','pendulum angle (radians)')
title('Step Response with LQR Control')
K=
-1.0000 -1.6567 18.6854 3.4594

Figure 9: Step response with LQR Control

The curve in red represents the pendulum's angle in radians, and the curve in blue represents the cart's
position in meters.

You may have noted that if you increased the values of the elements of even higher, you could improve
the response even more. The reason this weighting was chosen was because it just satisfies the transient
design requirements. Increasing the magnitude of more would make the tracking error smaller but

would require greater control force . More control effort generally corresponds to greater cost (more
energy, larger actuator, etc.).
Task
 Improve the response by increasing value of element Q further to achieve fast response.

Observations
By changing the values of the Q and R matrices, it can be seen that the performance parameters of
the system are changed. For example, state accuracy is attained by improving the value of Q, while
fuel cost is effectively reduced by increasing the value of R. This is the beauty of the LQR
controller.

Conclusion
LQR is an effective technique for controller design in the modern control theory.
Lab Session 07
Objective
To study the PID controller and its effects on the feedback loop response

Apparatus
MATLAB Software

Introduction
Consider the following unity feedback system

A system to be controlled is called plant and controller provides excitation for the plant; Designed to control
the overall system behavior.
The transfer function of the PID controller looks like the following:

KI KDs2  K ps  KI
Gc ( s)  K p   KDs 
s s
 KP = Proportional gain
 KI = Integral gain
 KD = Derivative gain
First, let's take a look at how the PID controller works in a closed-loop system using the schematic shown
above. The variable (e) represents the tracking error, the difference between the desired input value (R) and
the actual output (Y). This error signal (e) will be sent to the PID controller, and the controller computes
both the derivative and the integral of this error signal. The signal (u) just past the controller is now equal
to the proportional gain (KP) times the magnitude of the error plus the integral gain (KI) times the integral
of the error plus the derivative gain (KD) times the derivative of the error.
de(t )
u  K p e(t )  K I  e(t )dt  K D
dt
This signal (u) will be sent to the plant, and the new output (Y) will be obtained. This new output (Y) will
be sent back to the sensor again to find the new error signal (e). The controller takes this new error signal
and computes its derivatives and its internal again. The process goes on and on.
Example
Suppose we have a simple mass, spring, and damper system

Applying Newton 2nd Law, we get


 
M x  b x  kx  F
Taking the Laplace transform of the equation, we get

Ms 2 X (s)  bsX (s)  kX (s)  F (s)


The transfer function between the displacement X(s) and the input F(s) then becomes

X ( s) 1

F ( s) Ms  bs  k
2

Let suppose,

 M = 1kg
 b = 10 N.s/m
 k = 20 N/m
 F(s) = 1

Plug these values into transfer function, we get

X ( s) 1
G ( s)   2
F ( s) s  10s  20
To study the effect of Proportional, Differential and Integral Controller on

 Fast rise time


 Minimum overshoot
 No steady-state error

Open-loop Step Response


MATLAB CODE:
clc; clear all; close all;
num=1;
den=[1 10 20];
plant=tf(num,den);
step(plant)

Figure 10: Step response of OL G(s)

The DC gain of the plant transfer function is 1/20, so 0.05 is the final value of the output to a unit step input.
This corresponds to the steady-state error of 0.95, quite large indeed. Furthermore, the rise time is about
one second, and the settling time is about 1.5 seconds. Let's design a controller that will reduce the rise
time, reduce the settling time, and eliminates the steady-state error.

Proportional Control
The closed-loop transfer function of the above system with a proportional controller is

X ( s) Kp
 2
F ( s) s  10s  (20  K p )

Let the proportional gain (KP) =300


MATLAB CODE:
Kp=300;
contr=Kp;
sys_cl=feedback(contr*plant,1);
t=0:0.01:2;
step(sys_cl,t)

Figure 11: Step response of P-type Controller

The above shows that the proportional controller reduced both the rise time and the steady-state error,
increased the overshoot, and decreased the settling time by small amount.

Proportional-Derivative control
The closed-loop transfer function of the given system with a PD controller is

X ( s) KDs  K p
 2
F ( s) s  (10  K D ) s  (20  K p )

Let KP = 300 as before and let KD =10


MATLAB CODE:
Kp=300;
Kd=10;
contr=tf([Kd Kp],1);
sys_cl=feedback(contr*plant,1);
t=0:0.01:2;
step(sys_cl,t)
Figure 12: Step Response of PD-type Controller

This shows that the derivative controller reduced both the overshoot and the settling time, and had a small
effect on the rise time and the steady-state error.

Proportional-Integral control
Before going into a PID control, let's take a look at a PI control. For the given system, the closed-loop
transfer function with a PI control is

X ( s) K ps  KI
 3
F ( s) s  10s  (20  K p s)  K I
2

Let's reduce the KP = 30, and let KI = 70


MATLAB CODE:
Kp=30;
Ki=70;
contr=tf([Kp Ki],[1 0]);
sys_cl=feedback(contr*plant,1);
t=0:0.01:2;
step(sys_cl,t)
Figure 13: Step Response of PI-type Controller

We have reduced the proportional gain (Kp) because the integral controller also reduces the rise time and
increases the overshoot as the proportional controller does (double effect). The above response shows that
the integral controller eliminated the steady-state error.
Proportional-Integral-Derivative control
Now, let's take a look at a PID controller. The closed-loop transfer function of the given system with a PID
controller is

X ( s) KDs2  K ps  KI

F ( s) s 3  (10  K D ) s 2  (20  K p ) s  K I

After several trial and error runs, the gains Kp=350, Ki=300, and Kd=22 provided the desired response. To
confirm, enter the following commands to an m-file and run it in the command window. You should get
the following step response.
MATLAB CODE:
Kp=350;
Ki=300;
Kd=22;
contr=tf([Kd Kp Ki],[1 0]);
sys_cl=feedback(contr*plant,1);
t=0:0.01:2;
step(sys_cl,t)

Figure 14: Step Response of PID controller

Now, we have obtained a closed-loop system with no overshoot, fast rise time, and no steady-state error.
The characteristics of P, I, and D controllers
The proportional controller (KP) will have the effect of reducing the rise time and will reduce, but never
eliminate, the steady state error. An integral controller (K I) will have the effect of eliminating the steady
state error, but it may make the transient response worse. A derivative control (KD) will have the effect of
increasing the stability of the system, reducing the overshoot and improving the transient response.
Effect of each controller KP, KI and KD on the closed-loop system are summarized below

Task 1
Consider a process given below to be controlled by a PID controller
400
𝐺𝑝 (𝑠) =
𝑠(𝑠 + 48.5)

a) Obtain the unit step response of Gp(s).


b) Try PI controllers with (Kp=2, 10, 100), and Ki=Kp/10. Investigate the unit step response
in each case, compare the results and comment.
c) Let Kp=100, Ki=10, and add a derivative term with (Kd=0.1, 0.9, 2). Investigate the unit
step response in each case, compare the results and comment.

Based on your results in parts b) and c) above what do you conclude as a suitable PID controller for this
process and give your justification.

Observations

MATLAB Code:
s= tf('s');
sys= 400/(s*(s+48.5));
% kp=2;
% kp=10;
% kp=100;
% ki=kp/10;
% sys1= (kp*s+ki)/s;
% syst=
series(sys,sys1);
% system=
feedback(syst,1);
kp=100;
ki=kp/10;
% kd=15;
% kd=5;
kd=2;
sys1=
(kp*s+ki+kd*s^2)/s;
syst=
series(sys,sys1);
system=
feedback(syst,1);
step(system)

Step Response of the System


PI Controller

With Kp=10; Ki=Kp/10: With Kp=2; Ki=Kp/10:

With Kp=100; Ki=Kp/10:


PID Controller

With Kp=100; Ki=Kp/10; Kd=0.9: With Kp=100; Ki=Kp/10; Kd=0.1:

With Kp=100; Ki=Kp/10; Kd=02:

Conclusion

It can be seen from the figures, as well as the table above, the PID controller can be used to
manipulate the transient response characteristics of the system. The initially unstable system was
made stable by incorporating the controller. Kd, Kp, Ki all have specific functions, which can be
seen in the aforementioned table.
Lab Session 08
Objective
To Design Robust PID Controller

Apparatus
MATLAB

Introduction
Physical systems and the external environment in which they operate cannot be modeled precisely,
may change in an unpredictable manner, and may be subject to significant disturbances. The design
of control systems in the presence of significant uncertainty requires the designer to seek a robust
system.
“A robust control system exhibits the desired performance despite the presence of significant
process uncertainty”
The process model will always be an inaccurate representation of the actual physical system
because of
 Parameter changes
 Un-modeled dynamics
 Un-modeled time delays
 Changes in equilibrium point (operating point)
 Sensor noise
 Unpredicted disturbance inputs
Multiple methods are available for robust design, including root locus, frequency response, ITAE
methods for a robust PID systems, internal model control, and pseudo-quantitative feedback
method. Here we used Integral time-weighted absolute error method to design robust PID
controller. Let consider a plant transfer function with un-certain parameters
K
G p ( s) 
(s  1) 2

Where K and τ are varies,


1≤𝐾≤2
0.5 ≤ 𝜏 ≤ 1
Step response of plant transfer function with sampled data of uncertain parameters
MATLAB Code
clc; clear all; close all;
k=ureal('k',1.5,'Plusminus',0.5) % Nominal value of k is 1.5 with +/-
0.5
t=ureal('t',0.75,'Plusminus',0.25) % Nominal value of t is 0.75 with
+/- 0.25
P=tf([k],[t 1])
step(P,getNominal(P),4)
legend('Sampled uncertainty','Nominal')

Step Response

Figure 15: Step Response

As we can see from step response that there have multiple response corresponding to uncertain
parameter k and τ. We wish to design robust PID controller to eliminate disturbance effect or
parameter variation on system response.
Design specification
 Percent overshoot should be less than 2 %
 Settling time should be less than 2 sec ( 2 % criteria)
The transfer function of the PID controller is

KI KDs2  K ps  KI
Gc ( s)  K p   KDs 
s s
Therefore, the closed-loop transfer function without pre-filtering i.e. 𝐺𝑝(𝑠) = 1
We assume for simplicity K=1 and τ=1, closed loop Transfer function become

Gc ( s )G ( s ) KDs2  K ps  KI
T ( s)   3
1  Gc ( s )G ( s ) s  (2  K D ) s 2  (1  K p ) s  K I

Using integral time-weighted absolute error method to find robust gains values to achieve desired
response irrespective of uncertain parameter variation. Closed loop transfer function are of 3rd
order, we choose the optimum coefficients of the characteristic equation for ITAE

s 3  1.75 n s 2  2.15 n2 s   n3

We need to select 𝜔𝑛 = 8 in order to meet the settling time requirement. By comparison


characteristics equation of closed loop transfer function and ITAE, we calculate following gains
values

2  K D  14 => K D  12

1  K p  137.6 => K p  136.6

K I  512

These are the PID gains values which are robust to uncertain parameter variation, closed loop
transfer function become

12( s 2  11.38s  42.67)


T1 ( s)  3
s  14s 2  137.6s  512
Pre-filter Gp(s) transfer function are
42.67
G p ( s) 
s 2  11.38s  42.67

By multiplying pre-filter TF and closed loop TF, we get


512
T1 ( s ) 
s  14s  137.6s  512
3 2
Now we check step response to different values of K and τ,
MATLAB Code
clc;clear all;close all;
k=1; t=1;
kd=12; kp=136.6; ki=512;
sys=tf([k],[conv([t 1],[t 1])]);
Gc=tf([kd kp ki],[1 0]);
loop=series(Gc,sys);
cl_loop=feedback(loop,1);
Gp=tf([42.67],[1 11.38 42.67]);
final=series(Gp,cl_loop);
stepinfo(final)
step(final)

K=1 and τ =1
Step Response

Figure 16: Step Response when K=1 and t=1


K=1 and τ =0.5
Step Response

Figure 17: Step Response when K=1 and t=0.5

K=2 and τ =1
Step Response

Figure 18: Step Response when K=2 and t=1


Task
Consider Transfer function

Km
G( s) 
(s  p1 )( s  p2 )

Where nominal values are Km = 4, p1 = 1, and p2 = 4. However, the range of variation is


3 ≤ 𝐾𝑚 ≤ 5,
0.5 ≤ 𝑝1 ≤ 1.5
3.5 ≤ 𝑝2 ≤ 4.5
Design Specs:
 Percent overshoot less than 13%
 Settling time less than 2 seconds for a unit step input
 Choose 𝜔n to achieve desired specs

Observations
Matlab Code
s= tf('s');
% km=ureal('km',4,'Plusminus',1);
% p1=ureal('p1',1,'Plusminus',0.5);
% p2=ureal('p2',4,'Plusminus',0.5);
km=4; p1=1; p2=4;
sys= km/((s+p1)*(s+p2));
% step(sys,getNominal(sys),6)
% legend('Sampled
uncertainty','Nominal')
kd= 0.71875; kp=9.8844; ki=22.78125;
gc= ((kd*s^2)+(kp*s)+ki)/s;
system= series(sys,gc);
system= feedback(system,1)
% prefilter=
42.88/(1.125*s^2+22.34*s+42.88);
prefilter= 91.13/(s^2+39.54*s+91.13);
system1= prefilter*system;
stepinfo(system1)

Conclusions
Robust controller design is useful in the environments where the plant parameters are susceptible
to change. These controllers help maintain the required parameters of the system. Using the
ITAE standard equation, a robust PID controller can be designed.
Lab Session 09
Objective
To study the digital control system and compensator design in digital systems.

Apparatus
 MATLAB

Introduction
The figure below shows the typical continuous-time feedback system. Almost all continuous-time
controllers can be implemented employing analog electronics

Figure 19: CT System

The continuous controller, enclosed in the shaded rectangle, can be replaced by a digital controller, shown
below, that performs the same control task as the continuous controller. The basic difference between
these controllers is that the digital system operates on discrete signals (samples of the sensed signals)
rather than on continuous signals. Such a change may be necessary if we wish to implement our control
algorithm in software on a digital computer, which is frequently the case.

Figure 20: DT controller with CT Plant

The purpose of this lab is to demonstrate how to use MATLAB to work with discrete functions, either in
transfer function or state-space form, to design digital control systems.
In the above schematic of the digital control system, we see that the system contains both discrete and
continuous portions. Typically, the system being controlled is in the physical world and generates and
responds to continuous-time signals, while the control algorithm may be implemented on a digital
computer. When designing a digital control system, we first need to find the discrete equivalent of the
continuous portion of the system. There are multiple method of discretization

 Zero Order Hold (Forward Euler Method)


 Bilinear Transformation (Tustin Method)
 First Order Hold
 Impulse Transformation
There are two way to design DT contorller as shown below, first method is transform CT plant into DT
plant and then design DT controller. Second method is design controller in CT domain and then discretize
controller.

Continuous
Time Plant

CT Controller Discrete Time


Plant

DT Controller

Let us consider first order transfer function


1
𝐺𝑝 (𝑠) =
𝜏𝑠 + 1
With τ = 10
Ideally, we wish to discretize CT system while maintaining CT characteristics but depend on sampling
time results vary from original system. Following are the MATLAB code for observing difference in
‘ZOH’ and ‘Tustin’ method.
Designing DT Controller in DT domain
MATLAB Code
clc; clear all; close all;
sys=tf(1,[10 1]);
sys1=c2d(sys,4,'zoh');% CT to DT conversion with Ts 4 using ZOH Method
sys2=c2d(sys,0.5,'zoh');
sys3=c2d(sys,4,'tustin'); % CT to DT conversion with Ts 4 using Tustin Method
step(sys)
hold on
step(sys1)
hold on
step(sys2)
hold on
step(sys3)
hold on
step(sys3)
legend('CT','ZOH with Ts 4','ZOH with Ts 0.5','Tustin with Ts 4')

Graph

Figure 21: Step Response of CT and DT system with different sampling time

From graphs, ZOH method is suitable for lower sampling time as compared to system closed loop
bandwidth or time constant. While for higher sampling period, bilinear transformation is suitable.
For designing controller in DT, we use following MATLAB ‘c2d’ command

clc; clear all; close all;


sys=tf(1,[10 1]);
sys1=c2d(sys,0.1,'zoh');
% Tf is derivative filter constant value while Ts represent sampling %time. We can change default
method of discretization of integrator %and derivative term by IFormula and DForlmula respectively.
kp=4; ki=2; kd=5; Tf=1; Ts=0.1;
C=pid(kp,ki,kd,Tf,Ts,'IFormula',…
'Trapezoidal','Dformula','Trapezoidal');
Gp = series(C,sys1);
clos=feedback(Gp,1);
step(clos)

Figure 22: DT Controller Step Response

We can also use PID Tuner app for designing PID controller in discrete domain,

Figure 23: PID Tuner App


Import DT plant transfer function and regulate to achieve desired response,

Figure 24: PID Tuner App window

MATLAB Command window

>> C

C=

Ts z-1
Kp + Ki * ------ + Kd * ------
z-1 Ts

with Kp = 147, Ki = 173, Kd = 11.5, Ts = 0.1

Sample time: 0.1 seconds


Discrete-time PID controller in parallel form.

For these PID gain parameters, step response will


be

Figure 25: Step Response with tuned PID Gains


We can also use Simulink for designing DT controller and to observe simulation DT controller with CT
plant,

Figure 26: Simulink Diagram

PID(z) block explain below, its show discrete time controller while plant is in CT domain, we can tune
PID gains values manually or can be tune automatically by select Tune option in PID Simulink block.

1. Select Discrete Time


2. Choose discretization method for integrator and filter. If it’s desire to use PID without
filter then uncheck filtered derivative option
3. Plug PID gains values or tune automatically
4. Compensator formula
TASK
Consider a mass-damper-spring system have a transfer function

1
G p (s) 
s  10s  20
2

 Design a PID controller in CT to achieve following specification


 Fast rise time
 Minimum overshoot
 No steady-state error
 Discretize CT controller using ZOH and Tustin method to maintain characteristics of step
response
 Discretize plant transfer function and design a controller in discrete domain manually and
auto (PID Tuner).
 Compare CT and DT results and comments.

Observations

MATLAB Code:
%% Manual
s= tf('s');
sys= 1/(s^2+10*s+20);
sys1=c2d(sys,0.01,'tustin');
kp=600.0478; ki=1734.7763; kd=49.207; Tf=0.00017681; Ts=0.01;
C=pid(kp,ki,kd,Tf,Ts,'IFormula','Trapezoidal','Dformula','Trapez
oidal');
Gp = series(C,sys1);
clos=feedback(Gp,1);
step(clos)
stepinfo(clos)

%% Auto
s= tf('s');
sys= 1/(s^2+10*s+20);
sys1=c2d(sys,0.001,'tustin');
kp=428.386; ki=745.76135; kd=41.17381; Tf=0.00017681; Ts=0.001;
C=pid(kp,ki,kd,Tf,Ts,'IFormula','Trapezoidal','Dformula','Trapez
oidal');
Gp = series(C,sys1);
clos=feedback(Gp,1);
step(clos)
stepinfo(clos)
MATLAB Plots:
Discretization by ZOH:

Discretization with Tustin Method:


Manual application of PID:

Conclusions
Discretization of the time-based systems helps with the implementation of a discrete controller,
which is able to effectively control the system. This process is useful since most of the controllers
are computer based and run on discrete values.
Lab Session 10
Fuzzy controller (for inverted pendulum)

Fuzzy control logics can be divided into three phases:

I. Mapping inputs: In this phase we calculate how much the input


value belongs to each membership function. In the case of inverted
pendulum, we have two inputs: theta and thetad. For both of these
inputs, there exist 5 membership functions (10 in total).

II. Applying rules: So far, we have calculated the belonging of input to


each MF. Next thing to do is to form rule matrix and apply it to the input
belongings (for each MF). After this phase, we will know how much each
input belong to each output membership functions.

III. Defuzzification: In this phase we will get a real number for the output.

[Input1]
Name='theta'
Range=[-5 5]
NumMFs=5
MF1='NL':'trimf',[-7.5 -5 -2.5]
MF2='NS':'trimf',[-5 -2.5 0]
MF3='Z':'trimf',[-2.5 0 2.5]
MF4='PS':'trimf',[0 2.5 5]
MF5='PL':'trimf',[2.5 5 7.5]

[Input2]
Name='thetad'
Range=[-1.5 1.5]
NumMFs=5
MF1='NL':'trimf',[-2.25 -1.5 -0.75]
MF2='NS':'trimf',[-1.5 -0.75 0]
MF3='Z':'trimf',[-0.75 0 0.75]
MF4='PS':'trimf',[0 0.75 1.5]
MF5='PL':'trimf',[0.75 1.5 2.25]
[Output1]
Name='output1'
Range=[-40 40]
NumMFs=5
MF1='NL':'trimf',[-60 -40 -20]
MF2='NS':'trimf',[-40 -20 0]
MF3='Z':'trimf',[-20 0 20]
MF4='PS':'trimf',[0 20 40]
MF5='PL':'trimf',[20 40 60]

Simulink:
Fx=
( g*sin(u(2)) - m*l*(u(3)^2)*cos(u(2))*sin(u(2))/(mc + m) ) / ( l*(4/3 -
m*cos(u(2))^2/(mc + m)) ) + (cos(u(2))/(mc + m))*(-1)*u(1) / (l*(4/3 -
m*(cos(u(2))^2)/(mc+m)))
Function rules:
[Rules]
1 1, 1 (1) : 1
1 2, 1 (1) : 1
1 3, 1 (1) : 1
1 4, 2 (1) : 1
1 5, 3 (1) : 1
2 1, 1 (1) : 1
2 2, 1 (1) : 1
2 3, 2 (1) : 1
2 4, 3 (1) : 1
2 5, 4 (1) : 1
3 1, 1 (1) : 1
3 2, 2 (1) : 1
3 3, 3 (1) : 1
3 4, 4 (1) : 1
3 5, 5 (1) : 1
4 1, 2 (1) : 1
4 2, 3 (1) : 1
4 3, 4 (1) : 1
4 4, 5 (1) : 1
4 5, 5 (1) : 1
5 1, 3 (1) : 1
5 2, 4 (1) : 1
5 3, 5 (1) : 1
5 4, 5 (1) : 1
5 5, 5 (1) : 1
_
Result:-

Das könnte Ihnen auch gefallen