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
2. State-Feedback Control Design
3. Observer-Based Control Design
The image at right is of a cart of mass M supporting two inverted pendulums of mass m with lengths l__1 and l__2, 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:
M⁢v.⁡t=−m⁢g⁢θ__1−m⁢g⁢θ__2+u
m⁢v.⁡t+l__1⁢θ__1..⁡t=m⁢g⁢θ__1
m⁢v.⁡t+l__2⁢θ__2..⁡t=m⁢g⁢θ__2
With some simple term re-writing and by letting x__1=θ__1, x__2=θ__2, x__3=θ.1, x__4=θ.2 the equations of motion can be converted into state space form, that is x.=A⋅x+B⋅u.
Am≔00100001a__1a__200a__3a__400: Bm≔00b__1b__2 :
where:
params ≔a__1=M+m⁢gM⁢l__1,a__2=m⁢gM⁢l__1,a__3=m⁢gM⁢l__2,a__4=M+m⁢gM⁢l__2,b__1=−1M⋅l__1,b__2=−1M⋅l__2:
Am ≔ evalAm, params: Bm ≔ evalBm, params:
Since the states of the system, x__1 and x__2, 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:
Cm≔10000100: Dm≔00:
Using the DynamicSystems[StateSpace] command we can create the state space representation for our system.
sys≔DynamicSystemsStateSpaceAm,Bm,Cm, Dm: DynamicSystemsPrintSystemsys
State Spacecontinuous2 output(s); 1 input(s); 4 state(s)inputvariable=u1⁡toutputvariable=y1⁡t,y2⁡tstatevariable=x1⁡t,x2⁡t,x3⁡t,x4⁡ta=00100001M+m⁢gM⁢l__1m⁢gM⁢l__100m⁢gM⁢l__2M+m⁢gM⁢l__200b=00−1M⁢l__1−1M⁢l__2c=10000100d=00
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 x__1 and x__2 can be measured directly
2. 1 Determining Controllability
The controllability matrix for the above system can be determined using the DynamicSystems[ControllabilityMatrix] command.
CntrlMatrix≔ControllabilityMatrixsys
Rank of CntrlMatrix:
LinearAlgebraRankCntrlMatrix
4
Determinant of CntrlMatrix:
LinearAlgebraDeterminantCntrlMatrix
−g2⁢l__1−l__22M4⁢l__14⁢l__24
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 l__1=l__2. 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:
poles≔−3, −52+2⋅I,−52−2⋅I,−7:
The state-feedback gain, Kc, is then:
Kc, Kr≔StateFeedbackPolePlacementsys,poles, 'return_Kr'
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
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
Length of pendulum 1 l__1
Length of pendulum 2 l__2
Gravity g
9.81
The state-feedback controller which was designed in the previous section assumed that the states x__1 and x__2 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) x__1 is measured and x__2 is not, (2) x__2 is measured and x__1 is not, and (3) x__1 and x__2 are measured.
3.1.1 - x__1 is measured and x__2 is not
We get a subsystem using DynamicSystems[Subsystem] command where only x__1 is measurable:
subsysx1≔DynamicSystemsSubsystemsys,all,1:
The observability matrix can be determined by using the DynamicSystems[ObservabilityMatrix] command.
ObsvMatrix__x__1≔DynamicSystemsObservabilityMatrixsubsysx1
Rank of ObsvMatrix__x__1:
LinearAlgebraRankObsvMatrix__x__1
Determinant of ObsvMatrix__x__1:
LinearAlgebraDeterminantObsvMatrix__x__1
−m2⁢g2M2⁢l__12
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.1.2 - x__2 is measured and x__1 is not
We get a subsystem using DynamicSystems[Subsystem] command where only x__2 is measurable:
subsysx2≔DynamicSystemsSubsystemsys,all,2:
ObsvMatrix__x__2≔DynamicSystemsObservabilityMatrixsubsysx2
Rank of ObsvMatrix__x__2:
LinearAlgebraRankObsvMatrix__x__2
Determinant of ObsvMatrix__x__2:
LinearAlgebraDeterminantObsvMatrix__x__2
−m2⁢g2M2⁢l__22
As in section 3.1.1, the system is observable for all parameter values. This means that the system is observable when either of the angles are measured.
3.1.3 - x__1 and x__2 are measured
If the both states are measurable, the observability matrix of the system is:
ObsvMatrix__x__12≔DynamicSystemsObservabilityMatrixsys
Rank of ObsvMatrix__x__12:
LinearAlgebraRankObsvMatrix__x__12
The observability matrix is full rank. Clearly, the system is observable when both angles are measured, as well.
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+2⁢I,−52−2⁢I,−7:
ObserverPoles≔−25,−27,−26+7⋅I,−26−7⋅I:
Using the ControlDesign[StateObserver][PolePlacement] and ControlDesign[StateFeedback][PolePlacement] commands the observer gain, `L__`, and state feedback gain, K__c, to stabilize the inverted pendulum configuration on top of the cart are:
L≔StateObserverPolePlacementsubsysx1,ObserverPoles
Kc, Kr≔StateFeedbackPolePlacementsubsysx1,StateFeedbackPoles, 'return_Kr'
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.
closedloop≔ControlDesignControllerObserversubsysx1,Kc,L, ':-Kr'=Kr, 'closedloop'=true, 'stateerror' =true:
eigcl≔LinearAlgebraEigenvaluesclosedloop:-a
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.
closedloop1≔DynamicSystemsStateSpaceclosedloop:-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
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.
τc≔0.2: params≔M=10, m=1, g=9.81,l__1=1.2,l__2=2:
W ≔ ControlDesignComputeQRsubsysx1, τc, 'parameters'=params;
Kclqr, Krlqr ≔ ControlDesignLQRsubsysx1, W:-Q, W:-R, 'parameters'=params, 'return_Kr';
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;
We get the LQG controller equations using the ControlDesign[ControllerObserver] command.
LQG ≔ ControlDesignControllerObserversubsysx1, Kclqr, Lkal, 'Kr' =Krlqr, 'parameters' =params:
PrintSystemLQG;
We get the closed-loop system using the ControlDesign[ControllerObserver] command with the 'closedloop' option
clsyslqg≔ControlDesignControllerObserversubsysx1,Kclqr,Lkal, ':-Kr'=Krlqr, 'parameters'=params, 'closedloop'=true, 'stateerror' =true: eigcl_lqg ≔LinearAlgebraEigenvaluesclsyslqg:-a;
clsyslqg1≔DynamicSystemsStateSpaceclsyslqg:-a, clsyslqg:-b,LinearAlgebra:-IdentityMatrixclsyslqg:-statecount, Matrixclsyslqg:-statecount,clsyslqg:-inputcount:
Investigating the Closed-Loop Response Simulation to LQG Control Design
Download Help Document