Anda di halaman 1dari 15

Linear Control Systems - Laboration report

Inverted pendulum

Control of the position along a single axis of

a cart-pendulum system via feedback
Adam Kavanagh Coyne
Umeå University (
Course by Anton Shiraiev and Leonid Freidovich
Laboration by Staffan Grundberg, Leonid Freidovich and Kalle Prorok

October 24, 2016

1 Abstract
2 Introduction
A very commonly studied control problem is that of an inverted pendulum
mounted on a cart. Applied over two axes, the system is a control application
similar to balancing a pen on one’s finger; the pen will readily fall to the side
unless one moves the position of the finger adequately to ”catch” it. We will
model such a system over a single axis x, the finger being a cart of mass M and
the pen being a pendulum mounted on the cart, of length l and with a mass m
mounted on the end. The angle of deflection of the pendulum from the vertical
(positive in counterclockwise direction) is denoted θ(t). The task here will be
to choose the horizontal force applied to the cart F (t) along the axis.
As one can guess from the pen image, this is no easy task as the pen would
quickly fall to the side; θ(t) is unstable in an open loop system. Therefore if we
were to have a direct method of measuring θ(t) the task would be much easier.

3 Theory
First we will physically analyze the model of the system to derive equations of
motion. These can then be used in a non-linear state-space model[1, Inverted
Pendulum: System Modeling].

3.1 Equations of motion

Fig. 1: Inverted Pendulum

The following values are defined:

• M the mass of the cart
• l the length of the pendulum arm (considered massless and non-compressible)
• m the mass at the end of the pendulum
• x(t) the position of the cart along the x axis
• F (t) the force applied to the cart along the axis
• θ(t) the angle of the pendulum from the upwards vertical
• ω(t) the angular momentum of the pendulum
For the sake of clarity in equations, are also defined:
• λm = m
• b2 = l
where g is Earth’s gravitational constant.
Newton’s second law is applied; with N as the horizontal reaction force
applied by the pendulum, summing the forces in the free-body diagram for the
cart in the horizontal direction yields:
M ẍ + N = F (1)
The same horizontal analysis is performed on the pendulum mass:
N = mẍ + mlθ̈ cos θ − mlθ̇2 sin θ (2)
Substituting (2) into (1):
(M + m)ẍ + mlθ̈ cos θ − mlθ̇2 sin θ = F (3)
We then sum the vertical forces acting on the pendulum:
P sin θ − N cos θ − mg sin θ = −mlθ̈ − mẍ cos θ (4)
where P is the vertical reaction force applied by the pendulum. Furthermore,
summing the moments around the centroid of the pendulum gives us the fol-
lowing equation:
P l sin θ − N l cos θ = I θ̈ (5)
with I the mass moment of inertia of the pendulum. Equation (4) substituted
into equation (5) gets rid of the P and N terms:
(I + ml2 )θ̈ − mgl sin θ = −mlẍ cos θ
mgl sin θ − mlẍ cos θ
θ̈ = (6)
I + ml2
By further developing the above equations we find four equations:
ẋ = v
1 F 2 2
v̇ = λm +sin2 θ ( ml + ω sin θ − b sin θ cos θ)

θ̇ = ω
1 2 2 F
ω̇ = λm +sin2 θ [(1 + λm )b sin θ − ω sin θ cos θ − ml cos θ]

3.2 Linearisation
We can linearize the state-space model by applying small angle approximations;
to begin we shall consider an operating point where the pendulum is straight up,
therefore any deviation from the upwards position should be small; θ ≈ 0, ω ≈ 0.
cos θ ≈ 1 (7)
sin θ ≈ θ (8)
θ̇2 ≈ 0 (9)
After substituting the above into our nonlinear equations, we arrive at the lin-
earized equations of motion:

ẋ = v
v̇ F
= λ1m ( ml − b2 θ)
θ̇ = ω
ω̇ = λ1m [(1 + λm )b2 θ − F
ml ]

With u = F, a2 = gl (l + 1
λm ):

ẋ = v
1 u
v̇ = λm ( ml − b2 θ)
θ̇ = ω
1 u
ω̇ = a2 θ − λm ml
y = x

To express these equations as a state-space model such as

ẋ = Ax + Bu
y = Cx

the matrices A, B, C are as follows:

 
0 1 0 0
0 0 −mg/M 0
A =  0

0 0 1
0 0 (m+MMl
 1/M 
B =  
 0 
−1/(M l) 
C = 1 0 0 0

3.3 Transfer function

To find G0 (s), the transfer function of the linearized model, we need to calculate
C(sI − A)−1 B

 
s −1 0 0
0 s mg/M 0
sI − A =   (10)
0 0 s −1
0 0 − (m+M
1 1 glM glM 
s s2 s(gl+gM −lms2 ) s2 (gl+gM −lms2 )
0 1 glM glM 
gl+gM −lms2 s(gl+gM −lms2 ) 
(sI − A)−1 =  s

lms lm
0 0

−gl−gM +lms2 −gl−gM +lms2 
g(m+M ) lms
0 0 −gl−gM +lms2 −gl−gM +lms2
glM glM
C(sI − A)−1 = 1s s12 s(gl+gM −lms2 ) s2 (gl+gM −lms2 ) (12)

1 1 glM −1
C(sI − A)−1 D = + 2 (13)
s2 M s (gl + gM − lms2 ) M l
This gives us the corresponding transfer function G0 (s),

1 s2 − gl
G0 (s) = (14)
M s (s − gl −
2 2 g m
l M)

This can also be expressed

1 s2 − b2
G0 (s) =
M s2 (s2 − a2 )

where a2 = gl (1 + m
M) and b2 = gl .

4 Method
4.1 Single control loop
1. Controller design
We wish to synthesize a controller for the inverted pendulum, so as to
maintain the pendulum in an upright position. The controller is synthe-
sized through pole placement; the characteristic closed-loop polynomial
Ac l is predefined so as to have stable loops. To do so, we need to define
the polynomial zeros as real integers; here we will set all seven of them all
to -6.
Acl = A0 L + B0 P = (s + 6)7
The polynomials are given, and using the provided MATLAB function
paq.m polynomials P and L are determined:

P (s) 464s3 + 5083s2 + 16629s + 14253

C(s) = =
L(s) s3 + 42s2 − 152s − 1780

Figure 1: Simulink diagram modeled on calculated nominal model

Figure 2: Simulink diagram modeled on state-space equations (equivalent equa-

tions highlighted by area)

2. Simulation
Two forms of simulation will be run in Simulink, the first using the cal-
culated nominal model and the second by directly implementing the lin-
earized state-space equations found in part 3.2 (figures 1 and 2).
A step reference is provided as input for the cart position and the control
signal response and angle of the pendulum respectively are plotted over
time. The resulting curves are identical (figure 3).
The step responses are stable, however they present significant overshoot
and oscillations. It would seem that experimenting with different pole
values for Acl results, such as changing pole value, increasing the degree
of the polynomial or setting poles with non-zero imaginary parts, results
in a tradeoff between heavy oscillations with rapid stabilization versus
heavy overshoot with very long stabilization time.
3. Bode plots
The sensitivity function S0 (s) and the complementary sensitivity function

Figure 3: Step response of nominal model simulation and state-space equation

T0 (s) of the system are expressed as follows:

G0 (s)C(s)
S0 (s) = (15)
1 + G0 (s)C(s)
T0 (s) = (16)
1 + G0 (s)C(s)
The Bode magnitudes of these functions are plotted and shown in figure 4.
We can determine from these plots that the gain margin is -27.4 decibels
and the phase margin 22.5 degrees.

4.2 Cascade control

It is now assumed that we can continually measure the angle of the pendulum
θ(t). Logically, by incorporating this measurement in the control system we
can gain improve overall control. The previous task shall be repeated, this time
incorporating cascade control as we now have two sensor outputs to run off
(figure 5).

1. Inner controller
First is designed an internal-loop feedback controller for the open-loop
transfer function using polynomial pole-placement. To do so, we need to
find the first ”half” of the nominal model, a transfer function G02 (s) that
takes the same input as the original model but outputs θ(t). From this we

Figure 4: Bode plots for sensitivity functions of the system

Figure 5: Cascade controller

can create a controller C02 (s) using the same method as in section 4.1.1
to obtain the full inner loop.
We will begin by finding G02 (s), for G0 (s) = G01 (s)G02 (s) with Θ(s) =
G02 (s)U (s) the Laplace image of θ(t). By applying the Laplace transform
to the linearized equations relating θ, θ̈ and F , we obtain:
U (s)
s2 Θ(s) − sθ(0) − θ̇(0) = a2 Θ(s) −
λm ml
Considering θ(0) = θ̇(0) = 0, from this we can obtain the equation:
Θ(s) = − U (s)
M l(s2 − a2 )
Therefore we can define:
G02 (s) = −
M l(s2 − a2 )
As above, using polynomial pole placement via the equation Acl,02 =
A02 L02 +B02 P02 and assigning Acl,02 = (s+350)3 , we obtain the following
controller for the inner loop:
P02 −1.84 · 105 s − 2.14 · 107
C02 = =
L02 s + 1050
Different values for zeroes were simulated apart from Acl,02 = (s + 350)3 ;
350 would appear to be approximately the minimum absolute value for
zeroes in order to overcome a steady-state error. Increasing the absolute
value of zeroes further results in stronger oscillations. The step response
for this internal loop is presented as figure 6.
2. Outer controller
From the inner loop we can calculate a closed-loop transfer function:
G02 (s)C02 (s)
Cin (s) = 1−G 02 (s)C02 (s)
. Calculations using MATLAB yield the follow-
ing expression of this transfer function:
1.838 · 105 s + 2.145 · 107
Cin (s) =
0.5s3 + 525s2 + 1.837 · 105 s + 2.144 · 107
The corresponding system can be seen in figure 7.
Finally we design the outer controller for the cascade control system. Con-
sidering G0 (s) = G01 (s)G02 (s) and the given values for G0 (s) and G02 (s),
we can easily find:
l(s2 − b2 )
G01 (s) = −
We can obtain a transfer function Gf ull (s) = Cin (s)G01 (s) modeling the
whole plant and the inner-loop controller, the numerical expression of this
1.838 · 105 s3 + 2.145 · 107 s2 − 1.805 · 106 s − 2.106 · 108
Gf ull (s) =
0.5s5 + 525s4 + 1.837 · 105 s3 + 2.144 · 107 s2

Figure 6: Step response of inner loop control system (controlling θ)

Figure 7: Cascade controller with simplified inner loop

Figure 8: Equivalent simple control loop from cascade controller

3. Final control system
The final obtained system diagram (figure 8) is identical to a single-loop
control system. We can use pole placement, as before, to determine an ad-
equate controller C01 (s). Initially, controller synthesis was performed via
pole placement, as with every other controller above. However, possibly
in relation to the very high order of the nominal model Gf ull (s), it seemed
impossible to find poles resulting in a system without intense oscillations
which eventually diverged from the reference signal - using pole placement
resulted in an unstable system.
In lieu of this, we can attempt to implement a simple PID controller.
Considering the inner control loop Cin stabilizing θ, it is possible this
could be an adequate controller, despite its inherent simplicity.
A PID controller is created and tuned using MATLAB’s PID Tuner soft-
ware. The stabilizing controller is expressed with the compensator for-

1 N
C01 (s) = P + I +D
s 1 + N 1s

or alternatively, in a form expressing polynomial coefficients:

(P + DN )s2 + (P N + I)s + IN
C01 (s) =
s2 + N s
with the following constants:

P = −0.11
I = −0.002
D = −0.15
N = 2.17

There is now feedback on both signals, position of the cart and angle of
the pendulum.
A step reference is provided as input for the cart position and the control
signal response and angle of the pendulum are plotted over time (figure
The step response yields significantly less overshoot using cascade control
compared to single-loop control, and no oscillations.

4.3 Observer implementation

So as to control the cart more intelligently in relation to the pendulum angle an
observer can be created to estimate the value of all four state variables, while
only having direct access to one.

Figure 9: Step response of cascade controller on x with internally stabilized θ

Figure 10: Simple state feedback model in Simulink

We will begin by using the state-space model of the system using the matrices
A, B, C found above, adding feedback gain K and N̄ the reference scaling factor
(a precompensator for steady-state error) to implement state feedback (figure
K will be set using MATLAB’s place function with arbitrary poles −2 +
1i, −2 − 1i, −5, −6. N̄ is found using the rscale function provided in [1]. The
step response of this system is then measured (figure 11).
However this control system implies that we have direct access to vector x
(the state variables), which is nearly impossible in real-world implementations.
It is more common that a single state variable is measured. In order to recon-
struct the other variables from the single variable y, we can create an observer.
The block diagram is shown in figure 12; here we require matrices Â, B̂ and
Ĉ which, for a perfect model, would be identical to A, B and C, as well as

Figure 11: Step response of state feedback model shown in figure 10

observer gain L.
Our simulation will consider  = A, B̂ = B, Ĉ = C and L is calculated
using MATLAB’s place, providing arbitrary observer poles −40, −41, −42, −43.
The poles are chosen an order of magnitude greater than the controller poles
so that the observer response is sufficiently fast. The step response is shown in
figure 13

5 Discussion
5.1 Simple controller
Overall, it would seem that a single control loop, at least the one implemented,
is stable but not very efficient at stabilizing the system. The step responses for
both the transfer function implementation of the system and the full Simulink
implementation of the linearized state-space equations yielded identical responses
for the same controller - they are equivalent representations of the plant.

5.2 Cascade control

Increased efficacy was gained with the implementation of cascade control. The
internal controller on the pendulum angle, and the 5th-order transfer function
that represented the corresponding plant would make the final outer controller a
simpler task to implement. This may be the reason a high-order controller found
by pole placement was unstable, and why PID control was largely sufficient to
complete cascade control.

Figure 12: State-space system with observer feedback in Simulink

Figure 13: Step response of system with observer feedback

5.3 Observer control
Both step responses are identical for our state-space simulation, with or without
observer control. This would be because of our perfect plant model - the state
variables found using the observer are calculated identically to those within the

6 Conclusion
All necessary laboration tasks were completed - the laboration was educational
as to the pole placement technique and the nature of state-space and observer

[1] Bill Messner, Dawn Tillbury, Control Tutorials for Matlab and Simulink,, University of Michigan, 2011