Linear control of inverted pendulum

Similar documents
Numerics and Control of PDEs Lecture 1. IFCAM IISc Bangalore

Numerics and Control of PDEs Lecture 7. IFCAM IISc Bangalore. Feedback stabilization of a 1D nonlinear model

Review: control, feedback, etc. Today s topic: state-space models of systems; linearization

CALIFORNIA INSTITUTE OF TECHNOLOGY Control and Dynamical Systems

The Inverted Pendulum

Lab 6a: Pole Placement for the Inverted Pendulum

CDS 101/110a: Lecture 2.1 Dynamic Behavior

CDS 101/110a: Lecture 2.1 Dynamic Behavior

ECEN 420 LINEAR CONTROL SYSTEMS. Lecture 6 Mathematical Representation of Physical Systems II 1/67

Design and Comparison of Different Controllers to Stabilize a Rotary Inverted Pendulum

TIME DELAY AND FEEDBACK CONTROL OF AN INVERTED PENDULUM WITH STICK SLIP FRICTION

Lab 6d: Self-Erecting Inverted Pendulum (SEIP)

State Regulator. Advanced Control. design of controllers using pole placement and LQ design rules

CDS 101: Lecture 5-1 Reachability and State Space Feedback

The Control of an Inverted Pendulum

Swinging-Up and Stabilization Control Based on Natural Frequency for Pendulum Systems

1 (30 pts) Dominant Pole

CIMPA Summer School on Current Research on Finite Element Method Lecture 1. IIT Bombay. Introduction to feedback stabilization

In the presence of viscous damping, a more generalized form of the Lagrange s equation of motion can be written as

Real-Time Implementation of a LQR-Based Controller for the Stabilization of a Double Inverted Pendulum

Linearization problem. The simplest example

State Feedback MAE 433 Spring 2012 Lab 7

Rotary Inverted Pendulum

Feedback Optimal Control for Inverted Pendulum Problem by Using the Generating Function Technique

SRV02-Series Rotary Experiment # 7. Rotary Inverted Pendulum. Student Handout

EE Homework 3 Due Date: 03 / 30 / Spring 2015

Suppose that we have a specific single stage dynamic system governed by the following equation:

MEAM 510 Fall 2011 Bruce D. Kothmann

MEM04: Rotary Inverted Pendulum

The Control of an Inverted Pendulum

Linear Quadratic Regulator (LQR) I

1. Find the solution of the following uncontrolled linear system. 2 α 1 1

MEAM 510 Fall 2012 Bruce D. Kothmann

Stabilization of Heat Equation

Analog Signals and Systems and their properties

Computer Problem 1: SIE Guidance, Navigation, and Control

Linear Quadratic Regulator (LQR) Design I

Appendix A Equations of Motion in the Configuration and State Spaces

Topic # /31 Feedback Control Systems. Analysis of Nonlinear Systems Lyapunov Stability Analysis

EE 16B Midterm 2, March 21, Name: SID #: Discussion Section and TA: Lab Section and TA: Name of left neighbor: Name of right neighbor:

State Feedback and State Estimators Linear System Theory and Design, Chapter 8.

Lab 5a: Pole Placement for the Inverted Pendulum

System simulation using Matlab, state plane plots

ECE-320: Linear Control Systems Homework 8. 1) For one of the rectilinear systems in lab, I found the following state variable representations:

CDS 101 Precourse Phase Plane Analysis and Stability

ACM/CMS 107 Linear Analysis & Applications Fall 2016 Assignment 4: Linear ODEs and Control Theory Due: 5th December 2016

MCE 366 System Dynamics, Spring Problem Set 2. Solutions to Set 2

Inverted Pendulum. Objectives

Quadratic Stability of Dynamical Systems. Raktim Bhattacharya Aerospace Engineering, Texas A&M University

EEE582 Homework Problems

kx m x B N 1 C L, M Mg θ

CONTROL DESIGN FOR SET POINT TRACKING

Lecture 9. Introduction to Kalman Filtering. Linear Quadratic Gaussian Control (LQG) G. Hovland 2004

Automatic Control II Computer exercise 3. LQG Design

Übersetzungshilfe / Translation aid (English) To be returned at the end of the exam!

EECS C128/ ME C134 Final Wed. Dec. 15, am. Closed book. Two pages of formula sheets. No calculators.

Matlab-Based Tools for Analysis and Control of Inverted Pendula Systems

2 Lyapunov Stability. x(0) x 0 < δ x(t) x 0 < ɛ

Assignments VIII and IX, PHYS 301 (Classical Mechanics) Spring 2014 Due 3/21/14 at start of class

6.241 Dynamic Systems and Control

Reverse Order Swing-up Control of Serial Double Inverted Pendulums

A Light Weight Rotary Double Pendulum: Maximizing the Domain of Attraction

Complex Dynamic Systems: Qualitative vs Quantitative analysis

Represent this system in terms of a block diagram consisting only of. g From Newton s law: 2 : θ sin θ 9 θ ` T

Introduction to Modern Control MT 2016

Robotics. Control Theory. Marc Toussaint U Stuttgart

EE C128 / ME C134 Final Exam Fall 2014

4 Second-Order Systems

moments of inertia at the center of gravity (C.G.) of the first and second pendulums are I 1 and I 2, respectively. Fig. 1. Double inverted pendulum T

Chapter 3. LQ, LQG and Control System Design. Dutch Institute of Systems and Control

sc Control Systems Design Q.1, Sem.1, Ac. Yr. 2010/11

Lecture 2 and 3: Controllability of DT-LTI systems

Modeling and Experimentation: Compound Pendulum

Controlling the Inverted Pendulum

Control engineering sample exam paper - Model answers

Nonlinear Control Systems

Video 8.1 Vijay Kumar. Property of University of Pennsylvania, Vijay Kumar

Nonlinear Control Systems 1. - Introduction to Nonlinear Systems

Homework Solution # 3

28. Pendulum phase portrait Draw the phase portrait for the pendulum (supported by an inextensible rod)

ET3-7: Modelling I(V) Introduction and Objectives. Electrical, Mechanical and Thermal Systems

16.31 Fall 2005 Lecture Presentation Mon 31-Oct-05 ver 1.1

Dynamic Modeling of Rotary Double Inverted Pendulum Using Classical Mechanics

Inverted Pendulum: State-Space Methods for Controller Design

Linear Quadratic Regulator (LQR) Design II

x(n + 1) = Ax(n) and y(n) = Cx(n) + 2v(n) and C = x(0) = ξ 1 ξ 2 Ex(0)x(0) = I

EE363 homework 2 solutions

University of Toronto Department of Electrical and Computer Engineering ECE410F Control Systems Problem Set #3 Solutions = Q o = CA.

= 0 otherwise. Eu(n) = 0 and Eu(n)u(m) = δ n m

Lecture 4 Continuous time linear quadratic regulator

Lecture 2: Discrete-time Linear Quadratic Optimal Control

State space control for the Two degrees of freedom Helicopter

CALIFORNIA INSTITUTE OF TECHNOLOGY Control and Dynamical Systems

The Acrobot and Cart-Pole

Intermediate Process Control CHE576 Lecture Notes # 2

ROTATIONAL DOUBLE INVERTED PENDULUM

6 OUTPUT FEEDBACK DESIGN

Exam. 135 minutes, 15 minutes reading time

Perturbation theory for eigenvalues of Hermitian pencils. Christian Mehl Institut für Mathematik TU Berlin, Germany. 9th Elgersburg Workshop

EE363 homework 8 solutions

Transcription:

Linear control of inverted pendulum Deep Ray, Ritesh Kumar, Praveen. C, Mythily Ramaswamy, J.-P. Raymond IFCAM Summer School on Numerics and Control of PDE 22 July - 2 August 213 IISc, Bangalore http://praveen.cfdlab.net/teaching/control213 1 Inverted pendulum 334 M. LANDRY, S. CAMPBELL, K. MORRIS, AND C. AGUILAR y m l j i P θ l g = -g j F(t)i M O x(t) x Figure 1. Inverted pendulum system. Lagrangian x(t) θ(t) M m L l P F (t) Table 1 Notation. Displacement of the center of mass of the cart from point O Angle the pendulum makes with the top vertical Mass of the cart Mass of the pendulum Length of the pendulum Distance from the pivot to the center of mass of the pendulum (l = L/2) Pivot point of the pendulum Force applied to the cart In our experimental setup, the force F (t) on the cart is (1.3) I = Moment of inertia of pendulum about its cg = 1 3 ml2 L = 1 2 Mẋ2 + 1 2 m(ẋ + l θ cos θ) 2 + 1 2 (I + ml2 ) θ 2 mgl cos θ Euler-Lagrange equation ( ) d L L ẋ x = F, gives F (t) =αv (t) βẋ(t), ( ) d L θ L θ = (M + m)ẍ + ml θ cos θ ml θ 2 sin θ + kẋ = F where V (t) is the voltage in the motor driving the cart, and the second term represents electrical resistance in the motor. The voltage V (t) can be varied and is used to control the system. Themlẍ valuescos of the θ + parameters (I + ml for 2 ) θ our experimental mgl sinsetup θ + c[21] θ are = given in Table 2. The precise value of the viscous friction ɛ is difficult to measure; however, we expect that it will be of a similar order of magnitude as β. Our work will thus consider ɛ in the range [, 15]. A more convenient form of the equations1is found by solving for ẍ and θ from equations (1.1) and (1.2) and introducing the variables (1.4) y =(y 1,y 2,y 3,y 4 ) T =(x, θ, ẋ, θ) T.

This is a coupled system [ ] [ẍ ] M + m ml cos θ ml cos θ I + ml 2 = θ Define determinant Solving for ẍ, θ [ẍ ] = 1 θ D Define Then we can write the first order system ż 1 ż 2 ż 3 = ż 4 [ ] ml θ2 sin θ kẋ + F mgl sin θ c θ D = (M + m)(i + ml 2 ) m 2 l 2 cos 2 θ [ ml cos θ(c θ mgl sin θ) + (I + ml 2 )(F kẋ + ml θ ] 2 sin θ) (M + m)( c θ + mgl sin θ) ml cos θ(f kẋ + ml θ 2 sin θ) z = (z 1, z 2, z 3, z 4 ) = (x, ẋ, θ, θ) ż 1 = z 2, ż 3 = z 4 z 2 1 [ml cos z D 3(cz 4 mgl sin z 3 ) + (I + ml 2 )(F kz 2 + mlz4 2 sin z 3 )] z 4 1 [(M + m)( cz D 4 + mgl sin z 3 ) ml cos z 3 (F kz 2 + mlz4 2 sin z 3 )] In the experimental setup of Landry et al. [1], the force F on the cart is F (t) = αu(t) βẋ, α >, β > where u is the voltage in the motor driving the cart, and the second term represents the electrical resistance in the motor. Let us write the non-linear pendulum model as 1.1 Excercises dz = N(z, u) The matlab programs are in the directory pendulum; go into this directory and start matlab. E.g. if you are working on the Unix/Linux command line $ cd control213/ pendulum $ matlab If you have started matlab through some other way, then change the directory inside matlab >> cd <Full path to>/control213/ pendulum 2

Or use the matlab gui to change the working directory. The solution of the non-linear pendulum is implemented in nlp.m file and ths right hand side function without any control (F = ) is implemented in rhs nlp.m file. Study these two programs. The pendulum has two equilibrium positions, one upright (θ = ) and another in the down position (θ = π). 1. Using nlp.m solve the non-linear pendulum problem with initial condition close to upright position z() = [,, 5π 18, ] and final time T = 1. Is the upright position stable? What happens to the four variables? What is the time asymptotic value of x, ẋ, θ, θ? 2. Solve the non-linear pendulum problem with initial condition close to downward position z() = [,, 17π 18, ] and final time T = 1. Is the downward position stable? 3. Now set the value of friction coefficients k and c to zero in parameters.m file and run nlp.m again. How does the solution behave qualitatively? Is it converging to a stationary state? Note Set the value of k and c back to their initial non-zero values. 1.2 Linearised system We linearize around z = (,,, ) z 1 1 z 1 d z 2 z 3 = (k + β)v 2 m2 l 2 gv 2 mlcv 2 I+ml 2 I+ml 2 z 2 1 z 3 + ml(k+β)v z 4 2 mlgv M+m 1 cv 1 z 4 where v 1 = then we have the linear model M + m I(M + m) + mml 2, v 2 = dz = Az + Bu αv 2 αmlv 1 M+m I + ml 2 I(M + m) + mml 2 u 3

1.3 Excercises 1. Generate matrices for linear system >> parameters >> [ A, B ] = get_system_matrices ( ) 2. Compute eigenvalues >> e = eig ( A ) >> plot ( real ( e ), imag ( e ), 'o' ) Is there an unstable eigenvalue? Is there a zero eigenvalue? 3. The linear pendulum system is controllable if rank of controllability matrix is four. Check that (A, B) is controllable by computing rank of controllability matrix P c = [ B AB A 2 B A 3 B ] >> Pc = [ B, A B, Aˆ2 B, Aˆ3 B ] ; >> rank ( Pc ) 4. Check the controllability using Hautus criterion. Compute all the eigenvectors and eigenvalues of A. For each eigenvalue λ and eigenvector V of A check if A V = λv B V If the above condition is true for each unstable eigenvalue, i.e., with real(λ), then the system is stabilizable. Is the linear pendulum stabilizable? 5. Solve linear pendum model (see lp.m and rhs lp.m) with initial condition z() = [,, 5π 18, ] upto a final time of T = 5. Compare this solution with solution of non-linear model. 2 Matlab function: lqr The solution X of algebraic Riccati equation can be computed in matlab using A X + XA XBR 1 B X + Q =, Q = C C (1) 4

>> [ K, X, E ] = lqr ( A, B, Q, R ) ; Here K is the feedback gain and can be computed as K = B X and E contains the eigenvalues of A BK. 3 Minimal norm feedback control The minimal norm control is given by u(t) = Kz(t) with K = B X where X is the maximal solution of Algebraic Bernoulli Equation (ABE) A X + XA XBB X = For inverted pendulum, matrix A has a zero eigenvalue. We replace A with A+ωI, ω >, for determining the control. (A + ωi) X + X(A + ωi) XBB X =, K = B X Model with feedback dz = (A BK)z, z() = z 3.1 Excercises 1. Compute the minimal norm feedback matrix K using lqr function >> Q = zeros ( 4, 4 ) ; >> R = 1 ; >> om =. 1 ; >> As = A + om eye ( 4 ) ; >> [ K, X, E ] = lqr ( As, B, Q, R ) ; Compute feedback gain from solution X of Riccati equation and check that it is same as K given by lqr function >> K1 = B ' X >> K K1 % This should g i v e you zero matrix E contains the eigenvalues of As BK. Compare eigenvalues of As and As-B*K >> e = eig ( As ) ; >> plot ( real ( e ), imag ( e ), 'o', real ( E ), imag ( E ), '*' ) 5

Observe that unstable eigenvalues of As have been reflected symmetrically about the imaginary axis. 2. Also check that A BK is stable by computing its eigenvalues. >> e1 = eig ( A ) ; >> e2 = eig ( A B K ) ; >> plot ( real ( e1 ), imag ( e1 ), 'o', real ( e2 ), imag ( e2 ), '*' ) 4 Feedback control using LQR approach Output Performance measure Find feedback law J = 1 2 = 1 2 y m = Cz, e.g. C = I 4 y mq m y m + 1 2 z Qz + 1 2 u = Kz u Ru u Ru, which minimizes J. The feedback or gain matrix K is given by K = R 1 B X where X is solution of algebraic Riccati equation (ARE) 4.1 Excercises A X + XA XBR 1 B X + Q = 1. We may measure different output quantities, e.g., C = [ 1 ], C = [ 1 ], C = Q = C Q m C [ ] 1 1, C = 1 1 1 1 These correspond to controlling (x), (θ), (x, θ) and (x, ẋ, θ, θ) respectively. In each case, check if (A, C) is observable by computing rank of observability matrix C P o = CA CA 2 Is rank(p o ) = 4 or is rank(p o ) < 4? CA 3 6

For which C is the rank condition satisfied? Which of the four state variables is important? 2. Compute feedback operator K using lqr function. We will control position and angle. >> C = [ 1 ; 1 ] ; >> Q = C ' C ; >> R = 1 ; >> [ K, X, E ] = lqr ( A, B, Q, R ) ; >> plot ( real ( E ), imag ( E ), 'o' ) E contains the eigenvalues of A BK. Compare eigenvalues of A and A BK >> e = eig ( A ) ; >> plot ( real ( e ), imag ( e ), 'o', real ( E ), imag ( E ), '*' ) Is A BK stable? 3. Solve with LQR feedback control. This is implemented in program pend lqr.m which solves both linear and non-linear model. Compare the linear and non-linear solutions. Try with R =.1 and R =.1 and initial condition z() = [ 5π ] 18 Which is better, R =.1 or R =.1? 4. Run the program pend lqr.m with different initial angles z() = [ 5π 18 ], z() = [ 58π 18 ] and for R =.1 and R =.1. Which value of R gives faster stabilization? What is the maximum magnitude of control in each case? 5. If the initial angle θ is too large, then it may not be possible to stabilize the nonlinear pendulum. The linear pendulum is always stabilized. Find angle beyond which non-linear model cannot be stabilized. Do this for R =.1, R =.1 and R =.5. Use final time of T = 3 and initial conditions of the form z() = [ θ ] Use the evolution of energy as an indicator for finding the threshold angle. If the energy starts to increase monotonically, then conclude that it is not possible to stabilize the system. 7

5 Linear system with noise and partial information Consider the system with noise in the model and initial condition dz = Az + Bu + w, z() = z + η where w and η are error/noise terms. We may not have access to the full state but only some partial information which is also corrupted by noise. [ ] [ ] 1 x y o = Hz + v, e.g. H = = y 1 o = + v θ which corresponds to observing the position of cart x and the position of pendulum θ only. Since we have partial information, we have to estimate to estimate the remaining state variables somehow. 5.1 A simple estimator Suppose we can observe only z 1 = x and z 3 = θ but this information is also contaminated by some error. Then we can try to estimate ẋ and θ by using finite difference in time. ẋ(t n ) = x(t n) x(t n 1 ), θ(tn ) = θ(t n) θ(t n 1 ) t t Then we can try the following feedback control scheme using backward Euler time discretization This is implemented in lp noest.m. 5.2 Excercise y n = Hz n + v n y n 1 u n 1 = K t (yn 1 y1 n 1 ) y2 n 1 t (yn 2 y2 n 1 ) z n+1 z n = Az n+1 + Bu n + w n t Run the program lp noest.m and observe that the state and control are very noisy and hence this approach is not of practical utility. 8

5.3 Estimation problem Linear estimator dz e = Az e + Bu + L(y o Hz e ) We determine the filtering gain L by minimizing J = 1 2 The best L is given by (y o Hz e ) R 1 v (y o Hz e ) + 1 2 where X e is solution of algebraic Riccati equation w R 1 w w L = X e H R 1 v (2) AX e + X e A X e H R 1 v HX e + R w = This equation is similar to equation (1) if we replace 5.4 Excercises A with A B with H Q with R w R with R v 1. Compute the filtering matrix L >> Rw = (5 e 2)ˆ2 diag ( [ 1, 1, 1, 1 ] ) ; >> Rv = (5 e 2)ˆ2 diag ( [ 1, 1 ] ) ; >> [ L, Xe ] = lqr ( A ', H ', Rw, Rv ) ; >> L = real ( L ' ) ; 2. Compute eigenvalues of A LH and check that they are all stable. >> eig ( A L H ) 3. Compute L from equation (2) and check that it is same as L obtained in step 1 above. >> L1 = Xe H ' / Rv ; >> L L1 9

5.5 Linear system with linear estimator The feedback is based on estimated solution u = Kz e or in matrix form d dz dz e = Az BKz e + w = LHz + (A BK LH)z e + Lv [ ] [ ] [ ] z A BK z = + LH A BK LH z e The initial condition is given by This is implemented in program lp est.m 5.6 Excercises z e z() = z + η, z e () = z [ I L ] [ ] w v 1. Run program lp est.m. Observe that initially z and z e differ but after some time, z e approches z so that the estimation becomes more accurate. You may have to zoom the plot near the initial time to see the difference. Note that all the quantities including the control behave in a more regular manner now as compared to the finite difference estimation used before. 5.7 Non-linear system with linear estimator The feedback is based on estimated solution using the linear estimator which is used to add the control into the non-linear model. with initial condition dz = N(z, u) dz e = Az e + Bu + L(y o Hz e ) y o = Hz u = Kz e z() = z + η, z e () = z Since we do not know the precise initial condition, the estimator contains an error in the initial condition. This is implemented in program nlp est.m and rhs nlpest.m 1

5.8 Excercises 1. Run program nlp est.m. Zoom the plot near initial time and compare the nonlinear solution with the linear estimator. Note that z e approaches z for larger times. 2. Increase the initial angle and check if the feedback can be stabilize the non-linear system. Have the threshold angles evaluated for R =.1, R =.1 and R =.5 changed? If yes, then what are the new threshold angles? 3. How does the control vary as R is changed? Is the behaviour the same as that observed in the earlier cases? 4. How does the value of R influence the stabilization of the state variables? 5.9 Excercises Here we will assume that we do not know the value of the friction coefficient k and c. So the linear estimator will be constructed taking k = and c = whereas the non-linear model will include the friction. We want to see if the estimator is still able to give a good estimate of the real state and if the system is stabilized by the feedback. 1. In parameters.m set k and c to be zero. 2. Copy nlp est.m as nlp est2.m 3. Modify the initial part like this parameters ; [ A, B ] = get_system_matrices ( ) ; k =. 5 ; c =. 5 ; 4. Run the program >> nlp_est2 Does the estimate and control still succeed? 11

6 Inverted pendulum: Parameters 7 List of Programs M Mass of cart 2.4 m Mass of pendulum.23 l Length of pendulum.36 k Friction in cart.5 c Friction in pendulum.5 α Coefficient of voltage 1.7189 β Friction in motor 7.682 a Acceleration due to gravity 9.81 1. parameters.m: Set parameters for pendulum 2. get system matrices.m: Computes matrices for linear model 3. hautus.m: Checks the stabilizability of the system using Hautus criterion 4. rhs nlpc.m: Computes right hand side of non-linear model, with feedback 5. rhs lp.m: Computes right hand side of linear model, without feedback 6. rhs nlp.m: Computes right hand side of non-linear model, without feedback 7. rhs lpc.m: Computes right hand side of linear model, with feedback 8. rhs nlpc.m: Computes right hand side of non-linear model, with feedback 9. rhs nlpest.m: Computes right hand side of non-linear model coupled with the linear estimator and feedback 1. lp.m: Solves the linear model without feedback 11. nlp.m: Solves the linear model without feedback 12. pend lqr.m: Solves the linear and non-linear models with feedback and full state information 13. lp est.m: Solves the linear model with noise and partial information, coupled estimator and feedback stabilization 14. lp noest.m: Solves the linear model with noise and partial information, feedback without estimation 12

15. nlp est.m: Solves the non-linear model with noise and partial information, coupled estimator and feedback stabilization References [1] M. Landry, S. A. Campbell, L. Morris and C. O. Aguilar, Dynamics of an inverted pendulum with delayed feedback control, SIAM J. Applied Dynamical Systems, Vol. 4, No. 2, pp. 333-351, 25. 13