Top Banner
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
28
Welcome message from author
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
Page 1: Inverted Pendulum Using State Space Method

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

Page 2: Inverted Pendulum Using State Space Method

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

Page 3: Inverted Pendulum Using State Space Method

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

Page 4: Inverted Pendulum Using State Space Method

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

Page 5: Inverted Pendulum Using State Space Method

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

Page 6: Inverted Pendulum Using State Space Method

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

Page 7: Inverted Pendulum Using State Space Method

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

Page 8: Inverted Pendulum Using State Space Method

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

Page 9: Inverted Pendulum Using State Space Method

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

Page 10: Inverted Pendulum Using State Space Method

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

Page 11: Inverted Pendulum Using State Space Method

4 Controllability = 4

Observability = 4

11

Page 12: Inverted Pendulum Using State Space Method

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

Page 13: Inverted Pendulum Using State Space Method

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

Page 14: Inverted Pendulum Using State Space Method

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

Page 15: Inverted Pendulum Using State Space Method

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

Page 16: Inverted Pendulum Using State Space Method

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

position (x).

16

Page 17: Inverted Pendulum Using State Space Method

To obtain the desired output, the reference input is scaled so that the output equals

to the reference. This can be easily done by introducing a feedforwarding scaling factor

called Nbar. This function will find the scale factor for a full-state feedback system to

eliminate the steady-state error. Unfortunately, in this lab, the user-defined function

rscale cannot use to find Nbar. But certainly it can find from trial and errors. After

several trials, the Nbar equals to -61.55 provided the satisfactory response. From the plot

in figure 3, notice that the steady-state error of the cart's position have been eliminated

and the designed of system satisfied all design requirements.

The above response satisfies all design requirements; however, it was found

assuming all states are measurable. This assumption may not be valid for all systems. The

technique is developed for estimating the states of a plant from the information that is

available concerning the plant. The system that estimates the states of another system is

called an observer. Thus, in this section a full-order state observer is designed to estimate

those states that are not measurable. To design the observer, first, find the L matrix. To

find the L matrix, the poles needed to find the system without the observer (the poles of

F-G*K). The observer poles are placed to make the observer works a lot faster than the

system without the observer. The Matlab function place is used to find the L matrix.

From figure 4, as noticed, this response is about the same as before, and all of the design

requirements have been satisfied.

Table 1: Summarized of the settling time and rise time for all tasks.

time

Without observer polesWith observer

poles

Weighing factor

X=1 y=1 X=5000 y=100 X=5000 y=100

Cart Pend Cart Pend Cart pend

Rise Time, Tr 0.27s 0.48s 0.14s 0.17s

1.28s

0.58s

Settling time,

Ts4.94s 4.8s 1.52s 2.01s 4.16s

6.0 COMMENT

17

Page 18: Inverted Pendulum Using State Space Method

In this lab, first step is same as before that to convert the continuous to discrete

state-space equation. For inverted pendulum, we used matlab function called c2d to

convert that equation. Then we need to check either the system is completely state

controllable or completely state observable. From result in procedure 2, this proves that

our discrete system is both completely state controllable and completely state observable.

From figure 1, we can see 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 when we

use x=1 and y=1. Since we increase x=5000 and y=100, the step response shown as

figure 2 but the steady-state error of the cart position (x) are not satisfied. We use Nbar

equals to -61.55 provided the satisfactory response. From the plot in figure 3, notice that

the steady-state error of the cart's position have been eliminated and the designed of

system satisfied all design requirements. And lastly to confirm that the system is satisfied

all design requirement, the technique is developed for estimating the states of a plant

from the information that is available concerning the plant is called an observer. With

using place function to find L matrix, from figure 4, this response is about the same as

before, and all of the design requirements have been satisfied.

7.0 CONCLUSION

18

Page 19: Inverted Pendulum Using State Space Method

After this lab, conclusion that can make is the discrete state-space equation for

inverted pendulum is

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

with sampling time is 0.01.

The discrete system for inverted pendulum is both completely state controllable

and completely state observable. From figure 1(x=1 and y=1), the step response shows

that the design is not satisfied all design requirements. When increase x=5000 and y=100

the plot in figure 2 are shown but only steady-state error for cart’s position (x) are not

satisfied. By using Nbar commands, the steady-state error of the cart's position have been

19

Page 20: Inverted Pendulum Using State Space Method

eliminated and the designed of system satisfied all design requirements as shown in

figure 3. The place command is used to find L matrix in order to design observer. From

figure 4, this response is about the same as before, and all of the design requirements

have been satisfied.

8.0 REFERANCES

20

Page 21: Inverted Pendulum Using State Space Method

1. Lab sheet 2, BER 4113 Digital Control, Digital Dc Motor Speed Control

With Pid Control Amran Mohd Zaid , July 2007

2. Electronic and circuit analysis using MATLAB (Second Edition) , John

Okyeke Attia.

3. MATLAB Programming David C. Kuncicky, Prentice Hall, 2005.

21