






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







University of California, Santa Barbara Department of Electrical & Computer Engineering
Lab 3: Balancing the Inverted Pendulum
1 Overview
In this lab you will attempt to balance the inverted pendulum. The pendulum is a classic example in differential equations in general, and control systems in specific. This is due to the fact that it has two equilibria, one stable and one unstable. The stable equilibrium— when the pendulum hangs down—is not as interesting as the unstable one, but it is a lot easier to use for debugging your implementation. The ultimate objective is to get a balanced upright pendulum and this will require a good state-feedback/estimator based design.
2 Modeling
A schematic of the inverted pendulum is shown in Figure 1. You are already familiar with the motor cart. The pendulum is attached to the pivot on top of the cart and the angle measurements are obtained via a quadrature encoder, similar to the one used to obtain cart position measurements.
θ
p
Pendulum
Cart (^) Track
Figure 1: Inverted Pendulum
A free body diagram of the system is shown in Figure 2, and defines the forces and moments considered below. Applying Newton’s second law to the motor cart yields
mc p¨ = F − N. (1)
Figure 2: Free Body Diagram for Cart/Pendulum System
Applying Newton’s second law to the pendulum in both the horizontal and vertical directions we obtain
N = mp
d^2 dt^2
(p + l sin(θ))
= mp(¨p + l cos(θ)θ¨ − l sin(θ)( θ˙)^2 ) (2)
P − mpg = mp
d^2 dt^2
(l cos(θ))
= mpg + mpl(− sin(θ)θ¨ − cos(θ)( θ˙)^2 ). (3)
Balancing the moments about the pendulum’s center of mass gives
I θ¨ = P l sin(θ) − N l cos(θ). (4)
By substituting Equation 2 into Equation 1 we obtain
F = (mc + mp)¨p + mpl cos(θ)θ¨ − mpl sin(θ)( θ˙)^2. (5)
Substituting Equations 2 and 3 into Equation 4 yields
θ¨(I + mpl^2 ) = mpgl sin(θ) − mpl p¨ cos(θ). (6)
For simplicity, define the constants
M = mc + mp
L =
I + mpl^2 mpl
Substituting values from Table 1 yields the linearized system
δ x˙ 1 δ x˙ 2 δ x˙ 3 δ x˙ 4
δx 1 δx 2 δx 3 δx 4
[ y 1 y 2
[ 1 0 0 0 0 0 1 0
]
δx 1 δx 2 δx 3 δx 4
Having obtained a linear model, we are now ready to design a controller to balance the inverted pendulum.
3 Design Example
For the following design, a plant different from Equation 9 is considered. You will need to replicate what follows for the inverted pendulum system. Note that there may be some specific implementation issues not dealt with below that you will need to take care of.
For the following design, we will assume our plant is given by
x˙ = Ax + Bu (11)
x ˙ 1 x ˙ 2 x ˙ 3 x ˙ 4
=
x 1 x 2 x 3 x 4
+
V
y = Cx (12) [ y 1 y 2
[ 1 0 0 0 0 0 1 0
]
x 1 x 2 x 3 x 4
.
If we define the feedback input to be u = −Kx, then Equation 11 becomes
x˙ = Ax + B(−Kx) = (A − BK)x.
By examining the above equation we can see that it is possible to arbitrarily place the system poles by selecting the feedback gain matrix K. (This is subject to some technical conditions which will not be addressed here. For a full discussion, look up the subject of controllability in any linear systems text.) This is referred to as full-state feedback control, since we assume all the states are available for measurement. Note that this works for discrete-time systems as well (simply replace ˙x by x(k + 1)).
The zero-order hold equivalent, using a sample period of Ts = 0.01 seconds, for Equations 11 and 12 has poles at z = 0.6682, 0.9806, 1, and 1.0230. This system is obviously unstable (since it has a pole located outside the unit circle). Using the Matlab command place, we obtain a feedback gain matrix,
which places the closed-loop system poles at z = 0.67, 0.96, and 0. 98 ± j 0 .01. You should check this.
4 Observer Design
The above approach has an implementation problem; we do not have all of the states available for measurement. A simple, and somewhat crude, fix would be to notice that the states we don’t have available (x 2 and x 4 ) are derivatives of the states we do have available (x 1 and x 3 ). Therefore, we could use numerical differentiation to obtain an estimate of the unmeasured states.
For example, denote the cart velocity by v(k). We can get a crude estimate of v(k) via,
v(k) ≈
p(k) − p(k − 1) T
where p(k) is the measured cart position and T is the sample period. This estimate is susceptible to noise.
However, we have quite a bit of information about the system which may allow us to do something more intelligent. We know the system, the system input, and the system output. We can construct a copy of the system given in Equations 11 and 12, driven by an extra term:
xˆ˙ = Aˆx + Bu + L(y − ˆy) (14) yˆ = C xˆ (15)
x_ = Ax + B u y = C x
y ^ = C ^x
x_^ = A x^ + B u + L(y y^ )
K
r u y
y ^
^x
Observer-Controller
Figure 3: Observer-Controller Configuration
−0.02 0 0.5 1 1.5 2 2.5 3 3.5 4
0
Position and Angle Responses (Measured and Estimated)
Position(m)
time(sec)
Measured Estimate
0 0.5 1 1.5 2 2.5 3 3.5 4
0
Angle(rad)
time(sec)
Measured Estimate
Figure 4: Response for Sample System Design
5 Lab Schedule: Week 1
The first week will focus on trying to get a simple state-feedback controller to work. Imple- menting a state-feedback controller requires measurements of all four states (cart position, cart velocity, pendulum angle and pendulum angular velocity). Use a simple differencing scheme (as in Equation 13) to estimate the unmeasured values.
It’s much easier to debug the system if the plant is stable. So we will first try to design a controller for driving the pendulum to the down position.
When you have that working you can start looking at trying to control to the pendulum-up position. Note that these two control problems will require different plant models, as the linearizations are taken at different operating points.
You will need to write Matlab scripts to do the design, analysis and simulations. Attach copies of these scripts to your prelab.
7 Lab Schedule: Week 3
The objective here is to design a reduced order estimator to estimate only the two velocities. The two measured states will be used directly in the state-feedback design.
Once you have balanced the inverted pendulum, you may wish to try the following experi- ments:
8 System Parameters
These parameters should be checked for your particular system. They may differ slightly.
Parameter Symbol Value Units Motor Torque Constant Km 0.00767 (^) AmpN m Gear-box Ratio Kg 3.7 N/A Motor Armature Resistance R 2.6 Ω Motor Pinion Radius r 0.00635 m Cart Mass mc 0.455 kg Pendulum Mass mp 0.210 kg Rotational Inertia I 0.00651 kg m^2 Half-Length of Pendulum l 0.305 m
Table 1: System Parameters for Cart/Pendulum System