eecs 562 & aerosp 551 inverted pendulum on a cart …yeeyoung/publication/nl.pdf · inverted...

15
EECS 562 & AEROSP 551 Inverted Pendulum on a Cart Project Prof. J.W. Grizzle, Univ. of Michigan Due date: Tuesday, February 16, 2016, beginning of lecture. Late penalty: 15% for 5 minutes to one day; 10% per day thereafter. LAST NAME (PRINTED) , FIRST NAME HONOR PLEDGE: Copy and SIGN: I understand that this is an individual assignment and not a group exercise. I have neither given nor received aid on this project nor have I concealed any violation of the Honor Code. I have neither borrowed nor shared computer code for simulating my models and creating my plots. SIGNATURE This is a version of solution written by Yi Yang, all rights reserved. 1

Upload: hakhanh

Post on 02-Apr-2018

221 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: EECS 562 & AEROSP 551 Inverted Pendulum on a Cart …yeeyoung/publication/nl.pdf · Inverted Pendulum on a Cart Project Prof. J.W. Grizzle, Univ. of Michigan ... Solution:Itisconventionaltowritedownthecombinedequtionforthesystemplusobserver

EECS 562 & AEROSP 551Inverted Pendulum on a Cart ProjectProf. J.W. Grizzle, Univ. of Michigan

Due date: Tuesday, February 16, 2016, beginning of lecture.Late penalty: 15% for 5 minutes to one day; 10% per day thereafter.

LAST NAME (PRINTED),

FIRST NAME

HONOR PLEDGE: Copy and SIGN: I understand that this is an individual assignment and not a group

exercise. I have neither given nor received aid on this project nor have I concealed any violation of the Honor

Code. I have neither borrowed nor shared computer code for simulating my models and creating my plots.

SIGNATURE

This is a version of solution written by Yi Yang, all rights reserved.

1

Page 2: EECS 562 & AEROSP 551 Inverted Pendulum on a Cart …yeeyoung/publication/nl.pdf · Inverted Pendulum on a Cart Project Prof. J.W. Grizzle, Univ. of Michigan ... Solution:Itisconventionaltowritedownthecombinedequtionforthesystemplusobserver

Contents

Problem 1: Verify the Dimensionless Model 4

Problem 2: Linear State-Variable Model 5

Problem 3: Stabilizing Feedback 6

Problem 4: Stability with Full State Feedback 7

Problem 5: Simulation with Full State Feedback 8

Problem 6: Luenberger Observer Design 11

Problem 7: Simulation Results for Observer Based Compensator 11

Problem 8: Observer Based Compensator using Nonlinear 15

2

Page 3: EECS 562 & AEROSP 551 Inverted Pendulum on a Cart …yeeyoung/publication/nl.pdf · Inverted Pendulum on a Cart Project Prof. J.W. Grizzle, Univ. of Michigan ... Solution:Itisconventionaltowritedownthecombinedequtionforthesystemplusobserver

Provide answers to the following questions:

A Using linear state variable feedback and with the nonlinear model initialized at x2(0) =0, x3(0) = 0, x4(0) = 0, the largest I could make x1(0) before the closed-loop systemwent unstable was (radians). The linear state variable feedback that I used was

(give the feedback gains). It is not reasonable to try for six digitsin your answers!

B Using linear state variable feedback plus an observer, with the observer initialized at theorigin and the nonlinear model initialized at x2(0) = 0, x3(0) = 0, x4(0) = 0, the largestI could make x1(0) before the closed-loop system went unstable was (radians).The observer that I used to obtain the best response was linear/nonlinear (specifywhich one) and the observer gain was (give the gain matrix). Putall documentation in Problem 7 or 8, as appropriate.

3

Page 4: EECS 562 & AEROSP 551 Inverted Pendulum on a Cart …yeeyoung/publication/nl.pdf · Inverted Pendulum on a Cart Project Prof. J.W. Grizzle, Univ. of Michigan ... Solution:Itisconventionaltowritedownthecombinedequtionforthesystemplusobserver

Problem 1: Verify the Dimensionless Model (10 points): Verify that the equationfor φ in (??) indeed follows from (??) after substitution of the given dimensionless quantitiesand proper application of the chain rule. Doing the same for s is similar and is not requiredhere. I promise you, the equations are correct. The hard part is proper application of thechain rule! It’s a good exercise for engineers.

Hint: First note that t = tTimplies that t = T t. Hence, by the chain rule

dφ(t)

dt=dφ(t)

dt

∣∣∣∣t=T t

dt

dt,

where of course, dtdt

= T. You have to figure out the second derivative on your own. No helpon this part in office hours!Proof:

d2φ

dt2=

d

dt

(dφ

dt

)=

d

dt

(dφ

dt

dt

dt

)dt

dt= T 2 d

dt2

∣∣∣∣t=T t

=

(J

mL2+

M

m+M

)L

(M +m)mgLsin(φ)− (mL 1Tφ)2sin(φ)cos(φ)− (mLcos(φ))(M +m)gµ

(M +m)(J +mL2)− (mL)2cos2(φ)

=1

mgL(m+M)·

(M +m)mgLsin(φ)− (mL 1Tφ)2sin(φ)cos(φ)− (mLcos(φ))(M +m)gµ

1 + csin2(φ)

=−cφ2sin(φ)cos(φ)

1 + csin2(φ)+

sin(φ)

1 + csin2(φ)− cos(φ)µ

1 + csin2(φ)ok

4

Page 5: EECS 562 & AEROSP 551 Inverted Pendulum on a Cart …yeeyoung/publication/nl.pdf · Inverted Pendulum on a Cart Project Prof. J.W. Grizzle, Univ. of Michigan ... Solution:Itisconventionaltowritedownthecombinedequtionforthesystemplusobserver

Problem 2: Linear State-Variable Model (10 points): Construct a state-variablerepresentation of pendulum control equations and linearize the equations about the uprightequilibrium point. Define the states in the following manner: x1 = φ, x2 = φ, x3 = s, x4 = ˙s.For the remainder of this project, the following data is assumed:

M = 25 (kg) m = 20 (kg) L = 9.81 (m)

g = 9.81 (m/s2) J = 13mL2

(1)

Linearizing about the origin should yield the linearized system: x = Ax+Bµ

where A =

0 1 0 01 0 0 00 0 0 1−1 0 0 0

and B =

0−10b

(2)

Solution:The parameters for the linearized equations are: b = 3, c = 12, d = 3

2A state representation for the nonlinear system is:

x1 = x2

x2 =−cx2

2sin(x1)cos(x1)

1 + csin2(x1)+

sin(x1)

1 + csin2(x1)− cos(x1)µ

1 + csin2(x1)(3)

x3 = x4

x4 =d · x2

2sin(x1)

1 + csin2(x1)− cos(x1)sin(x1)

1 + csin2(x1)+

1 + csin2(x1)

Linearization about the upright equilibrium point will get:

A =

0 1 0 01 0 0 00 0 0 1−1 0 0 0

B =

0−103

(4)

5

Page 6: EECS 562 & AEROSP 551 Inverted Pendulum on a Cart …yeeyoung/publication/nl.pdf · Inverted Pendulum on a Cart Project Prof. J.W. Grizzle, Univ. of Michigan ... Solution:Itisconventionaltowritedownthecombinedequtionforthesystemplusobserver

Problem 3: Stabilizing Feedback (5 points): Verify that the linearized system iscompletely controllable and then determine a state variable feedback control law µ = Kx+vthat will place the closed-loop eigenvalues at (−3,−2,−0.7± j0.2). You may use the placecommand in MATLAB.Solution:

a) Verify the system is completely controllable. The controllability matrix is:

C =[B AB A2B A3B

]=

0 −1 0 −1−1 0 −1 00 0 3 13 3 1 0

∵ ρ(C) = 4 =⇒ the system is completely controllable.

b) State feedback design. The Matlab codes is as follows:

1 % EECS 562 Project_Inverted Pendulum on a cart2 % Date: 2/13/20163 % By- Yi Yang4 %--------------------------------------------------------------------------5 % Problem 3, place the closed loop eigenvalues at (-3,-2,-0.7\pm j*0.2)6 A = [0 1 0 0;7 1 0 0 0;8 0 0 0 1;9 -1 0 0 0];

10 B = [0; -1; 0; 3];11 Poles = [-3, -2, -0.7+0.2*j, -0.7-0.2*j];12 K = place(A,B,Poles);13 A - B*K;

The gain matrix for the controller is K =[19.3000 22.9750 1.5900 5.5250

]

6

Page 7: EECS 562 & AEROSP 551 Inverted Pendulum on a Cart …yeeyoung/publication/nl.pdf · Inverted Pendulum on a Cart Project Prof. J.W. Grizzle, Univ. of Michigan ... Solution:Itisconventionaltowritedownthecombinedequtionforthesystemplusobserver

Problem 4: Stability with Full State Feedback (5 points): Apply the control lawµ = Kx+ v to both the linearized system and nonlinear system using v ≡ 0. This gives youtwo closed-loop systems:

x = (A+BK)x (5)

andx = f(x,Kx) (6)

Verify that A + BK = ∂∂x

[f(x,Kx)], that is (5) is the linearization of (6) about the origin.What can you conclude about the stability properties of the origin for the nonlinear closed-loop system? See Theorem 4.7 on page 139 of Khalil. This theorem is really a justification forthe existence of linear control theory!!! See also Definition 4.1 on page 112 of our textbook.

Hint: linearize the closed-loop system (6) about the origin and compare to (5). (Secondhint: doing this on the model with the dynamics written out explicitly is way too painful.Use the chain rule on (6).)Solution:

A+BK =

0 1 0 0

−18.3 −22.975 −1.59 −5.5250 0 0 1

56.9 68.925 4.77 16.575

The nonlinear equations with linearized full state feedback control is:

x1 = x2

x2 =−cx2

2sin(x1)cos(x1)

1 + csin2(x1)+

sin(x1)

1 + csin2(x1)− cos(x1)

1 + csin2(x1)· (19.3x1 + 22.975x2 + 1.59x3 + 5.525x4)

x3 = x4

x4 =d · x2

2sin(x1)

1 + csin2(x1)− cos(x1)sin(x1)

1 + csin2(x1)+

b

1 + csin2(x1)· (19.3x1 + 22.975x2 + 1.59x3 + 5.525x4)

∴∂

∂x[f(x,Kx)] =

0 1 0 0

1− 19.3 0 0 00 0 0 1

−1 + 3× 19.3 3× 22.975 3× 1.59 3× 5.525

= A+BK

From Theorem 4.7 on page 139 of Kahalil, it concludes that the origin of the nonlinear closedloop system is asymptotically stable. ok

7

Page 8: EECS 562 & AEROSP 551 Inverted Pendulum on a Cart …yeeyoung/publication/nl.pdf · Inverted Pendulum on a Cart Project Prof. J.W. Grizzle, Univ. of Michigan ... Solution:Itisconventionaltowritedownthecombinedequtionforthesystemplusobserver

Problem 5: Simulation with Full State Feedback (10 points): Simulate both closed-loop systems for several initial conditions, comparing the results of the linearized model tothe nonlinear model. With x2(0) = 0, x3(0) = 0, and x4(0) = 0, explore how large you canmake x1(0) before the nonlinear model goes unstable.Solution:The Matlab codes for this part is attached below:

1 %--------------------------------------------------------------------------2 % Problem 5, simulation with full state feedback3 % Linearized model simulation4 C = eye(4); D = 0;5 sys_linear = ss(A-B*K,B,C,D);6 x0 = [0.1; 0; 0; 0]; t = linspace(0,10,201); u = zeros(size(t));7 [Y_l,T_l] = lsim(sys_linear,u,t,x0);8 figure(1);clf;9 for i = 1:4

10 plot(T_l,Y_l(:,i));11 hold on12 end13 hold off14 h = legend('$\phi$','$\dot{\phi}$','$\bar{s}$','$\dot{\bar{s}}$');15 set(h,'interpreter','Latex','FontSize',9)16 xlabel('t'); ylabel('y');17 title('Simulation for Linearized Model,x_0(1)=0.1')18 % Nonlinear model simulation19 f = @(t,x) [x(2);(-0.5*x(2)^2*sin(x(1))*cos(x(1))+sin(x(1))-cos(x(1))*(19.3*x(1)+...20 22.975*x(2)+1.59*x(3)+5.525*x(4)))/(1+0.5*(sin(x(1)))^2);x(4);...21 (1.5*x(2)^2*sin(x(1))-cos(x(1))*sin(x(1))+3*(19.3*x(1)+22.975*x(2)...22 +1.59*x(3)+5.525*x(4)))/(1+0.5*(sin(x(1)))^2)];23 tspan = [0 10];24 [T_n,Y_n] = ode45(f,tspan,x0,1e-6);25 figure(2);clf;26 for i = 1:427 plot(T_n,Y_n(:,i));28 hold on29 end30 hold off31 h = legend('$\phi$','$\dot{\phi}$','$\bar{s}$','$\dot{\bar{s}}$');32 set(h,'interpreter','Latex','FontSize',9)33 xlabel('t'); ylabel('y');34 title('Simulation for Nonlinear Model,x_0(1)=0.1')

8

Page 9: EECS 562 & AEROSP 551 Inverted Pendulum on a Cart …yeeyoung/publication/nl.pdf · Inverted Pendulum on a Cart Project Prof. J.W. Grizzle, Univ. of Michigan ... Solution:Itisconventionaltowritedownthecombinedequtionforthesystemplusobserver

Figure 1: Simulation for x0(1) = 0.1

Figure 2: Simulation for x0(1) = 0.5

Figure 3: Simulation for x0(1) = 0.6589

9

Page 10: EECS 562 & AEROSP 551 Inverted Pendulum on a Cart …yeeyoung/publication/nl.pdf · Inverted Pendulum on a Cart Project Prof. J.W. Grizzle, Univ. of Michigan ... Solution:Itisconventionaltowritedownthecombinedequtionforthesystemplusobserver

Figure 4: Simulation for x0(1) = 0.65898

The simulation results for linear and nonlinear full state feedback simulation are listed above.Figure 1 shows results with initial condition x0 =

[0.1 0 0 0

]T , Figure 2, 3, 4 shows resultswith different initial conditions, from there plots we can see the unstability for nonlinearsystem. Hence, x1(0) ≈ 0.65898 is the value the initial condition can attain before thenonlinear full state feedback system becomes unstable.

10

Page 11: EECS 562 & AEROSP 551 Inverted Pendulum on a Cart …yeeyoung/publication/nl.pdf · Inverted Pendulum on a Cart Project Prof. J.W. Grizzle, Univ. of Michigan ... Solution:Itisconventionaltowritedownthecombinedequtionforthesystemplusobserver

Problem 6: Luenberger Observer Design (10 points): Suppose now that you can onlymeasure the outputs y1 = φ and y2 = s. Verify that the system is completely observable andthen design an observer to implement the control law synthesized in Problem 3. Note thatthis is a more difficult pole placement problem than the one you did in Problem 3 becausethere are two outputs instead of just one; hence there are many ways of achieving the samepole positions. If you have had EECS 565, you may use methods from that course to designthe observer gain; otherwise, use once again the place command.Solution:The Matlab codes for problem 6 are attached below:

1 %--------------------------------------------------------------------------2 % Problem 6, Luenberger observer design3 C = [1 0 0 0; 0 0 1 0];4 L = place(A',C',Poles)'%eigenvalues assignments using duality

The observability matrix for this system is:

Θ =

CCACA2

CA3

=

1 0 0 00 0 1 00 1 0 00 0 0 11 0 0 0−1 0 0 00 1 0 00 −1 0 0

ρ(Θ) = 4 =⇒ The system is completely observable.Observer design:

x(t) = Ax(t) +Bu(t)

˙x(t) = Ax(t) +Bu(t) + L (y(t)− Cx(t))

= Ax(t) +Bu(t) + L (Cx(t)− Cx(t))

e = x(t)− ˙x(t) = (A− LC) (x(t)− x(t)) = (A− LC)e

From the duality theorem we know: If linear system (A,B,C,D) is completely observable,then system(A′, C ′, B′, D′) is completely controllable.

L = place(A′, C ′, P )′ =⇒ L =

3.0814 −0.16741.6355 −1.13130.7898 3.31860.3861 2.5363

11

Page 12: EECS 562 & AEROSP 551 Inverted Pendulum on a Cart …yeeyoung/publication/nl.pdf · Inverted Pendulum on a Cart Project Prof. J.W. Grizzle, Univ. of Michigan ... Solution:Itisconventionaltowritedownthecombinedequtionforthesystemplusobserver

Problem 7: Simulation Results for Observer Based Compensator (15 Points):Simulate the new dynamic controller (state feedback plus observer) on both the linearizedand nonlinear system models for a variety of initial conditions. Plot the outputs y1(t) andy2(t). How do the responses between the static and dynamic controllers compare? Beingable to measure states is really useful, isn’t it!! Always take the initial conditions of theobserver to be [0, 0, 0, 0]. Explore how large you can make x1(0) (the initial angle of thependulum) before the nonlinear model goes unstable. For most of you, it will be smallerthan in Problem 5, though some may find the opposite. Do not worry about this.Solution:It is conventional to write down the combined eqution for the system plus observerusing the original state x plus error state e = x− x, the feedback is u = −Kx.

x = Ax+B(r −Kx) = Ax+Br −BK(x− e) = (A−BK)x+BKe+Br

e = (A− LC)e

y = Ct

[xe

]For nonlinear system, we have:{

x = f(x, u)

y = g(x, u)

{˙x = f(x, u)

y = g(x, u)

˙x = f(x, u) + L(y − y) = f(x, u) + L(y − g(x, u))

e = x− ˙x = f(x, u)− f(x, u)− Lg(x, u) + Lg(x, u)

x = f(x, r −Kx) = f(x, r −K(x− e))

x, e are chosen to be state variables of this observer based system, there are eight states intotal. From plots below, we see that the residence time for dynamic controller is larger thanstatic controller and the amplitude for dynamic controller is also larger than static controller.The Matlab codes for this part is attached below:

1 %--------------------------------------------------------------------------2 % Problem 7, Simulation results for observer based compensator3 At = [A-B*K B*K;4 zeros(size(A)) A-L*C];5 Bt = [B;6 zeros(size(B))];7 Ct = [C zeros(size(C))];8 sys_ob = ss(At,Bt,Ct,0);9 [Yl_o,Tl_o] = lsim(sys_ob,u,t,[[0.53288;0;0;0];[0.53288;0;0;0]]);

10 figure(3);clf;11 plot(Tl_o,Yl_o(:,1));12 hold on13 plot(Tl_o,Yl_o(:,2));14 hold off

12

Page 13: EECS 562 & AEROSP 551 Inverted Pendulum on a Cart …yeeyoung/publication/nl.pdf · Inverted Pendulum on a Cart Project Prof. J.W. Grizzle, Univ. of Michigan ... Solution:Itisconventionaltowritedownthecombinedequtionforthesystemplusobserver

15 h = legend('$\phi$','$\bar{s}$');16 set(h,'interpreter','Latex','FontSize',9)17 xlabel('t'); ylabel('y');18 title('Simulation for Linearized Model plus Observer,x_0(1)=0.53288')19 % Nonlinear model simulation20 g = @(t,x) [x(2);(-0.5*x(2)^2*sin(x(1))*cos(x(1))+sin(x(1))-cos(x(1))...21 *(-K*[x(1)-x(5);x(2)-x(6);x(3)-x(7);x(4)-x(8)]))/(1+0.5*(sin(x(1)))^2);x(4);22 (1.5*x(2)^2*sin(x(1))-cos(x(1))*sin(x(1))+3*(-K*[x(1)-x(5);...23 x(2)-x(6);x(3)-x(7);x(4)-x(8)]))/(1+0.5*(sin(x(1)))^2);...24 [x(2)-(x(2)-x(6));(-0.5*x(2)^2*sin(x(1))*cos(x(1))+sin(x(1))-cos(x(1))*(0)...25 )/(1+0.5*(sin(x(1)))^2)-(-0.5*(x(2)-x(6))^2*sin(x(1)-x(5))*...26 cos(x(1)-x(5))+sin(x(1)-x(5))-cos(x(1)-x(5))*(0)...27 )/(1+0.5*(sin(x(1)-x(5)))^2);x(4)-(x(4)-x(8));...28 (1.5*x(2)^2*sin(x(1))-cos(x(1))*sin(x(1))+3*(0))/(1+0.5*...29 (sin(x(1)))^2)-(1.5*(x(2)-x(6))^2*sin(x(1)-x(5))-cos(x(1)-x(5))...30 *sin(x(1)-x(5))+3*(0))/(1+0.5*(sin(x(1)-x(5)))^2)]-...31 L*C*[x(5);x(6);x(7);x(8)]];32 tspan = [0 10];33 [Tn_o,Yn_o] = ode45(g,tspan,[[0.53288;0;0;0];[0.53288;0;0;0]],1e-3);34 figure(4);clf;35 plot(Tn_o,Yn_o(:,1));36 hold on37 plot(Tn_o,Yn_o(:,3));38 hold off39 h = legend('$\phi$','$\bar{s}$');40 set(h,'interpreter','Latex','FontSize',9)41 xlabel('t'); ylabel('y');42 title('Simulation for Nonlinear Model plus Observer,x_0(1)=0.53288')

The simulation results are listed below:

Figure 5: Simulation for x0(1) = 0.1

13

Page 14: EECS 562 & AEROSP 551 Inverted Pendulum on a Cart …yeeyoung/publication/nl.pdf · Inverted Pendulum on a Cart Project Prof. J.W. Grizzle, Univ. of Michigan ... Solution:Itisconventionaltowritedownthecombinedequtionforthesystemplusobserver

Figure 6: Simulation for x0(1) = 0.5

Figure 7: Simulation for x0(1) = 0.5325

Figure 8: Simulation for x0(1) = 0.53288

From these graphs, we see the nonlinear system becomes unstable when x0(1) ≈ 0.53288.this value is smaller than that in problem 5.

14

Page 15: EECS 562 & AEROSP 551 Inverted Pendulum on a Cart …yeeyoung/publication/nl.pdf · Inverted Pendulum on a Cart Project Prof. J.W. Grizzle, Univ. of Michigan ... Solution:Itisconventionaltowritedownthecombinedequtionforthesystemplusobserver

Problem 8: Observer Based Compensator using Nonlinear Model (10 points)Now explore the following design for the observer. Let your linear observer from Problem 6be

˙x = Ax+Bu+ L(y − y)y = Cxu = Kx

(7)

and note that the controller is implemented as u = Kx. You recognize the observer as beinga copy of the linearized model plus an “output injection” term L(y − y), which adjusts thestate estimates as a function of errors in the estimate of the output. For the nonlinear plant,consider implementing the observer as

˙x = f(x, u) + L(y − y)y = Cxu = Kx

(8)

which you recognize as being a copy of the nonlinear model plus linear output injection. Seeif this observer provides better estimates and hence better performance. Why should theorigin of the closed-loop nonlinear system still be asymptotically stable? Hint: linearize theclosed-loop system (8) about the origin and compare to (7). (Second hint: doing this on themodel with the dynamics written out explicitly is way too painful. Use the chain rule on(8).)Solution:Yes, this observer provides better estimates. Linearization about origin can convertthe nonlinear equations for system (8) to linearized equation the same as system (7). Theeigenvalues for state matrix (A − BK) and (A − LC) are −3,−2,−0.7 ± 0.2i, the realpart of them are all negative, thus the origin of the closed loop nonlinear system is stillasymptotically stable.

15