LAB 5 : INVERTED PENDULUM USING STATE-SPACE METHOD 1.0 OBJECTIVE i. To determine the discrete state-space for inverted pendulum. ii. To check the controllability and observability in inverted pendulum system. iii. To determine control design via pole placement with adding reference input of full-state feedback system. iv. To learn a technique for estimating the states of a plant using observer design. 2.0 MATLAB PROGRAM. Procedur es M-file code 1 M=0.5; m=0.2; b=0.1; i=0.006; g=9.8; l=0.3; p=i*(M+m)+M*m*1^2; %denominator for the A 1
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
LAB 5 : INVERTED PENDULUM USING STATE-SPACE METHOD
1.0 OBJECTIVE
i. To determine the discrete state-space for inverted pendulum.
ii. To check the controllability and observability in inverted pendulum
system.
iii. To determine control design via pole placement with adding reference
input of full-state feedback system.
iv. To learn a technique for estimating the states of a plant using observer
design.
2.0 MATLAB PROGRAM.
Procedures M-file code
1
M=0.5;
m=0.2;
b=0.1;
i=0.006;
g=9.8;
l=0.3;
p=i*(M+m)+M*m*1^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;
1
m*l/p];
C=[1 0 0 0;
0 0 1 0];
D=[0;
0];
Ts=1/100;
pend=ss(A,B,C,D);
pend_d=c2d(pend,Ts,'zoh')
4
F=[1.0000 0.0100 0.0001 0.0000;
0 0.9982 0.0267 0.0001;
0 0.0000 1.0016 0.0100;
0 -0.0045 0.3119 1.0016];
G=[0.0001
0.0182;
0.0002;
0.0454];
H=[1 0 0 0;
0 0 1 0];
J=[0;
0];
Ts=1/100;
pend_d=ss(F,G,H,J,Ts);
2
co=ctrb(pend_d);
ob=obsv(pend_d);
Controllability=rank(co)
Observability=rank(ob)
6
T=0:0.01:5;
U=0.2*ones(size(T));
F=[1.0000 0.0100 0.0001 0.0000;
0 0.9982 0.0267 0.0001;
0 0.0000 1.0016 0.0100;
0 -0.0045 0.3119 1.0016];
G=[0.0001
0.0182;
0.0002;
0.0454];
H=[1 0 0 0;
0 0 1 0];
J=[0;
0];
x=1;
y=1;
3
Q=[x 0 0 0;
0 0 0 0;
0 0 y 0;
0 0 0 0];
R=1;
K=dlqr(F,G,Q,R)
Ts=1/100;
sys_cl=ss(F-G*K,G,H,J,Ts);
[Y,T,X]=lsim(sys_cl,U);
stairs(T,Y)
legend('Cart (x)','Pendulum (phi)')
Procedures M-file code
10
T=0:0.01:5;
U=0.2*ones(size(T));
F=[1.0000 0.0100 0.0001 0.0000;
0 0.9982 0.0267 0.0001;
0 0.0000 1.0016 0.0100;
0 -0.0045 0.3119 1.0016];
G=[0.0001
0.0182;
0.0002;
0.0454];
4
H=[1 0 0 0;
0 0 1 0];
J=[0;
0];
x=5000; %weighting factor for the cart position
y=100; %weighting factor for the pendulum angle
Q=[x 0 0 0;
0 0 0 0;
0 0 y 0;
0 0 0 0];
R = 1;
K = dlqr(F,G,Q,R)
Nbar = -61.55;
Ts = 1/100;
sys_cl = ss(F-G*K,G*Nbar,H,J,Ts);
[Y,T,X]=lsim(sys_cl,U);
stairs(T,Y)
legend('Cart (x)','Pendulum (phi)')
5
Procedures M-file code
12
F=[1.0000 0.0100 0.0001 0.0000;
0 0.9982 0.0267 0.0001;
0 0.0000 1.0016 0.0100;
0 -0.0045 0.3119 1.0016];
G=[0.0001
0.0182;
0.0002;
0.0454];
H=[1 0 0 0;
0 0 1 0];
J=[0;
0];
x=5000; %weighting factor for the cart position
y=100; %weighting factor for the pendulum angle
Q=[x 0 0 0;
0 0 0 0;
0 0 y 0;
0 0 0 0];
6
R=1;
K=dlqr(F,G,Q,R);
poles=eig(F-G*K)
Procedures M-file code
14
F=[1.0000 0.0100 0.0001 0.0000;
0 0.9982 0.0267 0.0001;
0 0.0000 1.0016 0.0100;
0 -0.0045 0.3119 1.0016];
H=[1 0 0 0;
0 0 1 0];
P=[-0.3 -0.31 -0.32 -0.33];
L=place(F',H',P)'
7
16
T=0:0.01:5;
U=0.2*ones(size(T));
F=[1.0000 0.0100 0.0001 0.0000;
0 0.9982 0.0267 0.0001;
0 0.0000 1.0016 0.0100;
0 -0.0045 0.3119 1.0016];
G=[0.0001
0.0182;
0.0002;
0.0454];
H=[1 0 0 0;
0 0 1 0];
J=[0;
0];
x=5000;
y=100;
Q=[x 0 0 0;
0 0 0 0;
0 0 y 0;
0 0 0 0];
R=1;
K=dlqr(F,G,Q,R)
Nbar=-61.55;
8
L=[2.6310 -0.0105;
172.8146 -1.3468;
-0.0129 2.6304;
-2.2954 173.2787];
Fce=[F-G*K G*K;
zeros(size(F)) (F-L*H)];
Gce=[G*Nbar;
zeros(size(G))];
Hce=[H zeros(size(H))];
Jce=[0;0];
Ts=1/100;
sys_cl=ss(Fce,Gce,Hce,Jce,Ts);
[Y,T,X]=lsim(sys_cl,U);
stairs(T,Y)
legend('Cart (x)','Pendulum (phi)')
9
3.0 RESULTS
Procedures Results
1
a =
x1 x2 x3 x4
x1 1 0.009991 0.0001336 4.453e-007
x2 0 0.9982 0.02672 0.0001336
x3 0 -2.272e-005 1.002 0.01001
x4 0 -0.004544 0.3119 1.002
b = u1
x1 -9.085e-005
x2 -0.01816
x3 0.0002275
x4 0.04552
c = x1 x2 x3 x4
y1 1 0 0 0
y2 0 0 1 0
d = u1
y1 0
y2 0
Sampling time: 0.01
Discrete-time model.
10
4 Controllability = 4
Observability = 4
11
Procedures Results
6
x=1, y=1
K = -0.9384 -1.5565 18.1110 3.3499
K = -0.9384 -1.5565 18.1110 3.3499
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-0.25
-0.2
-0.15
-0.1
-0.05
0
0.05
0.1
Cart (x)
Pendulum (phi)
Figure 1: Step response for weighing factor x=1 and y=1.
Procedures Results
12
Tr=0.48s at 0.014873kgTs= 4.8s at -0.00025719kg
Tr=0.27s at 0.00341673kg
Ts= 4.94s at -0.21923kg
10
K = -61.9836 -33.3719 95.4404 18.8911
Figure 2: Step response for weighing factor x=5000 and y=100.
12
poles =
0.9156 + 0.0729i
0.9156 - 0.0729i
0.9535 + 0.0079i
0.9535 - 0.0079i
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-4
-3
-2
-1
0
1
2
3x 10
-3
Cart (x)
Pendulum (phi)
13
Tr=0.17s at 0.002613kg
Ts= 2.01s at -5.4651e-006kg
Tr=0.14s at 0.00093131kg
Ts= 1.52s at -0.0032227kg
Procedures Results
14 L =
2.6310 -0.0105
172.8146 -1.3468
-0.0129 2.6304
-2.2954 173.2787
16
K = -61.9836 -33.3719 95.4404 18.8911
Figure 3: Overall system response including observer.
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5-0.2
-0.15
-0.1
-0.05
0
0.05
0.1
0.15
0.2
Cart (x)
Pendulum (phi)
Tr=1.28s at 0.19758kg
Tr= 0.58s at 0.067686kg
Ts= 4.16s at -6.149e-10kg
14
4.0 OBSERVATION
Procedures Observation
1
The c2d command is used in procedure 1 to convert continuous to
discrete state-space equation with sampling time, Ts=0.01. The
output displayed in a, b, c, and d matrices in form discrete time
model.
2The output shown that the controllability and observability is 4.
3In figure 1 and 2, the curve in green represents the pendulum's
angle, in radians, and the curve in blue represents the cart's position
in meters.
4With including commands Nbar equals -61.55, the step response
will be as shown in figure 3 with same gain, K in procedure 3.
5The poles location for the system without the observer as shown in
result (procedure 5).
6To find L matrix, used place commands in matlab and the output
shown as result in procedure 6.
7Figure 4 shown as same as figure 3. The curve in green represents
15
the pendulum's angle, in radians, and the curve in blue represents
the cart's position in meters with the gain, K also the same value.
5.0 ANALYSIS
In order to convert the continuous state-space equations to discrete state-space is
by using c2dm commands in the Matlab. To use this c2dm commands, we need to specify
six arguments: four state-space matrices (A, B, C, and D), sampling time (Ts in
sec/sample), and the 'method'. The sampling time should be smaller than 1/(30*BW) sec,
where BW is the closed-loop bandwidth frequency. The method we will use is the zero-
order hold ('zoh') same as lab before.
The next step is to check the controllability and the observability of the system.
For the system to be completely state controllable, the controllability matrix must have
the rank of n. The rank of the matrix is the number of independent rows (or columns). In
the same token, for the system to be completely state observable, the observability matrix
must also have the rank of n. Since our controllability matrix and observability matrix are
'4x4', the rank of both matrices must be 4. The function rank can give you the rank of
each matrix. From result in procedure 2, this proves that our discrete system is both
completely state controllable and completely state observable.
In figure 1, the pendulum's and cart's overshoot appear fine, but their settling
times need improvement and the cart's rise time needs to be decreased. Also the cart has,
in fact, moved in the opposite direction. For x=1, y=1 the settling time, Ts is greater than
5 seconds and rise time for cart is over than 1 second. When increase the weighting
factors (x=5000, y=100), with settling time, Ts is about 2 seconds for pendulum(phi) and
less than 2 seconds for cart (x). For cart’s rise time, TR is less than 1 second. The plot in
figure 2, all design requirements are satisfied except the steady-state error of the cart