Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

ENGN8224

Advanced Control Systems

Computer Lab 2: Linear Quadratic Regulator (LQR) Implementation

The aims of this session are:

1. To understand the implementation of the linear quadratic regulator in MATLAB.

1    Experiment: LQR Control

Recall the model of the plant for an inverted pendulum on a cart:

Newton’s law gives the following equation of motion  (assuming the floor is frictionless):

F + ml sin θ θ˙2 ml cos θ θ¨

M + m

l

(1a)

(1b)

where x is the cart’s position  (m), θ  is the pendulum angle  (rad), F  is the input force  (N), m = 0.2 kg is the mass of the pendulum, M = 5 kg is the mass of the cart (kg), g = 9.8 m/s2  is

the acceleration of gravity, and l = 0.2 m is the length of the rod.

By assuming θ and θ˙ are small, equations (1) can be linearized and obtain

mgθ       F

M        M

 

l       Ml      Ml .

Then by taking the variables as

lx1      lx

x =           =         ,        u = F,        y = θ,

x3                 θ

x˙ = Ax + Bu;       y = Cx

can be obtained. Here the matrices A, B, and C are

l0   1        0        0                     l   0  

A =         1(0)   ;        B =            ;        C =  [0   0   1   0] .

0   0      0                  

Now, we want the cart to move from 0m to 5m. By implementing the LQR controller, simulate the situation by the following:

1. Start New Script” in MATLAB and define your constants and matrices.

 

Figure 1: Example on how to define your constants and matrices.

2. Check if the system is controllable and observable.

 

Figure 2: Example on how to check controllability.

 

Figure 3: Example on how to check observability.

3. Choose the appropriate Q and R to calculate K . An explanation for  will be given below.

 

Figure 4: Example on how to calculate K .

4. Simulate the calculated K using Simulink.

 

Figure 5: Example on the Simulink Block Diagram.

 

Figure 6: Graph of Position of the cart.

From Figure (6), we can clearly observe that this is not the expected result we wanted. An easy way to do is we could use a gain called  to fix this.  can also eliminate steady-state error at some point. The following figure is the function code to find  . Save this as rscale in the same folder you save your codes.

 

Figure 7: Code for finding  .

5. Now, include  into your Simulink

 

Figure 8: Example on the Simulink Block Diagram with  .

and a result such as the figure below should be observed.

 

Figure 9: Graph of Position of the cart.

2    Computer Lab Tasks

1. Reproduce the results in Figure (6) and Figure (9).

2. Now consider the MIMO version of equations (1) where an additional input and output will

be considered

τ =  ml cos θ + ml2  θ¨ − mgl sin θ

F =  (M + m) + ml cos θ θ¨ − ml sin θ θ˙2 .

(3a)

(3b)

All the variables constant will be as stated above.

(a) Linearize equations (3). Show your answers.

(b) Consider that you want your cart to move from  1m to  10m while maintaining the

pendulum straight up (π) from rest (π/2). Use LQR control and implement the situation in Simulink. Clearly show your codes (in one script file) and block diagram along with proper details in your blocks. Also, plot the position (x) and angle (θ) graph.

(c) In the same script file:

i. show that is the system controllable? observable?

ii. show and comment on the open-loop and closed-loop poles.