0% found this document useful (0 votes)
79 views

Lab 5 - State Feedback Control

1) The document describes a lab experiment involving a mass-spring system with two carts and springs connected. Students will develop state equations to model the system and design a state feedback controller to control the position of one of the carts. 2) Key objectives are to understand how to simulate and analyze a control system using state feedback control of a spring-mass system, and to collect data to identify the system model parameters like spring constants and friction coefficients. 3) Formulas are developed to calculate the unknown system parameters from experimental data by setting up systems of equations relating the measured state variables over time to the parameters. Solving these systems of equations identifies the parameter values.

Uploaded by

Hạo Namm
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views

Lab 5 - State Feedback Control

1) The document describes a lab experiment involving a mass-spring system with two carts and springs connected. Students will develop state equations to model the system and design a state feedback controller to control the position of one of the carts. 2) Key objectives are to understand how to simulate and analyze a control system using state feedback control of a spring-mass system, and to collect data to identify the system model parameters like spring constants and friction coefficients. 3) Formulas are developed to calculate the unknown system parameters from experimental data by setting up systems of equations relating the measured state variables over time to the parameters. Solving these systems of equations identifies the parameter values.

Uploaded by

Hạo Namm
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Department of Control Engineering & Automation – FEEE – HCMUT

LAB 5

STATE FEEDBACK CONTROL

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.

II. THEORETICAL BASIS


2.1. Mathematical description of spring-mass system
The model of the spring-mass system is shown in Figure 1. The system consists
of two carts with the weight m1, m2 connected to two springs with constant k1, k2. F
force impacts on the vehicle m2 to control the position of the cart 2 to desired position
x2 or control the position of the cart 1 to desired position x1.

Figure 1. Spring-mass system model

The differential equations describing the system is as follows:


m2 x2 = F − b2 x2 − k2 ( x2 − x1 )
(1)
m1x1 = k2 ( x2 − x1 ) − b1x1 − k1x1
where b1 is the friction coefficient of cart 1 and b2 is the friction coefficient of cart 2.

1/14
Department of Control Engineering & Automation – FEEE – HCMUT

In the spring-mass system experiment, the impact force F is provided by a DC


motor. If we ignore motor inductance, the force F is approximately proportional to the
supply voltage:
F = Ku (2)
where u is the voltage supplied to the DC motor, K is the gain coefficient. State
equations describing the system (1) can be rewritten as:
 0 1 0 0 
 x1   −( k + k ) −b1 x   0 
0  1  0 
k2
x   1 2
 1  m1 m1 m2   x1   
= +  0 u (3)
 x2  0 0 0 1   x2   
     K
 x2   k2 −k2 −b2   x2   
 0
m2   m2 
 m2 m2
y = 1 0 0 0 x : if we control x1 variable

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) 

Solving system of equations (7), we find k12 and b1 :

( )
−1
 = T  T  (8)

2.2.2. Develop formula to calculate K and b2


As described in Section 2.2.1, the second equation of (1) is rewritten as
follows:
T 2 Ku (k ) − b2T  x2 (k ) − x2 (k − 1) =
(9)
m2  x2 (k + 1) − 2 x2 (k ) + x2 (k − 1) + k12T 2  x2 (k ) − x1 (k ) 

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) 

 m2  x2 (3) − 2 x2 (2) + x2 (1) + k12T 2  x2 (2) − x1 (2)  


 
 m2  x2 (4) − 2 x2 (3) + x2 (2)  + k12T 2  x2 (3) − x1 (3)  
= 
...
 
 m2  x2 ( N ) − 2 x2 ( N − 1) + x2 ( N − 2) + k12T 2  x2 ( N − 1) − x1 ( N − 1) 
 
3/14
Department of Control Engineering & Automation – FEEE – HCMUT

Solving system of equations (10), we find K and b2 :

( )
−1
 = T  T  (11)

2.3. State feedback control

Figure 2. Structure of state feedback controller

The structure of state feedback controller is illustrated in Figure 2. For spring-


mass system, we will use feedback control with 4 state variables. Feedback
coefficients for 4 states are:
K f =  K f 1 Kf2 Kf3 K f 4  (12)

State equations of closed-loop system is:

(
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

III. LAB DESCRIPTION


3.1. Hardware
The hardware block diagram is shown in Figure 3. The PC104CARD board is
the central hardware in the experiments. ALTERA's FPGA based PC104CARD board
is capable of communicating with computer via the MATLAB / Simulink / Real-time
Windows Target software, the board has the following features:
• PWM: 4 PWM channels with resolution 0.1% (~ 10bit).
• Encoder: 4 x4 encoder inputs.
• Communicate with computer through printer port using EPP standard.
The DC motor used in this lab has rated voltage of 24V and encoder resolution
of 2048 pulses/rev. PWM and Dir signals will drive the motor at the desired speed and
direction:
• Voltage applied to the motor at the output of the motor driver is equal to (V),
where is the duty cycle of the pulse in 0.1% unit (0 – 1000).
• Positions (unit: mm) and speeds (unit: mm/s) of the carts are measured by
counting the number of pulses in one sampling period T=2ms.

Figure 3. Hardware connection diagram of the lab

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

• Go to the Simulation -> Configuration menu, select Solver to configure the


Simulation time and Solver Options as shown in Figure 5.
• Go to the Tools menu -> Real-Time Workshop -> Build Model (or left-click on
the Incremental Build icon) to compile the model.
• After the model is compiled successfully, go to the Simulation -> Connect To
Target menu (or left-click on the Connect To Target icon) to connect the
Simulink model to external hardware.
• Go to Simulation menu -> Run (or click on Run icon) to run the model.

Run Connect To Target Incremental Build

Figure 4. Simulink model connecting to hardware

6/14
Department of Control Engineering & Automation – FEEE – HCMUT

Figure 5. Configure simulation parameters

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

Figure 6. Simulink diagram to analyze output response of the spring-mass system


7/14
Department of Control Engineering & Automation – FEEE – HCMUT

Figure 7. Spring-mass system model

a) Create Simulink model file as shown in Figure 6.


b) Set Force = 10 (N).
c) Run the simulation.
d) Open the Scope to see output response, calculate moving distances of cart 1,
cart 2 and write the results in Table 1.
e) Repeat step b) to step d) with remaining Force values in Table 1. Plot the
graphs of x1 and x2 against Force. Comment on the graphs.

Table 1. Moving distance by impact force


Time Force (N) x1 (mm) x2 (mm)
1 10 10 20
2 20
3 30
4 40
5 50

4.2. Feedback control of spring-mass system


Designed the feedback controller to control the position of cart 2 as shown in
Figure 8, where:
• “Gain1” and “Gain2” block have value of 1000 in order to convert meter unit
to millimeter unit.

8/14
Department of Control Engineering & Automation – FEEE – HCMUT

• “Gain3” block has value of  0; 0; 1; 0 in order to select controlled variable as


x2 . (If controlled variable is x1 then “Gain3” block has value of 1; 0; 0; 0 ).

• Feedback coefficients K f =  K f 1 Kf2 Kf3 K f 4  correspond to 4 state

variables x =  x1 x2  .
T
x1 x2

Figure 8. Simulink diagram of state feedback control system

a) Create Simulink model file as shown in Figure 8.


b) K f =  0 0 0.1 0 . Set setpoint of cart 2 to 30mm.
c) Run the simulation.
d) Open the Scope to see output response; calculate POT, settling time and
steady-state error.
e) Repeat step b) to step d) with remaining values of K f in Table 2. Comment on
simulated results when increasing K f .
Table 2. K f values

Time Kf POT Steady-state error Settling time

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

Time k1 (N/m) b1 (N.s/m)


1
2
3
4
5
Average

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)

% Students refer to the code above


% to find parameters of the system:
% Gain coefficient U = K.F: K_hat
% Friction coefficient of m2: b2_hat
a1 = ...
a2 = ...
PHI = ...
lamda = ...

theta = inv(PHI'*PHI)*PHI'*lamda;
K_hat = theta(1)
b2_hat = theta(2)

b) Compile and run recti_response.mdl file to collect data.


c) Rerun recti_ident.m file after writing the code to calculate K, b2.
d) Rerun step b) and c) 5 times and write the results in Table 4, then calculate
average value of parameters K and b2.
Table 4. K , b2 values

Time K b2 (N.s/m)
1
2
3
4
5
Average

11/14
Department of Control Engineering & Automation – FEEE – HCMUT

5.2. Position control of cart 2


Experimental steps:
a) Open recti_feedback_ctrl2.mdl file.
b) K f =  0 0 0.1 0 . Set reference position of cart 2 to 30mm.
c) Compile and run the model (see instructions in Section 2.3).
d) Open the Scope to see output response; determine POT, settling time and
steady-state error.
e) Repeat step b) to step d) with remaining values of K f in Table 5. Comment on
the effect of each parameter K f 3 and K f 4 on the performance of the control
system.

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

5.3. Position control of cart 1


Experimental steps:
a) Open recti_feedback_ctrl1.mdl file.
b) K f =  0.2 0 0 0 . Set reference position of cart 1 to 15mm.
c) Compile and run the model.
d) Open the scope to see output response; determine POT, settling time and
steady-state error of cart 1’s position.

12/14
Department of Control Engineering & Automation – FEEE – HCMUT

e) Repeat step b) to step d) with remaining values of K f in Table 6. Comment on


the effect of each parameter K f 1 , K f 2 and K f 4 on the performance of the
control system.

Table 6. K f values

Time Kf POT Steady-state error Settling time

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

You might also like