Professional Documents
Culture Documents
ME389 MEM04 PendulumGantry Guideline
ME389 MEM04 PendulumGantry Guideline
ME389 MEM04 PendulumGantry Guideline
Contents
1 Overview 1
1.1 Configure ELVIS and DC Motor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.2 Goals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.3 Rotary-Pendulum Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2 Equations of Motion 3
5 Gantry Control 8
B Linearized Dynamics 13
C Files 14
1 Overview
This lab addresses the control of a pendulum swinging from a rotating beam. Their are two control
problems to consider: the gantry (crane) problem where we would like move the rotary section about
while minimizing the swing of the pendulum and the inverted pendulum problem where we would like to
balance the pendulum in the inverted position. First, the model structure for the system is derived from
first principles and simple experiments are carried out to determine the model parameter values. Then, the
laboratory proceeds with control design for each case separately.
1
We control the system using full state feedback, and explore both pole placement and LQR as techniques
for choosing the feedback gains.
The necessary files to carry out the laboratory are available in the “controls drive” (T drive). The drive
should be visible from the windows “Computer” pane
ELVIS (Educational Laboratory Virtual Instrumentation Suite) To startup the ELVIS follow the procedure
1. The main VI for this lab is QNET ROTPEN Lab 03 Gantry Control ME389.vi
• Found in \ME389 VIs
2. There is a reference printed on the wall for starting the ELVIS (Education LabView Instrumentation
Suite).
3. First confirm the prototyping board power is switched OFF, down position. Also switch the Com-
munications to BYPASS.
4. Turn on the main power to the ELVIS with the switch located on the back of the ELVIS. The system
power LED should light up.
5. Run QNET init elvis bypass.vi. The bypass is successful when the LED in the VI is lit.
6. Turn on the prototyping board power. The four LEDs +B, +15, -15, +5 should light up. If any are
not fully lit, consult the TA.
7. Warning: If the motor spins when switching ON the prototyping board power, immediately switch
OFF the Prototyping board power.
1.2 Goals
The rotary-pendulum system consists of an actuated rotary arm controlled by an input torque, τ , and an
unactuated pendulum connected to the arm at a pivot joint.
2
Figure 1: Rotary-pendulum system.
2 Equations of Motion
The rotary pendulum is an example of a “manipulator system”, i.e. a serial chain of robotic manipulator
arms. The equations of motion of all manipulator systems take the characteristic form known as the
manipulator equation,
H(q)q̈ + C(q, q̇)q̇ + G(q) = B̄u, (1)
where q is a generalized coordinate vector, H is the inertial matrix, C captures Coriolis forces, and G
captures potentials (such as gravity). The B̄ matrix maps control inputs u into generalized forces.
The matrices of (1) can be determined by Lagrange’s method. However, the complete derivation provided
in Appendix A of system dynamics is fairly involved and it’s not necessary to understand for this course.
For the rotary pendulum, we have
q = [θ, α]T ,
" #
Jarm + mp r2 + mp lp2 sin2 α mp rlp cos α
H(q) = ,
mp rlp cos α Jp + mp lp2
" #
1 2 1 2
m p lp α̇ sin 2α + C arm m p lp θ̇ sin 2α − m p rl p α̇ sin α
C(q, q̇) = 2 2
,
1
m l 2
sin 2α Cp (2)
2 p p
0
G(q) = ,
mp glp sin α
1
B̄ = ,
0
where Carm and Cp are damping coefficients that result from viscous friction at the joints. Note that the
system matrices H(q), C(q, q̇) and G(q) are independent of the state θ.
3
3 Linearization of Rotary Pendulum Dynamics
As explained in Appendix B, we can use taylor series expansion to obtain a linearized form of the manip-
ulator equation.
ẋ = Ax + Bu, (3)
where x is the full system state (x = [q, q̇]T = [θ, α, θ̇, α̇]T ), and u = τ is the input torque. For rigid body
systems that can be described by the manipulator equation (1), the first order taylor series approximation
around a fixed point (x∗ , u∗ ) is given by,
0 I 0
A= −1 ∂G(q) −1
, and B= −1
. (4)
−H(q) ∂q
−H(q) C(q, q̇) H B̄ x∗ ,u∗
x∗ ,u∗
Computing
mp lp2 + Jp
−1 1 −lp mp r cos α
H(q) = , (5)
∆ −lp mp r cos α mp lp2 sin2 α + mp r2 + Jarm
where
∆ = Jp Jarm + m2p lp4 sin2 α + m2p lp2 r2 + Jarm mp lp2 + Jp mp r2 + Jp lp2 mp sin2 α − lp2 m2p r2 cos2 α, (6)
and
∂G(q) 0 0
= , (7)
∂q 0 glp mp cos α
we can write
0 0 1 0
1
0 0 0 1
A= 2 2 2 1 2 3
(8)
∆ 0 glp mp r cos α 2 mp lp r cos α sin 2α 0
2 2 2 1 2 2 2 2
0 −(glp mp cos α(mp lp sin α + mp r + Jarm )) −( 2 mp lp sin 2α(mp lp sin α + mp r + Jarm )) 0 x∗ ,u∗
0
1
0
B= 2
, (9)
∆ mp lp + Jp
−lp mp r cos α x∗ ,u∗
In the actual physical system the control input is not the torque, but is actually the voltage applied to
the motor. The actuator dynamics must be included into the state equations since the computer does not
control the motor torque directly but controls the voltage being applied to the motor. The torque generated
at the arm pivot from the motor voltage, Vm , is given by
Kt Vm − Km θ̇
τ= . (10)
Rm
4
The linear dynamics of the motor can be combined with the state space system (13)-(14) to obtain the
complete dynamics
ẋ = Ax + Bu, (11)
where x = [θ, α, θ̇, α̇]T , u = Vm is the input motor voltage. This is achieved by the following transforma-
tion
Kt
A → A − 0 0 KRt Kmm B 0
B→ B, (12)
Rm
which results in
0 0 1 0
0 0 0 1
1
A=
glp2 m2p r cos2 α 1 2 3
− Kt Km
(mp lp2 + Jp )
∆ 0 2
m p l p r cos α sin 2α Rm
0
0 −(glp mp cos α(mp lp2 sin2 α + mp r2 + Jarm )) −( 2 mp lp sin 2α(mp lp sin α + mp r + Jarm )) + KR
1 2 2 2 2 t Km
(mp lp r cos α) 0
m x∗ ,u∗
(13)
0
Kt 0
B= 2
. (14)
Rm ∆ mp lp + Jp
−lp mp r cos α x∗ ,u∗
0 0 1 0 0
0 0 0 1 0
A = 0 m2p grlp2 −Kt Km (Jp +mp lp2 ) , B= K (J +m l 2)
.
t p p
p
Jp Jarm +Jp mp r2 +Jarm mp lp2 Rm (Jp Jarm +Jp mp r2 +Jarm mp lp2 )
0 2 2
Rm (Jp Jarm +Jp mp r +Jarm mp l )
p
mp glp (Jarm +mp r2 ) −Kt Km (mp rlp ) Kt (mp rlp )
0 Jp Jarm +Jp mp r2 +Jarm mp lp2 Rm (Jp Jarm +Jp mp r2 +Jarm mp lp2 )
0 Rm (Jp Jarm +Jp mp r2 +Jarm mp lp2 )
0 0 1 0 0
0 0 0 1 0
A = 0 m2p grlp2 −Kt Km (Jp +mp lp2 ) , B = Kt (Jp +mp lp2 ) .
Jp Jarm +Jp mp r2 +Jarm mp lp2 Rm (Jp Jarm +Jp mp r2 +Jarm mp lp2 )
0
Rm (Jp Jarm +Jp mp r2 +Jarm mp l2 )
p
−mp glp (Jarm +mp r2 ) Kt Km (mp rlp ) −Kt (mp rlp )
0 Jp Jarm +Jp mp r2 +Jarm mp lp2 Rm (Jp Jarm +Jp mp r2 +Jarm mp lp2 )
0 Rm (Jp Jarm +Jp mp r2 +Jarm mp lp2 )
To use the dynamic model described by (11), we have to plug in values for all the parameters. Some of
these are known constants, such as the gravitational acceleration, g. Others are easy to measure directly,
such as the pendulum length. The system identification procedure consists of three parts:
1
Note, the system exhibits a hanging fixed point for any value of θ, thus there are actually a continuum of hanging fixed
points, and any value of θ can be used to solve for the linear dynamics.
5
(a) Front View Pendulum where lp is the distance to the (b) Moment Inertial Diagram
center of mass
Figure 2: Free body diagrams of pendulum.
For a composite object, made of several bodies, the center of mass is given by
Pn
mi xi
xcm = Pi=1 n , (15)
i=1 mi
where xcm is the distance from some reference point to the center of mass of the composite object and xi
is the distance to the center of mass for each individual object.
6
Lab Work 1:
1. Using Table 1 and equation (15) calculate the center of mass of the pendulum relative to the pivot
location, lp .
The generalized equation for moment of inertia of an arbitrary rigid body about its axis of rotation is
Z
J= r2 dm, (16)
M
where r is the perpendicular distance between the element mass, dm, and the axis of rotation and the
integral is calculated over the object’s entire mass, M .
Lab Work 2:
1. Use (16) to write an expression for the moment of inertia in terms of the parameters Mp1 , Mp2 ,
Lp1 , and Lp2
M
(a) Hint: For a uniform rod of length L and mass M , the elemental mass is dm = L
dx
2. Use Table 1 and the obtained expression to determine the moment of inertia Jp .
The linearized dynamics of this system about and angle of α = 0 are given by
Jp α̈ + mp glp α = 0. (18)
Measurements of the natural frequency and pendulum center of mass length can be used to calculate the
pendulum moment of inertia.
7
Lab Work 3:
Collect data to determine the natural frequency of the pendulum alone. This can be done by letting the
pendulum swing while holding the rotary beam fixed and observing the time it takes for the pendulum
to swing through a single period. The natural frequency is equivalent 1 over the elapsed time required
to complete a period cycle.
3. Bring the pendulum to some angle and let it go allowing it to swing freely. What initial angle
makes sense for this test? Think about problems that occur in the limit of small to large angles.
5 Gantry Control
In this section, we consider control of the rotary system in the Gantry (crane) position. Imagine the rotary
beam as a crane with the pendulum in the down position as a load to be displaced. We wish to move
the load as fast as possible but minimize the amount of swinging. The model, determined in the previous
sections, is given in state space form,
ẋ = Ax + Bu, (22)
y = Cx, (23)
We assume measurements of all the states are available, i.e. y = x and C is the identity matrix. The
controller is called a linear state feedback controller, i.e. it is of the form
u = −K(x − xd ), (24)
where K is a matrix of control gains. The control gains are K = [kp,θ , kp,α , kd,θ , kd,α ]T , where kp,θ is a
proportional gain on θ, kp,α is a proportional gain on α, kd,θ is a derivative gain on θ, and kd,α is a derivative
gain on α:
u = −K(x − xd ) = −kp,θ (θ − θd ) − kp,α (α − αd ) − kd,θ θ̇ − kd,α α̇. (25)
8
Lab Work 5: Gantry Proportional Controller
Use proportional control to move the gantry to the desired position. Carry out the control design by first
simulation and then implementation on the real hardware.
1. The proportional control can be implemented by setting the gain matrix to K = [kp 0 0 0].
2. This applies a proportional gain to the state θ relative to the desired angle, θd , i.e.
u = −K(x − xd ) = kp (θ − θd ). (26)
3. Use the Control implementation tab of the VI and set the first LQR gain to Kp and the others to
zero.
4. Note the beam tracks the desired location, but there is lots of oscillation in the pendulum.
Note that K is a 1 × 4 matrix. Now design and LQR controller to improve the pendulum damping. Use
a Q matrix that penalizes non zero pendulum angles and non zero rotary beam locations. Carry out the
control design by first simulation and then implementation on the real hardware.
In this section, we consider control of the rotary system in the Inverted Pendulum position. The model,
determined in the previous sections, is given in state space form,
ẋ = Ax + Bu, (28)
y = Cx, (29)
9
Lab Work 8: Inverted Pendulum Pole-Placement Controller
Carry out the control design by first simulation and then implementation on the real hardware.
1. Create a state space system in Matlab for the inverted pendulum case
3. Verify that your system is controllable by using the Matlab ctrb command.
4. Choose the closed loop pole locations to be all in the LHP. You can mirror any RHP poles into the
LHP. Use Matlab place command to do the pole placement.
6. If the system is stabilized with reasonable input voltages (≤ 10 V), try it out on the real system.
Note that K is a 1 × 4 matrix. Now design and LQR controller to improve the pendulum damping. Use
a Q matrix that penalizes non zero pendulum angles and non zero rotary beam locations. Carry out the
control design by first simulation and then implementation on the real hardware.
10
A Derivation of System Dynamics by Lagrange method
The kinetic energy of the rotary arm is defined by the rotational kinetic energy
1
Tarm = Jarm θ̇2 (32)
2
and the kinetic energy of the pendulum is the sum of rotational kinetic energy and translational kinetic
energy
1 1
Tpend = Jp α̇2 + mp ṙTp ṙp (33)
2 2
where rp is the position vector of the pendulum center of mass in 3D space,
xp r sin θ + lp sin α cos θ rθ̇cθ + lp α̇cα cθ − lp θ̇sα sθ
rp = yp = h − lp cos α , ṙp = lp α̇sα , (34)
zp r cos θ − lp sin α sin θ −rθ̇sθ − lp α̇cα sθ − lp θ̇sα cθ
where cθ = cos θ, sθ = sin θ, cα = cos α, and sα = sin α. The coordinate values of xp and zp are
determined from the top view of the system, figure ??. To find T , expand the term ṙTp ṙp ,
2 2
ṙTp ṙp = rθ̇cθ + lp α̇cα cθ − lp θ̇sα sθ + (lp α̇sα )2 + −rθ̇sθ − lp α̇cα sθ − lp θ̇sα cθ (35)
11
expanding the quadratics, combining terms, and making cancellations,
ṙTp ṙp = r2 θ̇2 c2θ +2rθ̇cθ lp α̇cα cθ − 2 2 2 2 2
α̇θ̇ccs s + lp2 θ̇2 s2α s2θ + lp2 α̇2 s2α
α sθ + lp α̇ cα cθ − 2l
lp θ̇s
p α θ α θ
1 2 3 4 5 6 4
+ r2 θ̇2 s2θ +2rθ̇sθ lp α̇cα sθ + 2 2 2 2 2 2 2 2 2
α cθ + lp α̇ cα sθ + 2l
lp θ̇s
p
α̇ α sθ sα cθ + lp θ̇ sα cθ
θ̇c ,
1 2 3 4 5 6
ṙTp ṙp 2 2
= r θ̇ + lp2 α̇2 + lp2 θ̇2 s2α + 2rlp θ̇α̇cα .
1 2
4 6
(36)
Finally, the resulting dynamics can be rearranged into the manipulator equation form
where
" #
Jarm + mp r2 + mp lp2 s2α mp rlp cα
H(q) = ,
mp rlp cα Jp + mp lp2
" #
1 2 1 2
m l
p p α̇ sin 2α + C m l
arm 2 p p θ̇ sin 2α − m rl
p p α̇s α
C(q, q̇) = 2 , (44)
1 2
2
m p lp sin 2α C p
0 1
G(q) = ,B = .
mp glsα 0
Note, that the choice of C is not unique, and the identity 2 sin α cos α = sin 2α was used to determine C.
12
B Linearized Dynamics
13
C Files
The necessary files to carry out the lab can be found in T:\ME389 MEM04 GANTRY\. The files are
separated in three directories
• QNET ROTPEN Lab 03 Gantry Control ME389.vi - Can be used for carrying out
control experiments in the hanging position.
• QNET ROTPEN Lab 04 Inv Pendulum Control.vi - Can be used for carrying out
control experiments in the vertical balance position. Note: Ignore the warning for finding the
missing file.
• Use ROTPEN ME389 GANTRY.m to simulate control the rotary pendulum in the hanging
position for the gantry control problem. Plot Gantry SimData.m can be used to plot
the results of the gantry control simulation.
• Use ROTPEN ME389 InvPend.m to simulate control the rotary pendulum in the inverted
position for the balance control problem. Plot InvPend SimData.m can be used to plot
the results of the gantry control simulation.
14