Lab 5 - State Feedback Control
Lab 5 - State Feedback Control
LAB 5
I. LABORATORY OBJECTIVES
Mass – spring system consists of two carts and two springs connected with each
other. In this lab, students will develop state equations describing the mass – spring
system. Then students will design a state feedback controller to control the position of
cart 1 or cart 2 to reach the setpoint.
From the data collected from time response, students will find parameters of the
mass-spring system such as: spring constant, friction coefficient. After finding these
parameters, students will develop the state equations to describe mass-spring system.
In addition, the lab also helps students understand the effect of the feedback
controller on the quality of the control system.
Objectives after completing this lab:
Know how to construct and simulate control system to control spring-mass system
using state feedback controller.
Know how to collect data and identify spring-mass system model.
Analyze the performance of control system using state feedback controller.
1/14
Department of Control Engineering & Automation – FEEE – HCMUT
y = 0 0 1 0 x : if we control x2 variable
2.2. Identify parameters of the spring-mass system through experiment
In this section, we develop formulas to calculate unknown parameters of the
spring-mass system: spring constant k1, k2; friction coefficient b1, b2; gain coefficient
K.
2.2.1. Develop formula to calculate k1, b1
Let T be the signal sampling period, the first derivative and the second
derivative of x(t ) at time kT are calculated as follows:
1
x(kT ) = x(kT ) − x(kT − T ) (4)
T
1
(4) can be abbreviated to: x(k ) = x(k ) − x(k − 1)
T
1
x(kT ) = x(kT + T ) − 2 x(kT ) + x(kT − T ) (5)
T2
1
(5) can be abbreviated to: x(k ) = x(k + 1) − 2 x(k ) + x(k − 1)
T2
Assuming the constants of the two springs are the same and have value
k1 = k2 = k12 , the first equation of (1) is rewritten:
k12T 2 2 x1 (k ) − x2 (k ) + b1T x1 (k ) − x1 (k − 1) =
(6)
−m1 x1 (k + 1) − 2 x1 (k ) + x1 (k − 1)
If the mass m1 is known, equation (6) has 2 variables that need to be solved: k12
and b1 . At each sampling time, we will have one equation (6), collecting N data
samples we have (N - 2) equations as follows:
2/14
Department of Control Engineering & Automation – FEEE – HCMUT
. = (7)
where
T 2 2 x1 (2) − x2 (2) T x1 (2) − x1 (1)
T 2 2 x1 (3) − x2 (3) T x1 (3) − x1 (2)
=
... ...
T 2 x1 ( N − 1) − x2 ( N − 1) T x1 ( N − 1) − x1 ( N − 2)
2
−m1 x1 (3) − 2 x1 (2) + x1 (1)
k12 −m1 x1 (4) − 2 x1 (3) + x1 (2)
= , =
1
b ...
−m1 x1 ( N ) − 2 x1 ( N − 1) + x1 ( N − 2)
( )
−1
= T T (8)
If the mass m2 is known and the spring constant k12 is found in (8), equation
(9) has 2 variables that need to be solved: K and b2 . At each sampling time, we will
have one equation (9), collecting N data samples we have (N - 2) equations as follows:
. = (10)
where
T 2 u(2) −T x2 (2) − x2 (1)
=
T 2
u (3) −T x2 (3) − x2 (2) K
=
,
... ...
b2
T 2 u( N − 1) −T x2 ( N − 1) − x2 ( N − 2)
( )
−1
= T T (11)
(
x = A − BK f x + Bu ) (13)
y = Cx
where:
0 1 0 0
−( k + k ) 0
x1 1 2 −b1 k2 0
x 0
m1 m1 m2
x = 1, A= , B = 0 (14)
x2 0 0 0 1
K
x2 k2 − k2 −b2
0 m2
m2 m2 m2
C = 1 0 0 0 if we control x1 variable
C = 0 0 1 0 if we control x2 variable
4/14
Department of Control Engineering & Automation – FEEE – HCMUT
3.2. Software
The software used in this lab is MATLAB/Simulink/Real-time Windows
Target. Real-time Windows Target tool allows Simulink to connect to external
hardware and run in real time. In order to compile and run Simulink model connected
with the external hardware, student must perform the following steps:
• Create or open a Simulink model as in Figure 4.
5/14
Department of Control Engineering & Automation – FEEE – HCMUT
6/14
Department of Control Engineering & Automation – FEEE – HCMUT
IV. PREREQUISITES
4.1. Construct spring-mass system model
To successfully carry out this laboratory, students need to read the theoretical
basis section carefully and perform simulations on the computer.
Create Simulink diagram to analyze output response of the spring-mass system
as shown in Figure 6. “Mass-Spring Damper” containing spring-mass system model is
constructed from differential equations (1) and is described in Figure 7 with given
parameters:
Parameter m1 m2 k1 k2 b1 b2
Value 1.3 0.7 1000 1000 10 5
8/14
Department of Control Engineering & Automation – FEEE – HCMUT
variables x = x1 x2 .
T
x1 x2
1 0 0 0.1 0
9/14
Department of Control Engineering & Automation – FEEE – HCMUT
2 0 0 1 0
3 0 0 10 0
4 0 0 10 0.1
5 0 0 10 0.3
6 0 0 10 0.5
V. IN-LAB PROCEDURE
5.1. Find parameters of the spring-mass system
In this section, students will collect input and output data of the system and
apply formulas in Section 2.2 to calculate unknown parameters of spring-mass system:
spring constant k1, k2 of the springs; friction coefficients b1, b2; and gain coefficient K.
5.1.1. Determine k1, b1
Experimental steps:
a) Open recti_ident.m file and run the file to initialize stop-time and step-size
parameters. Students doesn’t need to reconfigure the parameters in Simulink-
Configuration.
Note: When running this file for the first time, the program will generate error
but still initialize the parameters normally.
a) Compile and run recti_response.mdl file to collect data (see instructions in
Section 3.2).
c) Rerun recti_ident.m file to find k1, b1.
d) Repeat step b) and step c) 5 times and write the results in Table 3, then
calculate average values of parameters k1, b1.
Table 3. k1 , b1 values
10/14
Department of Control Engineering & Automation – FEEE – HCMUT
5.1.2. Determine K, b2
Experimental steps:
a) Open recti_ident.m file and write the program to calculate K, b2 according to
(9) - (11).
Note: Students refer to the program calculating k1 , b1 based on (6) - (8) and
add code to calculate K, b2 as follows:
% Find parameters of the system:
% Constant of the spring k: k1_hat
% Friction coefficient of m1: b1_hat
a1 = T*T*(2*x1(2:N-1) - x2(2:N-1));
a2 = T*(x1(2:N-1) - x1(1:N-2));
PHI = [a1 a2];
lamda = (2*x1(2:N-1) - x1(1:N-2) - x1(3:N))*m1;
theta = inv(PHI'*PHI)*PHI'*lamda;
k1_hat = theta(1)
b1_hat = theta(2)
theta = inv(PHI'*PHI)*PHI'*lamda;
K_hat = theta(1)
b2_hat = theta(2)
Time K b2 (N.s/m)
1
2
3
4
5
Average
11/14
Department of Control Engineering & Automation – FEEE – HCMUT
Table 5. K f values
Steady-state
Time Kf POT Settling time
error
1 0 0 0.1 0
2 0 0 0.5 0
3 0 0 1 0
4 0 0 5 0
5 0 0 10 0
6 0 0 10 0.02
7 0 0 10 0.05
8 0 0 10 0.1
9 0 0 10 0.2
12/14
Department of Control Engineering & Automation – FEEE – HCMUT
Table 6. K f values
1 0.2 0 0 0
2 0.5 0 0 0
3 1 0 0 0
4 1.5 0 0 0
5 2 0 0 0
6 1 0.001 0 0
7 1 0.002 0 0
8 1 0.005 0 0
9 1 0.008 0 0
10 1 0.01 0 0
11 1 0 0 0.01
12 1 0 0 0.02
13 1 0 0 0.05
14 1 0 0 0.1
15 1 0 0 0.2
13/14
Department of Control Engineering & Automation – FEEE – HCMUT
LAB REPORT
Full name: Group: Date:
1. From Table 3 and Table 4, write state equations of spring-mass system according
to (3)?
...............................................................................................................................................
...............................................................................................................................................
...............................................................................................................................................
...............................................................................................................................................
...............................................................................................................................................
...............................................................................................................................................
...............................................................................................................................................
...............................................................................................................................................
...............................................................................................................................................
...............................................................................................................................................
...............................................................................................................................................
2. From experimental results in Section 5.2, comment on the effect of each parameter
K f 3 , K f 4 on the performance of the control system?
...............................................................................................................................................
...............................................................................................................................................
...............................................................................................................................................
...............................................................................................................................................
...............................................................................................................................................
...............................................................................................................................................
3. From experimental results in Section 5.3, comment on the effect of each parameter
K f 1 , K f 2 and K f 4 on the performance of the control system?
...............................................................................................................................................
...............................................................................................................................................
...............................................................................................................................................
...............................................................................................................................................
...............................................................................................................................................
14/14