Professional Documents
Culture Documents
A reportby: _______________________
submitted in the
requirements of ENGR 6131
Project Report on
Simulation of Inverted
pendulum Control
Table of contents
S. Topic Page
NO. No.
INTRODUCTION 2
STATE EQUATIONS AND OUTPUT EQUATIONS OF THE
1. 3
SYSTEM
2. TRANSFER FUNCTION - OPEN LOOP SYSTEM : 4
CONTROLLABLE, OBSERVABLE AND JORDAN CANONICAL
3. 5
FORMS
4. IMPULSE RESPONSE AND STEP RESPONSE 8
BODE PLOT AND ROOT-LOCUS OF THE UNCOMPENSATED
5. 9
SYSTEM
6. CONTROLLER DESIGN- CLASSICAL CONTROL THEORY 10
1
The motive of this project is to analyze the linear model of Inverted
pendulum based on Modern Control Theory and Classical Control Theory and
a comparison is made based on the results obtained for given specifications.
m1 lo x (t) + J
o
(t) (m1 lo + m2 lc) g (t) m1 g x(t)= 0
Where, F(T) is input signal and two output measurements are x and
2
m1 0.213 kg
m2 1.785 Kg
lo 0.330 m
Jo 0.0246 Kg-m2
lc 0.071 m
g 9.81 m/s2
Since both the above equation are of order 2 and both the equation involve
variables x and , So the system described by these equations is a 4 th
order system and hence we need 4 state variables to define the state space
model.
x4 (t) = (t)
By substituting the state variables and solving the input output equations,
following state equations and output equations are obtained .
State Equations:
x 1 = x2
)[ ]
m1 lo g x 1(t ) m l J Jo
( ( )
2
x =
+ 1+ 2 c o 2 g x 3 ( t ) F (t)
2 m1 lo 2J 0 lo m1l m1 l o
o ( m1 l o )
2
x 3 = x4
3
x 4 = x1(t) ( m1 g
2
m1 l o J o ) + x3(t) {[
g
m1 l o
2
m1 l o J o ( 1+
m2 l c J
)
o2 +
m1 l o m1 lo
1
lo ]} +F(t)
[ 1
+
Jo
m1 l o m1 l o ( m 1 l o2J o ) ]
Output Equations:
(t) = x (t)
3
x(t) = x1 (t)
By replacing the values of the constant parameter by the values from given
table
| | || |
0 1 0 0 x1 0
491.03 0 282.35 0 x 2 82.24
x = + [ F(t ) ]
0 0 0 1 x3 0
1,487.95 0 885.35 0 x 4 235
||
x1
y= | |
(t)
x (t) = |0 0 1 0 x2
1 0 0 0 x3 |
x4
A state space model for the system can be created in MATLAB by using the
command
sys_invpend = ss (A,B,C,D);
4
Y (S) 1
TF(S) = =C ( SI A ) B + D
U (S)
The transfer function of the system is in the form of transfer function matrix
because the system has two different outputs for the single input F(t).
These two transfer functions corresponding to two outputs will have the pole
location same but different zero locations.
X ( S) 82.24 S 26,459
= 4
Tf_Pos = H(1)= U (S) S 394.3 S 214,610
Cx = |B AB A
n1
B|
5
| |
0 82 0 25970
82 0 25970 0
Cx = 0 235 0 85688
235 0 85688 0
Rank = 4 = N (Controllable)
||
C
CA
2
Ox = CA
C A n1
| |
0 0 1 0
1 0 0 0
0 0 0 1
0 1 0 0
Ox = 1488 0 885.6 0
491 0 282.4 0
0 1488 0 885.6
0 491 0 282.4
Rank = 4 =N ( Observable)
3.c Controllable Form : In order to find the matrices for controllable canonical
form, first the coefficients of the characteristic polynomial are calculated by using
the command poly(A)
a0 = -14611
a1 = 0
6
a2 = -394
a3 = 0
a4 = 1
| | ||
0 1 0 0 0
0 0 1 0 0
Ac = 0 0 0 1 Bc = 0
14611 0 394 0 1
And Tc = CxCxc-1,
Cxc = |B c Ac B c Ac
n1
Bc|
Cc = C Tc..
Cc = |
6514.9 0 82.2 0
7136.8 0 235 0 | Dc =D =[0;0]
3.d Observable Form : The observable canonical form can be found by transposing
matrices in controllable canonical form
| |
0 0 0 14611
1 0 0 0
Ao = 0 1 0 394
0 0 1 0
Co = |0 0 0 1|
| |
6514.9 7136.8
0 0
Bo = 82.2 235 D0 = D =[0;0]
0 0
7
3.e Jordan Canonical Form :
For calculating the Jordan form we need modal matrix M and the eigen values of the matrix A so
as to create diagonal Jordan Matrix .
The Modal Matrix and the Jordan Matrix is calculated in MATLAB by using the command
[M,J]=eig(A)
| |
.0142 .0142 0.0887 i .0887 i
0.2932 0 .2932 0.5181 0.5181
M = 0.0461 0.0461 0.1436 i 00.1436 i
0.9548 0.9548 0.8385 0.8385
| |
20.7 0 0 0
0 20.7 0 0
Aj = 0 0 5.84 i 0
0 0 o 5.84 i
| |
106.09
106.09
Bj = 19.33
19.33
Cj = |
0.0142 0.0142 0.0887 i 0.0887 i
0.0461 0.0461 0.1436 i 0.1436 i |
8
4. IMPULSE RESPONSE AND STEP RESPONSE
Assuming zero initial conditions the impulse response of the two output transfer
functions is calculated by using the MATLAB command impulse (sys_invpend) and
the result is shown in figure below. The output graph 1 is for Position x and the
9
27
x 10 Impulse Response
2
1.5
To: Out(1)
0.5
Amplitude
0 27
x 10
0
-1
To: Out(2)
-2
-3
-4
-5
0 0.5 1 1.5 2 2.5 3
Time (seconds)
(b) Step Response: For step response , the MATLAB command used is step (sys_invpend)
Output plot 1 is for Position x and the output plot 2 is for the angle .
10
25
x 10 Step Response
8
6
To: Out(1)
2
Amplitude
0 26
x 10
0
-0.5
To: Out(2)
-1
-1.5
-2
-2.5
0 0.5 1 1.5 2 2.5 3
Time (seconds)
11
5. BODE PLOT AND ROOT-LOCUS OF THE UNCOMPENSATED
SYSTEM
Standard MATLAB commands (discussed in Appendix) are used to find bode and root
locus plots for two output transfer functions
Root Locus
15
10
Imaginary Axis (seconds-1)
-5
-10
-15
-25 -20 -15 -10 -5 0 5 10 15 20 25
Real Axis (seconds -1)
12
(c) Bode Plot for angle transfer function
Bode Diagram
150
100
Magnitude (dB)
50
-50
180
135
Phase (deg)
90
45
-45
-1 0 1 2
10 10 10 10
Frequency (rad/s)
Root Locus
8
4
Im aginary Ax is (s ec onds
-1
)
-2
-4
-6
-8
-50 -40 -30 -20 -10 0 10 20 30 40 50
Real Axis (seconds -1)
13
6. CONTROLLER DESIGN (USING CLASSICAL CONTROL
THEORY):
For designing a pid controller following table was considered while varying the
values of gains to get the desired output.
The PID gains are achieved by an iterative process of changing individual parameter to tune
in the requirements for each output transfer function. There is stable . After an intensive search
14
looking for the best parameters to be applied to control the system, the following results were
found:
( S)
For U (S) , PID parameters are Kp = -900; Kd = -0.5; Ki = -50; The controller transfer
Step Response
1.8
1.6
1.4
1.2
1
Amplitude
0.8
0.6
0.4
0.2
0
0 0.02 0.04 0.06 0.08 0.1 0.12
Time (seconds)
X (S)
Controller for U (S) with PID parameters: Kp = 3000;Kd = 1.2; Ki = 10. The controller
15
Step Response
1.8
1.6
1.4
1.2
1
Amplitude
0.8
0.6
0.4
0.2
0
0 0.02 0.04 0.06 0.08 0.1 0.12
Time (seconds)
No comments can be made about the damping ratio since the system behaviour does not
correspond to a 2nd order system
( S)
Response for U (S) =the closed system transfer function is:
----------------------------------------------------------------
16
s^5 + 117.6 s^4 + 2.114e05 s^3 + 8275 s^2 - 6.296e06 s - 3.49e05
Step Response:
Step Response
1.8
1.6
1.4
1.2
1
Amplitude
0.8
0.6
0.4
0.2
0
0 0.02 0.04 0.06 0.08 0.1 0.12
Time (seconds)
17
18
x 10
4.5
Square wave response for angle control
4
3.5
2.5
1.5
0.5
0
0 1 2 3 4 5 6 7 8 9 10
20
x 10
4.5
Sine Wave response for angle control
4
3.5
2.5
1.5
0.5
0
0 1 2 3 4 5 6 7 8 9 10
18
Response for TF2
Step Response:
Step Response
1.8
1.6
1.4
1.2
1
Amplitude
0.8
0.6
0.4
0.2
0
0 0.02 0.04 0.06 0.08 0.1 0.12
Time (seconds)
19
31
x 10
5
Square wave response for position control
4.5
3.5
2.5
1.5
0.5
0
0 1 2 3 4 5 6 7 8 9 10
Sinusoidal response :
20
34
x 10
12
Sine wave response for position control
10
0
0 1 2 3 4 5 6 7 8 9 10
The response of the system with the designed controller is controllable for step input but is
uncontrollable for square and sinusoidal inputs.
21
1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
0 1 2 3 4 5 6 7 8 9 10
0.8
0.6
0.4
0.2
-0.2
-0.4
-0.6
-0.8
-1
0 1 2 3 4 5 6 7 8 9 10
22
(S )
Robustness of transfer function :
Root Locus
6000
4000
Im aginary Ax is (s ec onds
)
2000
-1
-2000
-4000
-6000
-20000 -15000 -10000 -5000 0 5000
Real Axis (seconds -1)
23
X ( S)
Robustness of transfer function U (S) ;
Root Locus
3000
2000
Imaginary Axis (seconds)
1000
-1
-1000
-2000
-3000
-9000 -8000 -7000 -6000 -5000 -4000 -3000 -2000 -1000 0 1000
-1
Real Axis (seconds )
12
x 10 Step Response
4
1
Amplitude
-1
-2
-3
-4
0 0.5 1 1.5 2 2.5 3 3.5
Time (seconds)
24
From Root Locus it is evident that the stability region is very small for these two transfer
functions ,So if the gain is varied slightly the system will go to the instable state. Also, the step
disturbance input results in unstable system . Therefore, it can be said that the system under
control is not very robust with respect to changes in its parameters or disturbance input.
The design of this state feedback controller is done with the similar transient specifications:
In order to comply with the specifications, the system will be approximated to a second
order system with the following characteristic polynomial:
= 0.707;
S 2 +20 S +200
The other poles will be placed 3-4 times farther from these conjugated poles, to force the
behavior to be as approximated as possible to a second order system. Given the fact that our
system is a fourth order system, it will have 4 poles and because of that the pole placement for
the system will be forced to be the following:
Given this State feedback matrix, the A matrix of the system will be changed in the
following manner: Af= A BK;
25
| |
0 1 0 0
6663 833 3339 323
Af = 0 0 0 1
18954 2379 9463 923
Step Response
0.1
0
To: Out(1)
-0.1
-0.2
Amplitude
-0.3
0.4
Step response for Full State feedback control
0.2
To: Out(2)
-0.2
-0.4
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
Time (seconds)
26
Square response for Full State feedback control
0.5
Position
0.4 Theta
0.3
0.2
0.1
-0.1
-0.2
-0.3
0 1 2 3 4 5 6 7 8 9 10
0.1
-0.1
-0.2
-0.3
-0.4
0 1 2 3 4 5 6 7 8 9 10
27
12 FULL-ORDER OBSERVER
The controller was calculated to provide a systems time constant () equal to 0.1 sec. In order to
provide an acceptable estimator for the system the required time constant of the observer to be
from 2 to 5 times faster; therefore choosing 5 times faster, the following parameters are used for
the observer:
= 0.02
= 0.707
wn= 70.72
Considering the parameters, the desired 2nd order characteristic polynomial for the system
2
will be: S +100 S+ 5000
Because the present system is a 4 th order system two other poles have to be assumed.
These poles will be placed over the real axes, 3-4 times farther than the conjugated pair from the
origin. The desired observers pole location: -50 50i, -150,-200. The command place is
used to provide the estimator gain matrix G.
Here, the det( SI A + GC) is equated to the polynomial formed from the desired poles location
to find the coefficients of G.
| |
247.5 38.6
9126.5 7843.7
G= 54.8 202.5
7323.1 9037.3
Then the full order observer state space equations are found out using the matrices:
Ae =A-G*C-B*K;
sys_obs_pend = ss(Ae,Be,Ce,De);
28
Step Response
From: In(1) From: In(2)
60
40
20
Am plitude
-20
-40
-60
0 1 2 3 4 5 0 1 2 3 4 5
Time (seconds)
We need not to observe all the 4 states as we any measure two outputs as angle
and position and these are our known states x1 and x3 for reduced order observer.
29
Crce = -Ke;
Drce = -K1 - (Ke*Ge);
sys_red_obs = ss(Arce,Brce,Crce,Drce);
30
Step Response
From: In(1) From: In(2)
350
300
250
200
150
Amplitude
100
50
-50
-100
-150
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
Time (seconds)
step(tf_full,5);grid
Transfer functions:
31
X (S) 7154 S2 +561800
= 4
U (S) S 90 S3 +2800 S 2 +38000 s+ 240000
The resulting Transfer function of the controller-observer adds 4 poles and 3 zeros to the plants
transfer function. If we try to obtain an equivalent controller from the classical point of view, it is
possible to say that this controller is 3 differentiators and 4 integrators.
It can be seen that the step response given by the system under control complies in a very
nice manner the original specifications proposed. The settling time is less than 1 second and the
damping ratio is around the 0.707 value.
Step Response
4
2
To: Out(1)
-1
Amplitude
-2
6
2
To: Out(2)
-2
-4
-6
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
Time (seconds)
32
It can be seen that the step response given by the system under control is responding as
per our design specifications. The settling time is less than 0.4 second and the damping ratio is
around the 0.707 value.
In the project by applying these two different approaches, two different controllers
are designed. The inverter pendulum system is controlled by designing a controller
by adopting classical control techniques and Modern Control techniques.
The modern control theory provides an easy-fast and efficient way of solving a
control problem on the other hand.
We can make a unstable system stable by placing the poles at the desired locations
in modern approach. As we have seen from the results above , it is possible to
place the poles almost perfectly at the desired pole locations without the time
consuming iterations. This is done easily by understanding the mathematical model
of the system.
There are few disadvantage of the modern control theory, to name a few: one is that
it needs a good understanding of the mathematical model of the system to solve
the problem of control system in an efficient way.
Also we get valuable information on the control problems from the notions of
Controllability and Observability that provides the knowledge about the system
behaviour prior to designing a controller or observer. But there is no such notions
available in Classical control Theory.
33
APPENDIX: A- MATLAB COMMANDS
H = tf(sys_invpend);
Tf_Theta =H(2);
Tf_Pos =H(1);
%%%%%%%%%%%Var_Canonical forms%%%%%%%%%%%
%%%%%%%%%%%Var_Contrability test%%%%%%%%%%%
Var_Cx = ctrb(sys_invpend);
rank(Var_Cx);
%%%%%%%%%%%Observability test%%%%%%%%%%%
Ox = obsv(sys_invpend);
rank(Ox);
34
impulse(sys_invpend);grid
figure
step(sys_invpend);grid
%%%%%%%%%%%Signal Generation%%%%%%%%%%%
[Var_Asq,tsq] = gensig('square',2,10,0.01);
[Var_Asn,tsn] = gensig('sin',2,10,0.01);
%%%%%%%%%%%Angular control%%%%%%%%%%%
Controller_Kp = -900;
Controller_Kd = -0.5;
Controller_Ki = -50;
Var_Contrl1=tf([Controller_Kd Controller_Kp Controller_Ki],[1 0]);
Var_CL_1 = Var_Contrl1* Tf_Theta;
pid_theta= feedback(Var_CL_1,1);
%%%%%%%%%%%Step response%%%%%%%%%%%
figure
step(pid_theta);grid
%%%%%%%%%%%Position control%%%%%%%%%%%
Controller_Kd = 1.2;
Controller_Kp =3000;
Controller_Ki = 10;
Var_Contrl2=tf([Controller_Kd Controller_Kp Controller_Ki],[1 0]);
Var_CL_2= Tf_Pos * Var_Contrl2;
pid_pos= feedback(Var_CL_2,1);
%%%%%%%%%%%Step response%%%%%%%%%%%
figure
35
step(pid_pos);grid
Var_CL_distr1 = 1 + Var_CL_1;
Var_Dist1 = Tf_Theta / Var_CL_distr1;
figure
step(Var_Dist1)
Var_CL_distr2 = 1 + Var_CL_2;
Var_Dist2 = Tf_Pos / Var_CL_distr2;
figure
step(Var_Dist2)
%%%%%%%%%%%%%%%%%%State feedback control %%%%%%%%%%%%%%%%%%
Poles = [-10+10i -10-10i -30 -40];
K = place(Var_A,Var_B,Poles);
Var_Af = Var_A-Var_B*K;
sys_fdbk = ss(Var_Af,Var_B,Var_C,Var_D);
Tf_fdbk =tf(sys_fdbk);
[y,t,x]=lsim(sys_fdbk,Var_Asq,tsq);
figure
plot(t,y);grid
title('Square response for State feedback control')
legend('Pos','Theta');
[y,t,x]=lsim(sys_fdbk,Var_Asn,tsn);
figure
36
plot(t,y);grid
title('Sine response for State feedback control')
legend('Pos','Theta');
figure
step(sys_obs_pend,5);grid
figure
step(sys_full_obs,5);grid
[y,t,x]=lsim(sys_full_obs,Var_Asn,tsn);
figure
plot(t,y);grid
title('Sine response for Var_Closed loop Full order Observer -
Var_Controller')
legend('Pos','Theta');
figure
step(red_obs_pend,5);grid
37
38