State Feedback and Observer Based Control Design for a Two Inverted Pendulum on a Cart System - MapleSim Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : MapleSim Toolboxes : MapleSim Control Design Toolbox : Examples : MapleSimControlDesign/TwoInvertedPendulum

State Feedback and Observer Based Control Design for a Two Inverted Pendulum on a Cart System

1. System Definition

2. State-Feedback Control Design
2.1 Determining Controllability
2.2 Designing a State-Feedback Controller

3. Observer-Based Control Design
3.1 Determining Observability
3.2 Designing a Observer-Based Controller

4. LQG Control Design

 

1. System Definition

 

The image at right is of a cart of mass M supporting two inverted pendulums of mass m with lengths l1 and l2, respectively.

 

The variables and parameters of the system are summarized in the following table:

 

System Parameters

Mass of cart M

Mass of pendulums m

Length of pendulum 1 l1

Length of pendulum 2 l2

Angle of pendulum 1 from vertical θ1

Angle of pendulum 2 from vertical θ2

Forcing input ut

Velocity vt

 

                        

 

For small θ1 and θ2, the equations of motion for this system are:

 

Mv.t=mgθ1mgθ2+u

mv.t+l1θ1..t=mgθ1

mv.t+l2θ2..t=mgθ2

 

With some simple term re-writing and by letting x1=θ1,  x2=θ2, x3=θ.1, x4=θ.2 the equations of motion can be converted into state space form, that is x.=Ax+Bu.

Am00100001a1a200a3a400:  Bm00b1b2 :

where:

params a1=M+mgMl1,a2=mgMl1,a3=mgMl2,a4=M+mgMl2,b1=1Ml1,b2=1Ml2:

Am  evalAm, params: Bm  evalBm, params:

 

Since the states of the system, x1 and x2, act as our outputs and since this design assumes that both state variables are measured, the C matrix for our system can be defined as:

Cm10000100:  Dm00:

Using the DynamicSystems[StateSpace] command we can create the state space representation for our system.

 

sysDynamicSystemsStateSpaceAm,Bm,Cm, Dm: DynamicSystemsPrintSystemsys

State Spacecontinuous2 output(s); 1 input(s); 4 state(s)inputvariable=u1toutputvariable=y1t,y2tstatevariable=x1t,x2t,x3t,x4ta=00100001M+mgMl1mgMl100mgMl2M+mgMl200b=001Ml11Ml2c=10000100d=00

(1)

 

2. State-Feedback Control Design

 

The system defined in the previous section can be controlled so that the inverted pendulums remain vertical on top of the cart, that is θ1=θ2=0, using a state-feedback control strategy provided the system is: (1) controllable by the input, and (2) the states x1 and x2 can be measured directly

2. 1 Determining Controllability

 

The controllability matrix for the above system can be determined using the DynamicSystems[ControllabilityMatrix] command.

CntrlMatrixControllabilityMatrixsys

01Ml10M+mgM2l12mgM2l1l201Ml20mgM2l1l2M+mgM2l221Ml10M+mgM2l12mgM2l1l201Ml20mgM2l1l2M+mgM2l220

(2)

 

Rank of CntrlMatrix:

 

LinearAlgebraRankCntrlMatrix

4

(3)

 

Determinant of CntrlMatrix:

LinearAlgebraDeterminantCntrlMatrix

g2l1l22M4l14l24

(4)

 

Even though the generic rank of the above matrix is 4 (i.e. matrix is generically full rank), we cannot say the system is controllable without verifying the conditions upon which the determinant of the controllability matrix becomes 0. For this system, the determinant becomes 0 when l1=l2. From this we can conclude that the system is controllable if the lengths of the inverted pendulums differ from each other.

2. 2 Designing a State-Feedback Controller

Assuming we have prior knowledge of the desired location of the closed-loop poles for our system, we can use the ControlDesign[StateFeedback][PolePlacement]  command to calculate the state feedback gain for a single-input system.

 

For this design, let us assume that the desired location of the closed-loop poles are:

 

poles3, 52+2I,522I,7:

 

The state-feedback gain, Kc, is then:

 

Kc, KrStateFeedbackPolePlacementsys,poles, 'return_Kr'

144Mg2l2+325Mgl1l2+861Ml12l24g2l1m+4g2l2mgl1l2144Mg2l1+325Mgl1l2+861Ml1l22+4g2l1m4g2l2mgl1l2526g+83l1l1Ml2gl1l2526g+83l2l1Ml2gl1l2,8618Ml1l2g8618Ml1l2g

(5)

We can obtain the closed-loop state-space matrices using the ControlDesign[StateFeedbackClosedLoop] command. Then we can verify that the closed-loop system has its poles located at the desired pole locations.

clsys  ControlDesignStateFeedbackClosedLoopsys, Kc, ':-Kr' =Kr: 

LinearAlgebraEigenvaluesclsys:-a

37522I52+2I

(6)

 

At this point, we can simulate the closed-loop system to verify if the controller that we designed is able to stabilize the inverted pendulums on the cart. Since the controller was developed symbolically we can perturb any number of the system parameters. Doing so, will give us a sense of the controller's robustness to parameter variations.

Investigating the Closed-Loop Response Simulation

Parameters

Value

Mass of cart M        

Mass of pendulums m        

Length of pendulum 1 l1        

Length of pendulum 2  l2        

Gravity g        

9.81

 

3. Observer-Based Control Design

 

The state-feedback controller which was designed in the previous section assumed that the states x1 and x2 are measured directly. This is not practical in many situations, and consequently control designers must turn into observer-based control design to control their systems. Observer-based control design makes use of an observer module to estimate the states. It requires the system to be observable in addition to being controllable.

3. 1 Determining Observability

This section will examine the observability of the system under the following conditions: (1) x1 is measured and x2 is not, (2) x2 is measured and x1 is not, and (3) x1 and x2 are measured.  

 

3.1.1 -  x1 is measured and x2 is not

 

We get a subsystem using DynamicSystems[Subsystem] command where only x1 is measurable:

subsysx1DynamicSystemsSubsystemsys,all,1: 

The observability matrix can be determined by using the DynamicSystems[ObservabilityMatrix] command.

ObsvMatrixx1DynamicSystemsObservabilityMatrixsubsysx1

10000010M+mgMl1mgMl10000M+mgMl1mgMl1

(7)

Rank of ObsvMatrixx1:

LinearAlgebraRankObsvMatrixx1

4

(8)

Determinant of ObsvMatrixx1:

LinearAlgebraDeterminantObsvMatrixx1

m2g2M2l12

(9)

Since the observability matrix is calculated symbolically, knowing that the matrix is generically full rank does not provide us with enough information to say that the system is observable for all possible values of parameters. We must determine for what parameter values the determinant of the observability matrix becomes 0.  For this example, the system is observable for all values of the parameters.

 

 

 

3. 2 Designing an Observer-Based Controller

In section 2.2, we showed how the ControlDesign toolbox could be used to design a state-feedback controller when both angles are measured. In this section, we will show how the ControlDesign toolbox can be used to design an observer-based control system when only one state, let us say x1, is measured.

According to the separation principle, for linear time invariant systems, the state feedback and state observer can be designed independently. We select the desired poles for the observer error dynamic to be about 5-10 times further away from the jω axis than those of the state feedback gain design. This ensures that the state feedback poles are the dominant poles of the system.

For this example, the following values for the state-feedback poles and the observer poles were chosen. If you will recall, the state feedback poles that were chosen here are the same as those used in the state-feedback control design section.

StateFeedbackPoles−3,52+2I,522I,7:

ObserverPoles25,27,26+7I,267I:

Using the ControlDesign[StateObserver][PolePlacement] and ControlDesign[StateFeedback][PolePlacement] commands the observer gain, `L__`,  and state feedback gain, Kc, to stabilize the inverted pendulum configuration on top of the cart are:

 

LStateObserverPolePlacementsubsysx1,ObserverPoles

104104Mg+700Ml2+gml1l2mgMgl1+Mgl2+4104Ml1l2+gl1m+gl2mMl1l2M2g2l1+4104M2gl1l2+489375M2l1l22+2Mg2l1m+4104Mgl1l2m+g2l1m2+g2l2m2Ml22mg

(15)

 

Kc, KrStateFeedbackPolePlacementsubsysx1,StateFeedbackPoles, 'return_Kr'

144Mg2l2+325Mgl1l2+861Ml12l24g2l1m+4g2l2mgl1l2144Mg2l1+325Mgl1l2+861Ml1l22+4g2l1m4g2l2mgl1l2526g+83l1l1Ml2gl1l2526g+83l2l1Ml2gl1l2,8614Ml1l2g

(16)

Using the ControlDesign[ControllerObserver] command, the closed-loop system of the state-feedback controller and observer can be obtained. We can verify that closed-loop system poles match the desired pole locations.

closedloopControlDesignControllerObserversubsysx1,Kc,L, ':-Kr'=Kr, 'closedloop'=true, 'stateerror' =true: 

      eigclLinearAlgebraEigenvaluesclosedloop:-a

272573522I52+2I267I26+7I

(17)

 

We modify the state-space representation of the closed-loop system so that there are 8 outputs corresponding to all the states of the closed-loop system. The first four outputs represent the state outputs, while the last four outputs represent the observer error.

  closedloop1DynamicSystemsStateSpaceclosedloop:-a, closedloop:-b,LinearAlgebra:-IdentityMatrixclosedloop:-statecount, Matrixclosedloop:-statecount,closedloop:-inputcount:

 

As in the previous section, we can simulate the closed-loop system to verify if the observer-based controller that was designed can stabilize the two inverted pendulums on the cart system.

Investigating the Closed-Loop Response Simulation to Observer-Based Control Design

Parameters

Value

Mass of cart M        

Mass of pendulums m        

Length of pendulum 1 l1        

Length of pendulum 2  l2        

Gravity g        

9.81

4. LQG Control Design

We design the LQR controller using the ControlDesign[LQR] command. First, using the ControlDesign[ComputeQR] command, we compute the values of the weighting matrices Q and R based on a desired closed-loop time constant.

τc0.2:  paramsM=10, m=1, g=9.81,l1=1.2,l2=2:

W  ControlDesignComputeQRsubsysx1, τc, 'parameters'=params;

RecordQ=1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.,R=0.00000399497633449469

(18)

Kclqr, Krlqr  ControlDesignLQRsubsysx1, W:-Q, W:-R, 'parameters'=params, 'return_Kr';

3816.404290949014212.661306105791319.797477087631906.54047265615,513.977015364205

(19)

We design the Kalman observer using the ControlDesign[Kalman] command.

Gm  0.25350102500: Hm 0.001: Qm  200: Rm  0.005:

Lkal  ControlDesignKalmansubsysx1, Gm, Hm, Qm, Rm, 'parameters' =params1; 

101.76242790374190975.70419618153428.231101085425.93529526437802105

(20)

We get the LQG controller equations using the ControlDesign[ControllerObserver] command.

LQG  ControlDesignControllerObserversubsysx1, Kclqr, Lkal, 'Kr' =Krlqr, 'parameters' =params:

PrintSystemLQG;

State Spacecontinuous1 output(s); 2 input(s); 4 state(s)inputvariable=y1_reft,y1_meastoutputvariable=u1tstatevariable=x1_estt,x2_estt,x3_estt,x4_estta=101.7624279037410.01.00.090975.704196181530.00.01.03737.2722919851153351.87260882810705109.98312308623666158.878372714990585.937198561523493105216.028565305289665.989873854381695.32702363280744b=0.0101.7624279037410.090975.7041961815342.831417945303873428.231101085419625.6988507682102785.935295264378018105c=3816.40429094900544212.66130610579151319.7974770876321906.5404726561487d=513.9770153642054990

(21)

We get the closed-loop system using the ControlDesign[ControllerObserver] command with the 'closedloop' option

clsyslqgControlDesignControllerObserversubsysx1,Kclqr,Lkal, ':-Kr'=Krlqr, 'parameters'=params, 'closedloop'=true, 'stateerror' =true:      eigcl_lqg LinearAlgebraEigenvaluesclsyslqg:-a; 

5.11237012925113+4.08135896037352I5.112370129251134.08135896037352I2.21567959746349+0.00857051051146585I2.215679597463490.00857051051146585I65.0232928426605+0.I13.7032477007070+24.1120223072031I13.703247700707024.1120223072031I9.33263965978372+0.I

(22)

We modify the state-space representation of the closed-loop system so that there are 8 outputs corresponding to all the states of the closed-loop system. The first four outputs represent the state outputs, while the last four outputs represent the observer error.

  clsyslqg1DynamicSystemsStateSpaceclsyslqg:-a, clsyslqg:-b,LinearAlgebra:-IdentityMatrixclsyslqg:-statecount, Matrixclsyslqg:-statecount,clsyslqg:-inputcount:

Investigating the Closed-Loop Response Simulation to LQG Control Design

Parameters

Value

Mass of cart M        

Mass of pendulums m        

Length of pendulum 1 l1        

Length of pendulum 2  l2        

Gravity g        

9.81


Download Help Document

Was this information helpful?



Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam