Discrete-time Controller Design: Cart-Pendulum System
Lab 09 – EGH445 Modern Control – 2020
Electrical Engineering & Robotics (EER) Queensland University of Technology
September 24, 2020
Important: Demonstration 2
Demonstration 2 requires you to build and demonstrate a complete and working control system for a discrete time cart-pendulum model in MATLAB/Simulink. Your demonstrations will be assessed individually and conducted during your usual computer lab session.
Preparation: You are required to create the system outlined in Section 1 and Section 2 of this computer lab. Read the lab carefully and follow the instructions to complete the control system design.
Demonstration: You will be required to run two scripts and execute two functions created from this lab. These scripts and functions are listed below and should be used to automatically produce Figures 4 and 5 from this lab.
CP_DTSFC_Lin_a_MainFile_yourstudentnumber.m CP_DTSFC_Lin_b_MainFile_yourstudentnumber.m matexp(A,T,n)
intmatexpB(A,B,T,n)
You will then be asked a few questions (orally) of increasing complexity to assess your understanding of the scripts, Simulink models and the concepts used in control system design.
Marking: The marks for the demonstration are allocated as follows: 50% for the scripts, models and functions (correct expressions in fcn blocks and connections in Simulink model), and 50% for the questions.
Hint: For more guidance, see Computer Labs 4 – 8. Consider attempting Lab 9 (this lab) before your in class session so you can use your lab session to refine your scripts and simulation models with help from the teaching team.
1
Ob jectives
The objective of this Lab is to design and simulate a state-feedback controller for the cart-pendulum system in the discrete-time domain using Matlab and Simulink.
1 Inverted pendulum on a cart
The cart-pendulum system is a benchmark that has been widely used to study control system designs. Figure 1 shows the idealised model of the system that consists of a pendulum of mass m and length l attached to a cart of mass Mc. The cart moves on the horizontal direction and is actuated by the input force F. The equations of motion of the system are as follows
(M+m)q ̈+mlcos(q)q ̈−mlsin(q)q ̇2 = F, (1) c12222
ml cos(q )q ̈ +ml2 q ̈ −mgl sin(q ) = 0, (2) 2122
where q1 and q2 are the position of the cart and the angle of the pendulum respectively, and g is the gravitational constant. The state-space model can be written as follows
x3 x4
x ̇ 1
x ̇ 2 =
x24 lm sin(x2 )−gm sin(x2 ) cos(x2 )+F , (3) Mc+m−mcos2(x2)
−lm sin(x2 ) cos(x2 )x24 +g(Mc +m) sin(x2 )−cos(x2 )F l[Mc +m−m cos2 (x2 )]
x ̇3
x ̇ 4
where x1 = q1, x2 = q2, x3 = q ̇1 and x4 = q ̇2 are the states. We consider the values of the model parameters given in Table 1.
Table 1: Model parameters.
Parameter
value
m Mc l g
0.15kg 0.4kg 0.2m 9.81m/s2
Figure 1: Cart-pendulum system.
2
1.1 Linearised models.
We consider the following equilibrium points of the system (1)-(2):
x ̄ 1 a 0 x ̄a = x ̄2a = 0 ,
x ̄ 3 a 0 x ̄4a 0
where x ̄a and x ̄b correspond to the pendulum in the upright and down positions respectively, with the cart at the origin of the coordinate frame.
The linearised model of the cart-pendulum about x ̄a is
x ̃ ̇a =Aax ̃a +BaF, (5)
where
y = Cax ̃a + DaF, (6) 0 0 10 0
0 0 01 0
Aa =0 −mg 0 0; Ba = 1 ; Ca =I4; Da =04×1. Mc Mc
0 g(Mc+m) 0 0 − 1
where
x ̃ ̇b =Abx ̃b +BbF, (7) y = Cbx ̃b + DbF, (8)
0 0 10 0
0 0 01 0
Ab =0 −mg 0 0; Bb = 1 ; Cb =I4; Db =04×1.
x ̄ 1 b 0
x ̄b = x ̄2b = π, (4)
x ̄ 3 b 0 x ̄4b 0
lMc
The linearised model of the cart-pendulum about x ̄b is
lMc
Mc
0 −g(Mc+m) 0 0
lMc
Mc 1 lMc
2 Discrete-time linear models and state-feedback control
The tasks in this section are:
Formulate the discrete-time state-space linear models from the continuous-time models for both equilib- rium points x ̄a and x ̄b. The general form of a discrete-time state-space linear model is
x(kT + T) = Gx(kT) + Hu(kT), (9) y(kT ) = Cx(kT ) + Du(kT ). (10)
Design a controller u(kT) = −Kdx(kT) such that the eigenvalues of the characteristic polynomial of closed-loop dynamics
x(kT + T) = (G − H Kd)x(kT), (11) y(kT) = Cx(kT) + Du(kT) (12)
are placed in a desired location.
Discrete-time control system about x ̄a.
Create the script CP_DTSFC_Lin_a_MainFile_yourstudentnumber.m that computes a discrete-time state-space
linear model about x ̄a and the controller gain Kd =K_da as follows
a) Define all the values of the model parameters for the linearised model (5)-(6).
b) Compute the matrices Aa, Ba, Ca and Da.
c) Use the command ss to create a continuous-time state-space model. Name the model as sysc.
d) Use the command c2d to create a discrete-time model from sysc. Use sample time T_s=0.03 seconds and zoh method. Name the model as sysdzoh.
2.1
3
e) Consider the desired eigenvalues of the continuous-time closed-loop system λ1 = −3, λ2 = −4, λ3 = −5 and λ4 = −6. Map these eigenvalues to the discrete-time domain.
f) Compute the gain of the controller Kd =K_da such that the eigenvalues of (G − H Kd) are placed at the desired location in the discrete-time domain.
g) Simulate the discrete-time closed loop and the sampled-data continuous-time closed loop:
i) Create a Simulink model of the discrete-time system in closed loop with the state-feedback controller u(kT ) = −K_da x(kT ). An example of the Simulink model is shown in Figure 2. Hints: use the block Discrete State-Space, set sample time to T_s for the blocks that require sample time, use the dis- crete solver and set fixed-step size to T_s. Save your model as CP_DTSFC_Lin_a_yourstudentnumber.slx
ii) Create a Simulink model of the sampled-data continuous-time system in closed loop with the state- feedback controller and select the control gain K_a=K_da. An example of the Simulink model is shown in Figure 3. This Simulink model attempts to emulate the behaviour of the continuous-time plant in closed loop with the discrete-time controller. Hints: use the blocks Rate Transition, set the sample time to T_s if needed, set the initial conditions of the blocks that require ini- tial conditions, use fixed-step solver ode4 and select 0.001 as step time. Save your model as CP_SD_SFC_Lin_a_yourstudentnumber.slx.
iii) Export the states, the control input and the simulation time from Simulink to Matlab.
iv) Simulate both the discrete-time closed-loop system and the sampled-data closed-loop system. Use
the initial condition x(0) = 0.2 20π/180 0 0⊤.
h) Plot the results of the simulations in a figure that shows the time histories of the position of the cart, the angle of the pendulum, the velocity of the cart, the angular velocity of the pendulum and the control force for both the discrete-time control system and the sampled-data control system. Use the command stem to plot the results of the discrete-time control system, and the command plot for the sampled-data control system. An example of the simulation results is shown in Figure 4.
In addition, run the script CP_DTSFC_Lin_a_MainFile_yourstudentnumber.m but select T_s=0.05. Compare the results and analyse the response.
4
Figure 2: Discrete-time control system.
Rate Transition!
Figure 3: Sampled-data continuous-time control system.
5
2.2 Discrete-time control system about x ̄b.
Similar to the tasks in Section 2.1, create the script CP_DTSFC_Lin_b_MainFile_yourstudentnumber.m that computes a discrete-time state-space linear model about x ̄b and the controller gain Kd =K_db. Follow the same steps as in section 2.1, but name the Simulink models: CP_DTSFC_Lin_b_yourstudentnumber.slx and CP_SD_SFC_Lin_b_yourstudentnumber.slx. An example of the simulation results is shown in Figure 5.
2.3 Discrete-time models using approximation of the matrix exponential.
The task in this section is to create two functions to compute the matrices G and H of the discrete-time model (9) given the matrices A and B of a linear model. The matrices G and H are defined as
G = eAT, (13) T
eAλdλB. (14)
eAT =I+AT+1A2T2+1A3T3+1A4T4+···, 2! 3! 4!
to create the following functions:
a) matexp(A,T,n): Compute the matrix exponential eA T using an approximation of order n.
b) intmatexpB(A,B,T,n): Compute T eA λdλ B using an approximation of order n for the matrix exponen-
H = Use the approximation of the matrix exponential
0
tial eA T .
0
Compute the matrices G and H for the linearised models of the cart-pendulum about the equilibrium x ̄a and x ̄b using the functions matexp(A,T,n) and intmatexpB(A,B,T,n) with n=4. Compare the results with the matrices obtained using the command c2d.
6
0.5
0
20 0 -20
1.5 1 0.5 0 -0.5
100 0 -100 -200 -300
10 5 0 -5
Design Using Linearisation About EPa
0 0.5 1 1.5 Time [s]
x1 Discrete-time model
x1 sampled-data model
2 2.5 3
x2 Discrete-time model
x2 sampled-data model
2 2.5 3
x3 Discrete-time model
x3 sampled-data model
2 2.5 3
x4 Discrete-time model
x4 sampled-data model
2 2.5 3
F Discrete-time model
F sampled-data model
2 2.5 3
0 0.5 1 1.5 Time [s]
0 0.5 1 1.5 Time [s]
0 0.5 1 1.5 Time [s]
0 0.5 1 1.5 Time [s]
Control Force [N]
Pendulum rate [deg/s]
Cart velocity [m/s]
Pendulum angle [deg] Cart position [m]
Figure 4: Time histories of the states and input.
7
0.2 0.1 0
20 10 0 -10
0.2 0 -0.2 -0.4
100 0 -100 -200
2
0 -2
0 0.5 1 1.5 Time [s]
0 0.5 1 1.5 Time [s]
0 0.5 1 1.5 Time [s]
x1 Discrete-time model
x1 sampled-data model
2 2.5 3
x2 Discrete-time model
x2 sampled-data model
2 2.5 3
x3 Discrete-time model
x3 sampled-data model
2 2.5 3
x4 Discrete-time model
x4 sampled-data model
2 2.5 3
F Discrete-time model
F sampled-data model
2 2.5 3
0 0.5 1 1.5 Time [s]
0 0.5 1 1.5 Time [s]
Design Using Linearisation About EPb
Control Force [N]
Pendulum rate [deg/s]
Cart velocity [m/s]
Pendulum angle [deg] Cart position [m]
Figure 5: Time histories of the states and input.
8