Lab Gantry
Lab Gantry
AAE 364L
In this experiment we will design a controller for a gantry or crane. Without a controller
the pendulum of crane will swing for a long time. The idea is to use control to stop the
swinging of the pendulum.
This experiment consists of a cart with mass M on a one dimensional track and a pendu-
lum swinging from the cart. The pendulum is in the downward position. The cart is driven
by a force from a servo motor. The position of the cart is denoted by xc (t), and the Voltage
to the servo motor is denoted by v(t). The angle between the pendulum and its resting
position is denoted by α; see Figure 1. The nonlinear equations of motion are given by
( ) ( )
(Mc + Mp )Ip + Mc Mp lp2 + Mp2 lp2 sin(α)2 ẍc + Ip + Mp lp2 Beq ẋc
( ) ( )
= Mp lp Bp cos(α)α̇ + Mp2 lp3 + Ip Mp lp sin(α)α̇2 + Ip + Mp lp2 Fc + Mp2 lp2 g cos(α) sin(α);
( )
(Mc + Mp )Ip + Mc Mp lp2 + Mp2 lp2 sin(α)2 α̈ + (Mc + Mp ) Bp α̇
= Mp lp cos(α)Beq ẋc − (Mc + Mp ) Mp glp sin(α) − Mp2 lp2 sin(α) cos(α)α̇2 − Mp lp cos(α)Fc ;
ηg Kg ηm Kt (vrmp − Kg Km ẋc )
Fc = 2
. (0.1)
Rm rmp
Here Fc is the force on the cart. The notation and values are given in the table in the
Appendix. These values are given also given in the MATLAB file “setup lab ip02 spg.m”
posted on the Web page for the course. So you will not have to calculate any of these values
for the Lab. The linearized equations of motion are given by
−(Ip + Mp lp2 )Beq ẋc + Mp lp Bp α̇ + Mp2 lp2 gα + (Ip + Mp lp2 )Fc
ẍc =
(Mc + Mp )Ip + Mc Mp lp2
Mp lp Beq ẋc − (Mc + Mp )Bp α̇ − (Mc + Mp )Mp glp α − Mp lp Fc
α̈ =
(Mc + Mp )Ip + Mc Mp lp2
ηg Kg ηm Kt (vrmp − Kg Km ẋc )
Fc = 2
. (0.2)
Rm rmp
Now let us convert the linear equations to a state space model of the form
ẋ = Ax + Bv.
Here A is a 4 × 4 matrix, B is a column vector of length 4 and the input v is the voltage to
1
Figure 1 The Gantry
the motor. To convert the system in (0.2) we used the following state variables:
x1 xc
x2 α
x=
x3 = ẋc . (0.3)
x4 α̇
By consulting the values in the table at the end of the section, we computed A and B, that
is,
0 0 1 0 0
0 0 0 1 0
A=
0 1.5216 −11.6513 0.0049 and B = 1.5304
.
(0.4)
0 −26.1093 26.8458 −0.0841 −3.5261
These matrices A and B are contained in the MATLAB setup file on the Web page, so
you do not have to retype A and B in MATLAB. The eigenvalues of A are given by
{0, −11.3975, −0.1689 + 4.8040i, −0.1689 − 4.8040i}. So A only is marginally stable.
Let us compute the transfer function from the voltage v to the output xc . Since x1 = xc ,
the corresponding output matrix C is given by
[ ]
C= 1 0 0 0 . (0.5)
2
By using ss2tf in MATLAB, we see that the transfer function from the voltage v to the
output xc is given by
Xc (s) 1.53s2 + 0.1114s + 34.59
= C(sI − A)−1 B = 4 . (0.6)
V (s) s + 11.74s3 + 26.96s2 + 263.4s
Xc (s) Xc (s)
Notice that V (s)
has a pole at the origin. Moreover, the poles of V (s)
are the eigenvalues of
A. Finally, it is noted XVc(s)
(s)
is a fourth order system.
Now let us compute the transfer function from the voltage v to the angle α. Since x2 = α,
the corresponding output matrix C is given by
[ ]
C= 0 1 0 0 . (0.7)
By using ss2tf in MATLAB, we see that the transfer function from the voltage v to the
angle α is given by
α(s) −3.526s
= C(sI − A)−1 B = 3 . (0.8)
V (s) s + 11.74s2 + 26.96s + 263.4
By using ss2tf in MATLAB we see that the transfer function from the voltage v to the end
of the pendulum xe is given by
Xe (s) −0.7311s2 + 0.1114s + 34.59
= C(sI − A)−1 B = 4 . (0.10)
V (s) s + 11.74s3 + 26.96s2 + 263.4s
Finally, it is noted that this is a fourth order system.
3
The equation of motion is nonlinear. Recall that for small angles, sin(α) ≈ α. Using this we
see that the linearized equation of motion is determined by
( )
Ip + Mp lp2 α̈ + Mp lp gα = 0. (1.2)
Hence the linear equation of motion for the pendulum is given by
√
Mp lp g
α̈ + ωp2 α = 0 where ωp = . (1.3)
Ip + Mp lp2
Here ωp is the natural frequency of the pendulum. In other words, the pendulum will oscillate
at ωp for small angles. For example, assume that the initial condition are given by α(0) = α0
and α̇ = 0. The the solution to the linear differential equation in (1.3) is given by
α(t) = α0 cos(ωp t). (1.4)
By consulting the table for our experiment (or the corresponding MATLAB setup file) we
see that
ωp = 4.7543 rad/s. (1.5)
So let us verify this number experimentally. Hold the cart still and start the pendulum off
at a small angle α(0) = α0 and α̇ = 0. Record the output of the angle. Then measure the
period τ . We expect the period to be approximately
2π
τ= = 1.3216 s. (1.6)
ωp
4
1.2 In your lab report include the following under Part (i):
(a) Hand in your experimental plot of the angle.
(b) Hand in your calculation of the frequency ωp that you determined from the experiment.
2.1 Pre-Lab for resonance. Due at the beginning of the lab experiment. You
will not be allowed to run the lab experiment with out a complete pre-lab.
(i) Hand in your values for the damping ratio ζ and natural frequency ωn that you calcu-
lated.
(ii) Hand in the Bode plot of Gα . Determine |Gα (ıω)| from the Bode plot for ω = 3 rad/s,
ωn , and 7 rad/s.
5
2.2 The Lab steps to demonstrate resonance
(i) In the same directory, open labgantryres in Simulink. Select Tools - External
Mode Control Panel - Signal & Triggering, and change the duration to 20,000.
(ii) In the Simulink window, set simulation time to 39 seconds.
(iii) In the MATLAB command window, type X M AX = 0.6; X M IN = −0.6;.
(iv) To properly record your data, repeat Step (v) from Section 1.1 for the angle (theta)
scope.
(v) Place the cart at the center of the track. Set the sinusoid to 3 sin(ωt), that is, set the
amplitude of the sinusoid to be 3. Run the experiment for ω varying from 3 rad/s to
ωn and then 7 rad/s.
(vi) Click Quarc - Build. Select Simulation - Connect to Target, and Quarc - Start.
After about 30 seconds, stop the simulation.
(vii) Save the angle history in MATLAB (File - Save - Save as Mat file) for ω = 3
rad/s, ω = ωn and ω = 7 rad/s.
(viii) Close the Simulink model, don’t save changes.
2.3 In your lab report include the following under Part (ii):
(a) Hand in the values for ωn and ζ that you calculated.
(b) Notice that ωn ≈ ωp . In two short sentences or less explain why ωn ≈ ωp .
(c) Hand in the Bode plot of Gα . Hand in your value for the natural frequency ωn that you
computed from the Bode plot. In two short sentences or less explain how you computed
ωn from the Bode plot.
(d) Hand in your plots of the angle from the experiment for ω = 3 rad/s, ω = ωn and ω = 7
rad/s. What happens when the frequency ω = ωn ?
(e) Compute |Gα (ıω)| from the Bode plot of Gα and from the experimental results for
ω = 3 rad/s, ω = ωn and ω = 7 rad/s.
6
The input is v, the output is y and the vector x is the state. Here A is a n × n matrix, B is
a column vector of length n, the state x is a vector of length n and C is the row vector of
length n given by
a11 a12 · · · a1n b1 x1
a21 a22 · · · a2n b2 x2
A = ... .. ..
, B= ..
and x = ..
. ··· . . .
an1 an2 · · · ann bn xn
[ ]
C = c1 c2 · · · cn . (3.2)
Recall that the solution to the state space system in (3.1) is given by
∫ t
At
x(t) = e x(0) + eA(t−σ) Bv(σ)dσ
0
∫ t
At
y(t) = Ce x(0) + CeA(t−σ) Bv(σ)dσ. (3.3)
0
Substituting this v into ẋ = Ax + Bv yields the following state variable feedback system:
7
The solution to the state space feedback system in (3.8) is given by
∫ t
(A−BK)t
x(t) = e x(0) + e(A−BK)(t−σ) Br(σ)dσ
0
∫ t
(A−BK)t
y(t) = Ce x(0) + Ce(A−BK)(t−σ) Br(σ)dσ. (3.9)
0
The transfer function from the reference signal r to the output y is given by
Y (s)
= GK (s) = C (sI − (A − BK))−1 B. (3.10)
R(s)
Notice that the closed loop transfer function GK (s) depends upon the choice of the feedback
gain K. The characteristic polynomial for A − BK is defined by det[sI − (A − BK)]. By
using the appropriate minors to compute the inverse of sI − (A − BK), it follows that the
closed loop transfer function from the reference signal r to the output y is given by
q(s)
GK (s) = C(sI − (A − BK))−1 B = (3.11)
det[sI − (A − BK)]
where q is a polynomial of degree at most n − 1. In particular, the poles of the closed loop
system GK (s) are contained in the set of all eigenvalues for A − BK. Finally, it is noted
that the closed loop system GK is stable if all the eigenvalues of A − BK are contained in
the open left half plane {s : ℜs < 0}.
Recall that the poles of the closed loop system depend upon the choice of the feedback
gain K. The eigenvalues of the closed loop system in (3.8) are determined by the eigenvalues
of A−BK. Our feedback strategy is to pick the state feedback gain K to place the eigenvalues
of A − BK at n specified locations {λj }n1 in the open left hand plane {s : ℜs < 0}. In this
case, the closed loop system GK is stable. Moreover, if the reference signal r set to zero,
then the solution of the feedback system (3.8) converges to zero, that is,
So by choosing the state feedback vector appropriately, one can force the state to zero.
Moreover, by placing the eigenvalues of A − BK at n specified locations {λj }n1 in the open
left hand plane {s : ℜs < 0} one can dictate how the state x converges to zero. Finally,
it is noted that in order to implement state variable feedback, one needs an actuator or an
instrument to to read all the states {xj }n1 .
Consider the state space system in (3.1) or a pair of matrices {A, B} where A is a n × n
matrix and B is a column vector of length n. The controllability matrix W associated with
the pair {A, B} is the n × n matrix defined by
[ ]
W = B AB A2 B A3 B · · · An−1 B . (3.12)
The state space system in (3.1) or the pair {A, B} is controllable if its controllability matrix
W is invertible, or equivalently, the rank of W equals n. We will use the following result to
control the pendulum swing in our gantry problem.
8
THEOREM 3.1 Consider the state space system
ẋ = Ax + Bv (3.13)
where A is a n × n matrix and B is a column vector of length n. Assume that the pair
{A, B} is controllable. Let {λj }n1 any set of distinct complex numbers. Then there exists a
state feedback vector K such that {λj }n1 are the eigenvalues of A − BK. In particular, the
poles of the feedback system GK are contained in {λj }n1 , that is,
q(s)
GK (s) = C(sI − (A − BK))−1 B = . (3.14)
(s − λ1 )(s − λ2 ) · · · (s − λn )
Finally, this state feedback gain K can be computed by using the place command in MATLAB,
that is, ( [ ])
K = place A, B, λ1 λ2 · · · λn . (3.15)
The Gantry Design Problem. If one hits the pendulum, then the pendulum will oscillate
for a long period of time. Your Prelab assignment is to design a controller to make the
pendulum stop oscillating in 2.2 seconds or less. Bring you control design to the Lab. Then
the TA will tap the pendulum to see if your design works.
One method to design a feedback controller is to consider what happens for transfer
functions F of the form
ωn2
F (s) = 2 . (3.16)
s + 2ζωn s + ωn2
Let P O denote the percent overshoot and ts the settling time due to a step. Then it is well
known that if the natural frequency ωn and ζ are given by
|ln (P O/100)| 4
ζ=√ and ωn = . (3.17)
ts ζ
ln (P O/100)2 + π 2
Then the response of the transfer function F due to a step has the desired percent overshoot
P O and settling time ts . For our problem let us choose P O = 5 and ts = 2.2 s. Hence
So if ζ = 0.6901 and ωn = 2.6346 rad/s for the transfer function F in (3.16), then the
response due to a step will have a 5% percent overshoot and a settling time of 2.2 seconds.
The poles λ1 and λ2 of F corresponding to ζ = 0.6901 and ωn = 2.6346 rad/s are given by
solving for the roots of
Therefore the poles of F corresponding to ζ = 0.6901 and ωn = 2.6346 rad/s are given by
9
Notice that our state space linear approximation for the cart and pendulum in (0.2) is
fourth order. Moreover, the pair {A, B} in (0.4) is controllable. Now let {λj }41 be any
four distinct complex numbers in the open left half plane {s : ℜs < 0}. Then one can use
the place command in MATLAB to find a state feedback gain K such that {λj }41 are the
eigenvalues of A − BK, that is,
[ ] [ ]
K = k1 k2 k3 k4 = place (A, B, λ1 λ2 λ3 λ4 ) (3.20)
This sets the initial conditions xc (0) = 0 m, ẋc (0) = 0 m/s, α(0) = 0 rad and the initial
angle angular velocity to α̇(0) = π/2 rad/s. These initial conditions are set to simulate
10
someone hitting the pendulum with α̇(0) = π/2 rad/s and α(0) = 0 rad. Here we want to
see how our controller will respond when the pendulum is struck with an angular velocity of
α̇(0) = π/2
[ rad/s while
] the pendulum is a rest. To simulate the pendulum with no control
set K = 0 0 0 0 in MATLAB. Then run the Simulink file and save the angle plot to
hand in later. Make sure that the amplitude in the position set point block is set equal to
zero.
xc_des
Control Effort:
Position Setpoint (m) Vm (V) xc (m) X_eom
alpha (rad)
u = Vm
30e−3 K(1) Vm (V)
xc_dot (m/s) Scopes
Position Setpoint UPM Voltage
Setpoint Amplitude (m) Saturation alpha_dot (rad/s)
SPG + IP02:
Non−Linear EOM
State−Feedback Gain
Now you can use this Simulink file to design a feedback control with the place command.
To accomplish this choose the poles λ3 and λ4 that you deem appropriate. Then in MATLAB
type
[ ]
K = place (A, B, −1.8182 + 1.9067i −1.8182 − 1.9067i λ3 λ4 ). (3.23)
Then K will be a vector of length 4 which is the state feedback gain used in the Simulink file.
Now run the Simulink file and check out the various scopes to see if you like the response.
Then vary {λj }41 until you achieve the response that meets the design objective. You do not
have to choose λ1 = −1.8182+1.9067i and λ2 = −1.8182−1.9067i. This is just a suggestion.
You can choose {λj }41 to have any value that you want as long as the angle stops moving in
under 2.2 seconds. Save the angle plot for your best values of K. Then plot this angle on
the same plot with K = 0. Bring your best value of the state feedback gain K to the Lab
with you. For your pre-lab also bring your plot of the angle α for your best feedback gain
and no feedback K = 0 on the same plot. Finally, it is noted that K cannot be infinitely
large, that is, |K(j)| ≤ 200 for all j.
11
3.1 Pre-Lab for pole placement. Due at the beginning of the lab experiment.
You will not be allowed to run the lab experiment with out a complete
pre-lab.
(i) Hand in your best values for the state gain K that you computed from Simulink.
(ii) Hand in the graph of the angle α for your best choice of the feedback gain K and the
graph of the angle α for no control K = 0 on the same plot for 15 seconds.
(ii) In the same directory, open labgantrypp in Simulink. Select Tools - External Mode
Control Panel - Signal & Triggering, and change the duration to 10,000.
(iii) In the Simulink window, set simulation time to 19 seconds.
(iv) To properly record your data, repeat Step (v) from Section 1.1 for the angle (theta)
scope.
(v) Click Quarc - Build. Select Simulation - Connect to Target, and Quarc - Start.
(vi) Have the TA tap the pendulum. After about 10 seconds hit the stop button.
(vii) If you are not happy with your response you can change the values of K, and run the
experiment again. Note that you can only do this because it can be done cheaply.
(viii) For your best run, save the angle history in MATLAB (File - Save - Save as Mat
file). Close the Simulink model, don’t save changes.
3.3 In your lab report include the following under Part (iii):
(a) Hand in the best values for the state gain K that you calculated using Simulink, along
with the the time it takes for the pendulum to stop swinging after it is given initial
angular velocity α̇(0) = π/2 rad/s.
(b) Hand in the best values for the state gain K that you used in the experiment.
(c) From the plot of the angle from the experiment, determine the initial angular velocity
after you tapped the pendulum. Using the best values for the state gain K that you
used in the experiment, simulate your system in Simulink with this initial condition of
angular velocity. Hand in your plot of the angle from your best experiment. Compare
that with the plot of the angle from your simulation using your best values for the state
gain K.
(d) Is your simulation accurate? Use your simulation to estimate the time it takes for the
pendulum to stop swinging after given initial angular velocity α̇(0) = π/2 rad/s.
12
4 Integral control of the gantry
In this section we will add an integral control to move the pendulum to various positions on
the track. Our design objective is to move the cart and pendulum 0.5 meters on the track
and have the pendulum stop moving as soon as possible. The idea behind our design is to
incorporate an integral controller in our pole placement method. To this end, consider the
four dimensional state variable system in (0.3). Now let us define a new state variable
∫ t
x5 = (u(σ) − x1 (σ)) dσ or equivalently ẋ5 = u − x1 . (4.1)
0
Here u is the new input. Recall that x1 is the position of the cart. In our problem u will be
a constant. So x5 will be the integral between the reference signal u and the position of the
cart. Using ẋ5 = u − x1 , we may write a new state space system as
ẋ1 0 x1 b1 0
ẋ2 0 x2 b2 0
A
ẋ3 = 0 x3 + b3 v + 0 u (4.2)
ẋ4 0 x4 b4 0
[ ]
ẋ5 −1 0 0 0 0 x5 0 1
Now let us define the new state matrix Ai and Bi , that is,
0 b1
0 [ ] b2
A
Ai = 0 and Bi = B = b3
0
b4
[ ] 0
−1 0 0 0 0 0
xc 0
α
0
x = ẋc and D = 0 .
α̇ 0
∫
(u − xc ) 1
ẋ = Ai x + Bi v + Du. (4.3)
Using the matrices A and B in (0.4) one can easily construct Ai , Bi and D in MATLAB.
Recall that you already have A and B in MATLAB once you run “setup lab ip02 spg.m”.
So in MATLAB Ai and Bi are given by
13
It turns out that the pair {Ai , Bi } is controllable. So one can use the place command in
MATLAB to place the eigenvalues of Ai − Bi K at any five distinct locations {λj }51 in the
open left half plane {s : ℜs < 0}. Substituting v = −Kx into the new state variable system
(4.3), we arrive at
ẋ = (Ai − Bi K) x + Du. (4.4)
Now choose u to be the step u(t) = u0 for all t ≥ 0. Because all the eigenvalues of A are
in the open left half plane, the state space system in (4.4) will move to steady state, that
is, ẋ = 0 in steady state. In particular, 0 = ẋ5 = u0 − x1 . In other words, in steady state
x1 = u0 , and the cart will move to the position u0 on the track.
Now we would like to design a controller to move the gantry to position u0 = 0.5 meters
on the track and have the system settle down in under 2.2 seconds. To accomplish this
choose five poles {λj }51 that you deem appropriate. Then in MATLAB type
[ ]
K = place (Ai , Bi , λ1 λ2 λ3 λ4 λ5 ). (4.5)
Then K will be a vector of length 5 which is the state feedback gain used in the Simulink file.
One could use λ1 = −1.8 + 1.9i and λ2 = −1.8 − 1.9i and choose the three remaining poles
far away to try to maintain a 5% overshoot and 2.2 seconds settling time. However, this
choice of λ1 and λ2 is not necessary and you may find a much better choice for your poles.
Your design problem is to try to design a controller which will move the pendulum and the
cart 0.5 meters down the track and have the pendulum settle down as fast as possible. You
can use the Simulink file “aae364gantry2.mdl” on the website or simply rebuild the Simulink
file “s spg pp.mdl” to match that given in Figure 2. To test your design, set the step to 1
and slider gain to 0.5 meters. Then choose the poles {λj }51 that you think will work and run
place in MATLAB. Finally, run the Simulink file in Figure 3. Keep changing the closed loop
poles {λj }51 until you find the state feedback gain which matches the design specifications.
Bring your best gain matrix K to the Lab.
position
180/pi
alpha (rad)
0.5 1 K(5) Vm (V)
s xc_dot (m/s)
Step Slider Integrator UPM Voltage
Gain Saturation alpha_dot (rad/s)
SPG + IP02:
Non−Linear EOM
State−Feedback Gain
14
4.1 Pre-Lab for the integral controller. Due at the beginning of the lab ex-
periment. You will not be allowed to run the lab experiment with out a
complete pre-lab.
(i) Hand in your best values for the state gain K that you computed from Simulink.
(ii) Hand in the graph of the cart position xc and the angle α for your best choice of the
feedback gain K, along with the settling time of α.
15
4.3 In your lab report include the following under Part (iv):
(a) Hand in the best values for the state gain K that you calculated using Simulink, along
with settling time of the pendulum.
(b) Hand in the best values for the state gain K that you used in the experiment, along
with settling time of the pendulum.
(c) Simulate your system using the best values for the state gain K that you used in the
experiment. Hand in your plots of the cart position from the experiment and the
simulation on the same figure. In a separate figure, hand in your plots of angle from
the experiment and the simulation.
16
5 Appendix: The notation for the pendulum and cart
17