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



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 ${l}_{1}$ and ${l}_{2}$, respectively.

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

 System Parameters Mass of cart $\left(M\right)$ Mass of pendulums $\left(m\right)$ Length of pendulum 1 $\left({l}_{\mathit{1}}\right)$ Length of pendulum 2 $\left({l}_{\mathit{2}}\right)$ Angle of pendulum 1 from vertical $\left({\mathrm{θ}}_{1}\right)$ Angle of pendulum 2 from vertical $\left({\mathrm{θ}}_{2}\right)$ Forcing input $\left(u\left(t\right)\right)$ Velocity $\left(\mathrm{v}\left(\mathrm{t}\right)\right)$

For small $\left|{\mathrm{\theta }}_{1}\right|$ and $\left|{\mathrm{\theta }}_{2}\right|$, the equations of motion for this system are:

$M\stackrel{\mathbf{.}}{v}\left(t\right)=-mg{\mathrm{\theta }}_{1}-mg{\mathrm{\theta }}_{2}+u$

$m\left(\stackrel{\mathbf{.}}{v}\left(t\right)+{l}_{1}\stackrel{\mathbf{..}}{{\mathrm{\theta }}_{1}}\left(t\right)\right)=mg{\mathrm{\theta }}_{1}$

$m\left(\stackrel{\mathbf{.}}{v}\left(t\right)+{l}_{2}\stackrel{\mathbf{..}}{{\mathrm{\theta }}_{2}}\left(t\right)\right)=mg{\mathrm{\theta }}_{2}$

With some simple term re-writing and by letting ${x}_{1}={\mathrm{\theta }}_{1}$,  ${x}_{2}={\mathrm{\theta }}_{2}$, ${x}_{3}={\stackrel{.}{\mathrm{\theta }}}_{1}$, ${x}_{4}={\stackrel{.}{\mathrm{\theta }}}_{2}$ the equations of motion can be converted into state space form, that is $\stackrel{.}{x}=A\cdot x+B\cdot u$.

  

where:

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:



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

 $\left[\begin{array}{l}{\mathbf{State Space}}\\ {\mathrm{continuous}}\\ {\mathrm{2 output\left(s\right); 1 input\left(s\right); 4 state\left(s\right)}}\\ {\mathrm{inputvariable}}{=}\left[{\mathrm{u1}}{}\left({t}\right)\right]\\ {\mathrm{outputvariable}}{=}\left[{\mathrm{y1}}{}\left({t}\right){,}{\mathrm{y2}}{}\left({t}\right)\right]\\ {\mathrm{statevariable}}{=}\left[{\mathrm{x1}}{}\left({t}\right){,}{\mathrm{x2}}{}\left({t}\right){,}{\mathrm{x3}}{}\left({t}\right){,}{\mathrm{x4}}{}\left({t}\right)\right]\\ {\mathrm{a}}{=}\left[\begin{array}{cccc}{0}& {0}& {1}& {0}\\ {0}& {0}& {0}& {1}\\ \frac{\left({M}{+}{m}\right){}{g}}{{M}{}{{l}}_{{1}}}& \frac{{m}{}{g}}{{M}{}{{l}}_{{1}}}& {0}& {0}\\ \frac{{m}{}{g}}{{M}{}{{l}}_{{2}}}& \frac{\left({M}{+}{m}\right){}{g}}{{M}{}{{l}}_{{2}}}& {0}& {0}\end{array}\right]\\ {\mathrm{b}}{=}\left[\begin{array}{c}{0}\\ {0}\\ {-}\frac{{1}}{{M}{}{{l}}_{{1}}}\\ {-}\frac{{1}}{{M}{}{{l}}_{{2}}}\end{array}\right]\\ {\mathrm{c}}{=}\left[\begin{array}{cccc}{1}& {0}& {0}& {0}\\ {0}& {1}& {0}& {0}\end{array}\right]\\ {\mathrm{d}}{=}\left[\begin{array}{c}{0}\\ {0}\end{array}\right]\end{array}\right$ (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 ${\mathrm{\theta }}_{1}={\mathrm{\theta }}_{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.

$\mathrm{CntrlMatrix}≔\mathrm{ControllabilityMatrix}\left(\mathrm{sys}\right)$

 $\left[\begin{array}{cccc}{0}& {-}\frac{{1}}{{M}{}{{l}}_{{1}}}& {0}& {-}\frac{\left({M}{+}{m}\right){}{g}}{{{M}}^{{2}}{}{{{l}}_{{1}}}^{{2}}}{-}\frac{{m}{}{g}}{{{M}}^{{2}}{}{{l}}_{{1}}{}{{l}}_{{2}}}\\ {0}& {-}\frac{{1}}{{M}{}{{l}}_{{2}}}& {0}& {-}\frac{{m}{}{g}}{{{M}}^{{2}}{}{{l}}_{{1}}{}{{l}}_{{2}}}{-}\frac{\left({M}{+}{m}\right){}{g}}{{{M}}^{{2}}{}{{{l}}_{{2}}}^{{2}}}\\ {-}\frac{{1}}{{M}{}{{l}}_{{1}}}& {0}& {-}\frac{\left({M}{+}{m}\right){}{g}}{{{M}}^{{2}}{}{{{l}}_{{1}}}^{{2}}}{-}\frac{{m}{}{g}}{{{M}}^{{2}}{}{{l}}_{{1}}{}{{l}}_{{2}}}& {0}\\ {-}\frac{{1}}{{M}{}{{l}}_{{2}}}& {0}& {-}\frac{{m}{}{g}}{{{M}}^{{2}}{}{{l}}_{{1}}{}{{l}}_{{2}}}{-}\frac{\left({M}{+}{m}\right){}{g}}{{{M}}^{{2}}{}{{{l}}_{{2}}}^{{2}}}& {0}\end{array}\right]$ (2)

Rank of $\mathrm{CntrlMatrix}$:

$\mathrm{LinearAlgebra}\left[\mathrm{Rank}\right]\left(\mathrm{CntrlMatrix}\right)$

 ${4}$ (3)



Determinant of $\mathrm{CntrlMatrix}$:

$\mathrm{LinearAlgebra}\left[\mathrm{Determinant}\right]\left(\mathrm{CntrlMatrix}\right)$

 ${-}\frac{{{g}}^{{2}}{}{\left({{l}}_{{1}}{-}{{l}}_{{2}}\right)}^{{2}}}{{{M}}^{{4}}{}{{{l}}_{{1}}}^{{4}}{}{{{l}}_{{2}}}^{{4}}}$ (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 ${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:

The state-feedback gain, $\mathrm{Kc}$, is then:

 $\left[\begin{array}{cccc}\frac{{1}}{{4}}{}\frac{{4}{}{M}{}{{g}}^{{2}}{}{{l}}_{{2}}{+}{325}{}{M}{}{g}{}{{l}}_{{1}}{}{{l}}_{{2}}{+}{861}{}{M}{}{{{l}}_{{1}}}^{{2}}{}{{l}}_{{2}}{-}{4}{}{{g}}^{{2}}{}{{l}}_{{1}}{}{m}{+}{4}{}{{g}}^{{2}}{}{{l}}_{{2}}{}{m}}{{g}{}\left({{l}}_{{1}}{-}{{l}}_{{2}}\right)}& {-}\frac{{1}}{{4}}{}\frac{{4}{}{M}{}{{g}}^{{2}}{}{{l}}_{{1}}{+}{325}{}{M}{}{g}{}{{l}}_{{1}}{}{{l}}_{{2}}{+}{861}{}{M}{}{{l}}_{{1}}{}{{{l}}_{{2}}}^{{2}}{+}{4}{}{{g}}^{{2}}{}{{l}}_{{1}}{}{m}{-}{4}{}{{g}}^{{2}}{}{{l}}_{{2}}{}{m}}{{g}{}\left({{l}}_{{1}}{-}{{l}}_{{2}}\right)}& \frac{{5}}{{2}}{}\frac{\left({6}{}{g}{+}{83}{}{{l}}_{{1}}\right){}{{l}}_{{1}}{}{M}{}{{l}}_{{2}}}{{g}{}\left({{l}}_{{1}}{-}{{l}}_{{2}}\right)}& {-}\frac{{5}}{{2}}{}\frac{\left({6}{}{g}{+}{83}{}{{l}}_{{2}}\right){}{{l}}_{{1}}{}{M}{}{{l}}_{{2}}}{{g}{}\left({{l}}_{{1}}{-}{{l}}_{{2}}\right)}\end{array}\right]{,}\left[\begin{array}{cc}\frac{{861}}{{8}}{}\frac{{M}{}{{l}}_{{1}}{}{{l}}_{{2}}}{{g}}& \frac{{861}}{{8}}{}\frac{{M}{}{{l}}_{{1}}{}{{l}}_{{2}}}{{g}}\end{array}\right]$ (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.

$\mathrm{LinearAlgebra}\left[\mathrm{Eigenvalues}\right]\left(\mathrm{clsys}:-a\right)$

 $\left[\begin{array}{c}{-}{3}\\ {-}{7}\\ {-}\frac{{5}}{{2}}{-}{2}{}{I}\\ {-}\frac{{5}}{{2}}{+}{2}{}{I}\end{array}\right]$ (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 $\left(M\right)$ Mass of pendulums $\left(m\right)$  Length of pendulum 1 $\left({l}_{1}\right)$  Length of pendulum 2 $\left({l}_{2}\right)$  Gravity $\left(g\right)$ $9.81$   



3. Observer-Based Control Design

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:

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

${\mathrm{ObsvMatrix}}_{{x}_{1}}≔\mathrm{DynamicSystems}\left[\mathrm{ObservabilityMatrix}\right]\left({\mathrm{subsys}}_{{x}_{1}}\right)$

 $\left[\begin{array}{cccc}{1}& {0}& {0}& {0}\\ {0}& {0}& {1}& {0}\\ \frac{\left({M}{+}{m}\right){}{g}}{{M}{}{{l}}_{{1}}}& \frac{{m}{}{g}}{{M}{}{{l}}_{{1}}}& {0}& {0}\\ {0}& {0}& \frac{\left({M}{+}{m}\right){}{g}}{{M}{}{{l}}_{{1}}}& \frac{{m}{}{g}}{{M}{}{{l}}_{{1}}}\end{array}\right]$ (7)

Rank of ${\mathrm{ObsvMatrix}}_{{x}_{1}}$:

$\mathrm{LinearAlgebra}\left[\mathrm{Rank}\right]\left({\mathrm{ObsvMatrix}}_{{x}_{1}}\right)$

 ${4}$ (8)

Determinant of ${\mathrm{ObsvMatrix}}_{{x}_{1}}$:

$\mathrm{LinearAlgebra}\left[\mathrm{Determinant}\right]\left({\mathrm{ObsvMatrix}}_{{x}_{1}}\right)$

 ${-}\frac{{{m}}^{{2}}{}{{g}}^{{2}}}{{{M}}^{{2}}{}{{{l}}_{{1}}}^{{2}}}$ (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.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:

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

${\mathrm{ObsvMatrix}}_{{x}_{2}}≔\mathrm{DynamicSystems}\left[\mathrm{ObservabilityMatrix}\right]\left({\mathrm{subsys}}_{{x}_{2}}\right)$

 $\left[\begin{array}{cccc}{0}& {1}& {0}& {0}\\ {0}& {0}& {0}& {1}\\ \frac{{m}{}{g}}{{M}{}{{l}}_{{2}}}& \frac{\left({M}{+}{m}\right){}{g}}{{M}{}{{l}}_{{2}}}& {0}& {0}\\ {0}& {0}& \frac{{m}{}{g}}{{M}{}{{l}}_{{2}}}& \frac{\left({M}{+}{m}\right){}{g}}{{M}{}{{l}}_{{2}}}\end{array}\right]$ (10)

Rank of ${\mathrm{ObsvMatrix}}_{{x}_{2}}$:

$\mathrm{LinearAlgebra}\left[\mathrm{Rank}\right]\left({\mathrm{ObsvMatrix}}_{{x}_{2}}\right)$

 ${4}$ (11)

Determinant of ${\mathrm{ObsvMatrix}}_{{x}_{2}}$:

$\mathrm{LinearAlgebra}\left[\mathrm{Determinant}\right]\left({\mathrm{ObsvMatrix}}_{{x}_{2}}\right)$

 ${-}\frac{{{m}}^{{2}}{}{{g}}^{{2}}}{{{M}}^{{2}}{}{{{l}}_{{2}}}^{{2}}}$ (12)

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:

${\mathrm{ObsvMatrix}}_{{x}_{\mathrm{12}}}≔\mathrm{DynamicSystems}\left[\mathrm{ObservabilityMatrix}\right]\left(\mathrm{sys}\right)$

 $\left[\begin{array}{cccc}{1}& {0}& {0}& {0}\\ {0}& {1}& {0}& {0}\\ {0}& {0}& {1}& {0}\\ {0}& {0}& {0}& {1}\\ \frac{\left({M}{+}{m}\right){}{g}}{{M}{}{{l}}_{{1}}}& \frac{{m}{}{g}}{{M}{}{{l}}_{{1}}}& {0}& {0}\\ \frac{{m}{}{g}}{{M}{}{{l}}_{{2}}}& \frac{\left({M}{+}{m}\right){}{g}}{{M}{}{{l}}_{{2}}}& {0}& {0}\\ {0}& {0}& \frac{\left({M}{+}{m}\right){}{g}}{{M}{}{{l}}_{{1}}}& \frac{{m}{}{g}}{{M}{}{{l}}_{{1}}}\\ {0}& {0}& \frac{{m}{}{g}}{{M}{}{{l}}_{{2}}}& \frac{\left({M}{+}{m}\right){}{g}}{{M}{}{{l}}_{{2}}}\end{array}\right]$ (13)

Rank of ${\mathrm{ObsvMatrix}}_{{x}_{\mathrm{12}}}$:

$\mathrm{LinearAlgebra}\left[\mathrm{Rank}\right]\left({\mathrm{ObsvMatrix}}_{{x}_{\mathrm{12}}}\right)$

 ${4}$ (14)

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 ${x}_{1}$, 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 $\mathrm{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.



$\mathrm{StateFeedbackPoles}≔\left[-3,-\frac{5}{2}+2I,-\frac{5}{2}-2I,-7\right]:$

$\mathrm{ObserverPoles}≔\left[-25,-27,-26+7\cdot \mathrm{I},-26-7\cdot \mathrm{I}\right]:$



Using the ControlDesign[StateObserver][PolePlacement] and ControlDesign[StateFeedback][PolePlacement] commands the observer gain, $\mathrm{L__}$,  and state feedback gain, ${K}_{c}$, to stabilize the inverted pendulum configuration on top of the cart are:

$L\mathit{≔}\mathrm{StateObserver}\left[\mathrm{PolePlacement}\right]\left({\mathrm{subsys}}_{{x}_{1}},\mathrm{ObserverPoles}\right)$

 $\left[\begin{array}{c}{104}\\ \frac{{104}{}\left({M}{}{g}{+}{700}{}{M}{}{{l}}_{{2}}{+}{g}{}{m}\right){}{{l}}_{{1}}}{{{l}}_{{2}}{}{m}{}{g}}\\ \frac{{M}{}{g}{}{{l}}_{{1}}{+}{M}{}{g}{}{{l}}_{{2}}{+}{4104}{}{M}{}{{l}}_{{1}}{}{{l}}_{{2}}{+}{g}{}{{l}}_{{1}}{}{m}{+}{g}{}{{l}}_{{2}}{}{m}}{{M}{}{{l}}_{{1}}{}{{l}}_{{2}}}\\ \frac{{{M}}^{{2}}{}{{g}}^{{2}}{}{{l}}_{{1}}{+}{4104}{}{{M}}^{{2}}{}{g}{}{{l}}_{{1}}{}{{l}}_{{2}}{+}{489375}{}{{M}}^{{2}}{}{{l}}_{{1}}{}{{{l}}_{{2}}}^{{2}}{+}{2}{}{M}{}{{g}}^{{2}}{}{{l}}_{{1}}{}{m}{+}{4104}{}{M}{}{g}{}{{l}}_{{1}}{}{{l}}_{{2}}{}{m}{+}{{g}}^{{2}}{}{{l}}_{{1}}{}{{m}}^{{2}}{+}{{g}}^{{2}}{}{{l}}_{{2}}{}{{m}}^{{2}}}{{M}{}{{{l}}_{{2}}}^{{2}}{}{m}{}{g}}\end{array}\right]$ (15)



 $\left[\begin{array}{cccc}\frac{{1}}{{4}}{}\frac{{4}{}{M}{}{{g}}^{{2}}{}{{l}}_{{2}}{+}{325}{}{M}{}{g}{}{{l}}_{{1}}{}{{l}}_{{2}}{+}{861}{}{M}{}{{{l}}_{{1}}}^{{2}}{}{{l}}_{{2}}{-}{4}{}{{g}}^{{2}}{}{{l}}_{{1}}{}{m}{+}{4}{}{{g}}^{{2}}{}{{l}}_{{2}}{}{m}}{{g}{}\left({{l}}_{{1}}{-}{{l}}_{{2}}\right)}& {-}\frac{{1}}{{4}}{}\frac{{4}{}{M}{}{{g}}^{{2}}{}{{l}}_{{1}}{+}{325}{}{M}{}{g}{}{{l}}_{{1}}{}{{l}}_{{2}}{+}{861}{}{M}{}{{l}}_{{1}}{}{{{l}}_{{2}}}^{{2}}{+}{4}{}{{g}}^{{2}}{}{{l}}_{{1}}{}{m}{-}{4}{}{{g}}^{{2}}{}{{l}}_{{2}}{}{m}}{{g}{}\left({{l}}_{{1}}{-}{{l}}_{{2}}\right)}& \frac{{5}}{{2}}{}\frac{\left({6}{}{g}{+}{83}{}{{l}}_{{1}}\right){}{{l}}_{{1}}{}{M}{}{{l}}_{{2}}}{{g}{}\left({{l}}_{{1}}{-}{{l}}_{{2}}\right)}& {-}\frac{{5}}{{2}}{}\frac{\left({6}{}{g}{+}{83}{}{{l}}_{{2}}\right){}{{l}}_{{1}}{}{M}{}{{l}}_{{2}}}{{g}{}\left({{l}}_{{1}}{-}{{l}}_{{2}}\right)}\end{array}\right]{,}\left[\begin{array}{c}\frac{{861}}{{4}}{}\frac{{M}{}{{l}}_{{1}}{}{{l}}_{{2}}}{{g}}\end{array}\right]$ (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.

$\mathrm{eigcl}\mathit{≔}\mathrm{LinearAlgebra}\left[\mathrm{Eigenvalues}\right]\left(\mathrm{closedloop}:-a\right)$

 $\left[\begin{array}{c}{-}{27}\\ {-}{25}\\ {-}{7}\\ {-}{3}\\ {-}\frac{{5}}{{2}}{-}{2}{}{I}\\ {-}\frac{{5}}{{2}}{+}{2}{}{I}\\ {-}{26}{-}{7}{}{I}\\ {-}{26}{+}{7}{}{I}\end{array}\right]$ (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.

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 $\left(M\right)$ Mass of pendulums $\left(m\right)$  Length of pendulum 1 $\left({l}_{1}\right)$  Length of pendulum 2 $\left({l}_{2}\right)$  Gravity $\left(g\right)$ $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.

 ${\mathrm{Record}}{}\left({Q}{=}\left[\begin{array}{cccc}{1.}& {0.}& {0.}& {0.}\\ {0.}& {0.}& {0.}& {0.}\\ {0.}& {0.}& {0.}& {0.}\\ {0.}& {0.}& {0.}& {0.}\end{array}\right]{,}{R}{=}\left[\begin{array}{c}{0.00000399497633449469}\end{array}\right]\right)$ (18)

 $\left[\begin{array}{cccc}{-}{3816.40429094901}& {4212.66130610579}& {-}{1319.79747708763}& {1906.54047265615}\end{array}\right]{,}\left[\begin{array}{c}{513.977015364205}\end{array}\right]$ (19)

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

 $\left[\begin{array}{c}{101.762427903741}\\ {90975.7041961815}\\ {3428.23110108542}\\ {5.93529526437802}{}{{10}}^{{5}}\end{array}\right]$ (20)

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

$\mathrm{PrintSystem}\left(\mathrm{LQG}\right);$

 $\left[\begin{array}{l}{\mathbf{State Space}}\\ {\mathrm{continuous}}\\ {\mathrm{1 output\left(s\right); 2 input\left(s\right); 4 state\left(s\right)}}\\ {\mathrm{inputvariable}}{=}\left[{\mathrm{y1_ref}}{}\left({t}\right){,}{\mathrm{y1_meas}}{}\left({t}\right)\right]\\ {\mathrm{outputvariable}}{=}\left[{\mathrm{u1}}{}\left({t}\right)\right]\\ {\mathrm{statevariable}}{=}\left[{\mathrm{x1_est}}{}\left({t}\right){,}{\mathrm{x2_est}}{}\left({t}\right){,}{\mathrm{x3_est}}{}\left({t}\right){,}{\mathrm{x4_est}}{}\left({t}\right)\right]\\ {\mathrm{a}}{=}\left[\begin{array}{cccc}{-}{101.762427903741}& {0.0}& {1.0}& {0.0}\\ {-}{90975.70419618153}& {0.0}& {0.0}& {1.0}\\ {-}{3737.2722919851153}& {351.87260882810705}& {-}{109.98312308623666}& {158.87837271499058}\\ {-}{5.937198561523493}{}{{10}}^{{5}}& {216.0285653052896}& {-}{65.9898738543816}& {95.32702363280744}\end{array}\right]\\ {\mathrm{b}}{=}\left[\begin{array}{cc}{0.0}& {101.762427903741}\\ {0.0}& {90975.70419618153}\\ {-}{42.83141794530387}& {3428.2311010854196}\\ {-}{25.698850768210278}& {5.935295264378018}{}{{10}}^{{5}}\end{array}\right]\\ {\mathrm{c}}{=}\left[\begin{array}{cccc}{3816.4042909490054}& {-}{4212.6613061057915}& {1319.797477087632}& {-}{1906.5404726561487}\end{array}\right]\\ {\mathrm{d}}{=}\left[\begin{array}{cc}{513.977015364205499}& {0}\end{array}\right]\end{array}\right$ (21)

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

 $\left[\begin{array}{c}{-}{5.11237012925113}{+}{4.08135896037352}{}{I}\\ {-}{5.11237012925113}{-}{4.08135896037352}{}{I}\\ {-}{2.21567959746349}{+}{0.00857051051146585}{}{I}\\ {-}{2.21567959746349}{-}{0.00857051051146585}{}{I}\\ {-}{65.0232928426605}{+}{0.}{}{I}\\ {-}{13.7032477007070}{+}{24.1120223072031}{}{I}\\ {-}{13.7032477007070}{-}{24.1120223072031}{}{I}\\ {-}{9.33263965978372}{+}{0.}{}{I}\end{array}\right]$ (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.

 Investigating the Closed-Loop Response Simulation to LQG Control Design Parameters Value Mass of cart $\left(M\right)$ Mass of pendulums $\left(m\right)$  Length of pendulum 1 $\left({l}_{1}\right)$  Length of pendulum 2 $\left({l}_{2}\right)$  Gravity $\left(g\right)$ $9.81$