Inverted Pendulum Cart
Inverted Pendulum Cart
Inverted Pendulum Cart
(ESEIAAT)
January 2018
Martínez Ramírez, Erik January 2018
Abstract
Stabilization of unstable systems is a very important area in the automatic control
discipline and it is needed in a wide range of applications, some examples being missile
guidance or stabilization of a biped robot.
The main objective of this study is to research the single inverted pendulum in order to
develop a controller for it. Two different alternatives are considered in this study in
order to stabilize the pendulum in its upright position while keeping the cart oscillating
around a desired position.
The first one is a full-state feedback controller which can have its characteristics
modified changing the placement of the dominant poles.
The second controller is a cascaded PID controller. This controller can be tuned with
different parameters to modify its response. The controller is stable in computer
simulation, although it has a worse response that the full-state feedback controller and
it is not stable in the laboratory system.
The results of the full-state feedback controller turned out to be very stable, precise
and controllable.
- iii -
Martínez Ramírez, Erik January 2018
Acknowledgments
I would like to especially thank my director Joseba Quevedo for his enthusiasm,
motivation, support and passion transmitted during the project. It has been a major
encouragement during the academic quarter. I also want to thank Ramon Perez for his
time and help regarding several aspects of the project. Finally, my most since gratitude
to my girlfriend and my family for their understanding and support during the project
and during the whole career.
- iv -
Martínez Ramírez, Erik January 2018
Contents
Abstract ........................................................................................................................................ iii
Acknowledgments ........................................................................................................................iv
Contents .........................................................................................................................................v
List of Figures ...............................................................................................................................vii
Abbreviations................................................................................................................................ix
Introduction ...................................................................................................................................x
Aim ............................................................................................................................................. x
Scope ......................................................................................................................................... xi
Requirements ........................................................................................................................... xii
Justification and utility ............................................................................................................ xiii
1. State of the art ....................................................................................................................... 1
1.1 Planar inverted pendulum................................................................................................... 1
1.2 Rotary inverted pendulum .................................................................................................. 2
1.3 2DOF inverted pendulum .................................................................................................... 3
1.4 Real-life applications ........................................................................................................... 4
2. Characteristics of the inverted pendulum............................................................................. 5
3. Linearization of the system ................................................................................................... 8
4. State observer design .......................................................................................................... 14
4.1 Pole placement ............................................................................................................... 14
4.2 Observer design .............................................................................................................. 17
5. PID controller design............................................................................................................ 24
5.1 PID controller .................................................................................................................. 24
5.2 Cascaded PID .................................................................................................................. 25
5.3 Frequency method.......................................................................................................... 27
5.4 Routh-Hurwitz stability criterion .................................................................................... 28
6. Laboratory tests ................................................................................................................... 35
6.1 Laboratory environment ................................................................................................. 35
6.2 Full-state observer tests ................................................................................................. 37
6.3 Cascaded PID tests .......................................................................................................... 42
7. Future lines of research ....................................................................................................... 44
8. Planning ................................................................................................................................ 45
8.1 Brief task description ...................................................................................................... 45
8.2 Preliminary Gantt chart .................................................................................................. 46
9. Budget .................................................................................................................................. 47
-v-
Martínez Ramírez, Erik January 2018
- vi -
Martínez Ramírez, Erik January 2018
List of Figures
Figure 1 Single inverted pendulum schematic .............................................................................. 2
Figure 2 Rotary inverted pendulum schematic ............................................................................. 3
Figure 3 2DOF inverted pendulum ................................................................................................ 3
Figure 4 Schematic of the forces applied to the inverted pendulum ............................................ 6
Figure 5 Schematic of the laboratory model ................................................................................. 7
Figure 6 Model of the pendulum in Simulink ................................................................................ 9
Figure 7 Comparison of the responses of both models around the stable position .................... 11
Figure 8 Open-loop response to non-zero initial condition ......................................................... 12
Figure 9 Full-state feedback system schematic .......................................................................... 14
Figure 10 Response of the cart for 𝑥1 = 0m and 𝑥2 = 0.01rad ................................................ 16
Figure 11 Response of the pendulum for 𝑥1 = 0m and 𝑥2 = 0.01rad ...................................... 16
Figure 12 Response of the cart for 𝑥1 = 0m and 𝑥2 = 0.01rad ................................................ 17
Figure 13 Response of the pendulum for 𝑥1 = 0m and 𝑥2 = 0.01rad ...................................... 17
Figure 14 Schematic of a full-state feedback system with an observer ...................................... 18
Figure 15 Response of the cart with 𝑥1 = 0m and 𝑥2 = 0.1rad................................................ 19
Figure 16 Response of the pendulum with 𝑥1 = 0m and 𝑥2 = 0.1rad ...................................... 20
Figure 17 Response of the cart with 𝑥1 = 0m and 𝑥2 = 0.1rad................................................ 21
Figure 18 Response of the pendulum with 𝑥1 = 0m and 𝑥2 = 0.1rad ...................................... 21
Figure 19 Cart position change due to step inputs ..................................................................... 22
Figure 20 Pendulum oscillations due to the change of position of the cart ................................ 22
Figure 21 Cart position change due to step inputs ..................................................................... 23
Figure 22 Pendulum oscillations due to the change of position of the cart ................................ 23
Figure 23 PID loop schematic ...................................................................................................... 24
Figure 24 Schematic of a cascaded PID controller ...................................................................... 26
Figure 25 Bode diagram of the response of the pendulum of the linearized system.................. 27
Figure 26 Response of the pendulum to the PID with small values with 𝑥2 = 0.1rad ............... 30
Figure 27 Bode diagram of the open-loop system ...................................................................... 30
Figure 28 Response of the pendulum to the PID with improved phase margin values............... 31
Figure 29 Response of the pendulum to the PID with 𝐾 = 10 𝑥2 = 0.1rad .............................. 32
Figure 30 Response of the pendulum to the PID with optimal values with 𝑥2 = 0.1rad ........... 33
Figure 31 Bode diagram of the system with the pendulum and the PID .................................... 33
Figure 32 Response of the cart with initial conditions 𝑥1 = 0m and 𝑥2 = 0.01rad .................. 34
Figure 33 Response of the pendulum with initial conditions 𝑥1 = 0m and 𝑥2 = 0.01rad ........ 34
- vii -
Martínez Ramírez, Erik January 2018
- viii -
Martínez Ramírez, Erik January 2018
Abbreviations
UPC – Polytechnic University of Catalonia
I/O – Input/Output
- ix -
Martínez Ramírez, Erik January 2018
Introduction
Aim
The aim of the project is to design different controllers that are able to stabilize a
highly unstable system, as is the inverted pendulum and to observe which ones
perform the best and draw conclusions.
-x-
Martínez Ramírez, Erik January 2018
Scope
The scope of the project is to study and design the control system of an unstable
system, in this case an inverted pendulum. The first step will be to simulate different
alternatives on a computer with a modeled system of the reality. After that, once the
simulations are stable, the control system will be used on the real system of the
inverted pendulum in the laboratories of the UPC. The final goal is to be able to
stabilize the pendulum in its upright position while keeping the cart oscillating around
a desired position, to evaluate the different alternatives and to draw conclusions.
The following list is a short description of the aspects developed in the project:
- xi -
Martínez Ramírez, Erik January 2018
Requirements
• The different designed controllers must make the inverted pendulum stable.
• Stability must be achieved in less than 10 seconds.
• The oscillation of the pendulum must not exceed 3 degrees of amplitude after
stability is reached
• The static error of the position of the cart must be less than 0.02 meters after
stability is reached.
• The position of the cart must not oscillate more than 0.05 meters after stability
is reached.
- xii -
Martínez Ramírez, Erik January 2018
The main challenge will be to use the simulated control system in the laboratory. Some
elements might not be correctly modeled such as friction or perturbations and noise
might appear.
- xiii -
Martínez Ramírez, Erik January 2018
This system has two positions of equilibrium, one of them is stable while the other is
unstable. The stable position corresponds to the pendulum pointing downright.
Releasing the pendulum from any position other than exactly straight up, makes the
pendulum fall and oscillate around the stable position until it comes to rest due to
friction forces. Therefore, the stable position requires no control and it is not
interesting from a control point of view.
The unstable position corresponds to the pendulum pointing upright and requires a
controller to maintain this position. The main objective of the inverted pendulum
control is to maintain the unstable position when the pendulum starts from the
unstable equilibrium position.
For the single inverted pendulum there are two types of controllers. The first is a
feedforward controller the objective of which is to do the swing-up phase and change
the pendulum’s position from the stable position to the upright position. The second is
a linear feedback controller with a full-state observer in order to keep the pendulum
stabilized in the upright position[1].
There is also neural network control, where after several tries for learning the
controller is able to stabilize the system. The algorithm used for the learning process is
the back-propagation algorithm[2].
-1-
Martínez Ramírez, Erik January 2018
For the double inverted pendulum, the controller is developed in three steps. First,
swing-up the first pendulum using energy control method. Second, to swing-up the
second pendulum use the same method while stabilizing the first pendulum using
sliding mode control method. Lastly, stabilize both pendulums upright with the sliding
mode control method[3].
There is also a neural network controller that self-tunes a PID. To do this, the squared
error between the output and the desired value is the function that the neural
network tries to minimize[4].
In these previous examples, the pendulum can only fall in a plane. The inverted
pendulums of these projects can be required to only maintain balance starting from an
unstable equilibrium position or be able to achieve the unstable position by itself.
-2-
Martínez Ramírez, Erik January 2018
-3-
Martínez Ramírez, Erik January 2018
The most prevalent example of the inverted pendulum is humans. People need to
make constant adjustments to maintain the upright position of the body whether
standing, walking or running. Another simple example is balancing brooms with a hand
or a finger.
The inverted pendulum has been employed in various devices. For instance, it was the
central component of early seismometers because any disturbance caused the
pendulum to oscillate and the response was measurable.
Some two-wheeled personal transports that offer higher maneuverability are designed
based on inverted pendulum models.
The inverted pendulum is also related to rocket and missile guidance, where the center
of gravity is located behind the center of drag causing aerodynamic instability that
need to be corrected in order to not start spinning out of control. It is also related to
the balance of a biped humanoid robot, which has similar characteristics as previously
mentioned with humans.
-4-
Martínez Ramírez, Erik January 2018
An inverted pendulum is often formed by a cart that can move freely alongside a guide
and a pendulum that can rotate freely with the center of rotation in the cart. The only
variable that can be controlled is the force applied to the cart. The pendulum must be
actively balanced in order to remain upright. This can be done by several different
ways:
The inverted pendulum is heavily used as benchmark for testing different control
strategies such as PID controllers, state space representation, neural networks, fuzzy
control, etc.).
Considering the pendulum alone, it has two positions of equilibrium, one stable and
one unstable. The aim is to make the unstable position stable with a control system,
even if pushed with some kind of perturbation. In a real scenario the guide in which
the cart moves is finite, in order to represent this, both the position of the cart and the
position of the pendulum must be made stable.
-5-
Martínez Ramírez, Erik January 2018
Defining the variables as cart position (𝑥1 ), pendulum position relative to the
horizontal (𝑥2 ), cart speed (𝑥3 ) and angular speed of the pendulum (𝑥4 ). The dynamic
equations of the system are:
Where:
𝑚𝑐 : cart mass
𝑚𝑝 : pendulum mass
𝑉 : normal force
𝑔 : gravity force
𝐽 : moment of inertia
-6-
Martínez Ramírez, Erik January 2018
The forces applied to this system are shown in Figure 4. The pendulum rotates in the
vertical plane and the rotation axis is located in the cart which moves along the guide
impulsed by the power unit.
Figure 5 represents the scheme of the laboratory model. It can also work as a normal
pendulum or a gantry crane.
-7-
Martínez Ramírez, Erik January 2018
The inverted pendulum is a non-linear system and it must be linearized around the
unstable equilibrium position, which is when the pendulum is in its upright position, to
be able to be studied.
Using the equations provided in the previous chapter and considering a linear
expression for the cart friction (𝑇𝑐 = 𝐹𝑐 𝑥3 ) and for the friction torque (𝐷𝑝 = 𝑓𝑝 𝑥4 ), the
pendulum model can be represented by the following system of equations:
𝑥1̇ = 𝑥3
𝑥2̇ = 𝑥4
Where
𝐽
𝑎= − 𝑙2
𝑚𝑐 + 𝑚 𝑝
µ = 𝑙(𝑚𝑐 + 𝑚𝑝 )
The system can be represented in Simulink using the previous system of equations.
The result is something similar to the model provided by the manufacturers of the real
system without the non-linear expression of the friction force. The model of the
pendulum in Simulink can be observed in Figure 6.
-8-
Martínez Ramírez, Erik January 2018
The force applied to the cart is proportional to the input and normalized between 1
and −1 with the constant 𝑀 and limited by a saturation between 𝑈𝑚𝑀 and – 𝑈𝑚𝑀.
This value limits the maximum force that can be applied to the system and it is very
important to keep this in mind because in a computer simulation any input value will
work as long as the system is theoretically stable, but that will not happen in the real
system.
𝑚𝑐 = 1.12 𝑘𝑔
𝑚𝑝 = 0.095 𝑘𝑔
𝑙 = 0.0167903 𝑚
𝐽 = 0.0075 𝑚4
𝐾𝑔
𝐹𝑐 = 0.75 𝑠
𝐾𝑔𝑚2
𝑓𝑝 = 0.0038 𝑠
𝑚
𝑔 = 9.81 𝑠2
𝑀 = 22.03
𝑈𝑚 = 0.5
In the real system the initial positions (𝑥1 = 0 and 𝑥2 = 0) are defined by the
positions of the cart and the pendulum when the simulation starts. This means that
any reset will also reset the initial conditions to the actual positions of the cart and
pendulum. For simplicity, since the inverted pendulum will start the simulation in its
-9-
Martínez Ramírez, Erik January 2018
upward position, this will be the initial condition for the model, 𝑥2 = 0. The positive
rotation of the pendulum is counter-clock wise.
To linearize the model the initial conditions must be established. For this case, the
initial position of the cart can be any constant, for simplicity it will be 𝑥1 = 0, the initial
condition of the pendulum will be 𝑥2 = 0 as explained in the previous paragraph and
both velocities will be 𝑥3 = 0 and 𝑥4 = 0.
The linearization can be done with Simulink and this translates into the following
space-state matrices:
0 0 1 0
0 0 0 1
A
0 - 0,4480 - 0.5891 0,0085
0 26,6835 1,6790 - 0,5067
0
0
B
0.7855
2.2387
1 0 0 0
0 1 0 0
C
0 0 1 0
0 0 0 1
0
0
D
0
0
To check if the linearization is correct, the same model can be linearized around the
stable position, this is the pendulum in its downright position, so the response of the
linearization can be compared with the response of the non-linear system. The
linearization of the upright position cannot be compared because it is unstable,
meaning that the pendulum will rapidly fall and oscillate on the non-linear model and
in the linearized model will go to infinity since the model is not linearized at the right
point.
Doing this, new matrices are obtained with the same values and only a few sign
changes, which are:
- 10 -
Martínez Ramírez, Erik January 2018
0 0 1 0
0 0 0 1
A1
0 - 0,4480 - 0.5891 - 0,0085
0 - 26,6835 - 0,5067
- 1,6790
0
0
B1
0.7855
2.2387
1 0 0 0
0 1 0 0
C1
0 0 1 0
0 0 0 1
0
0
D1
0
0
Figure 7 Comparison of the responses of both models around the stable position
- 11 -
Martínez Ramírez, Erik January 2018
The comparison of the responses to a step input can be seen in Figure 7 where barely
any difference can be observed. From this, it can be concluded that both linearizations
of the model are correct.
The eigenvalues of the matrix A are the poles of the system. In this case, these are:
𝑝1 = 0
𝑝2 = 4.9065
𝑝3 = −5.4417
𝑝4 = −0.5606
The poles are the roots of the denominator of the transfer function. The transfer
function can be obtained from the space-state matrices but it is not needed. The
locations of the poles determine whether the system is stable and how well the system
performs. Real parts correspond to exponentials and imaginary parts correspond to
sinusoidal values. In this case, one pole has positive real part, which means that the
system is unstable in open-loop.
This instability can be observed in Figure 8, where an initial position of 𝑥2 = 0.01 𝑟𝑎𝑑
causes the loss of the unstable position of equilibrium. Since the model is linearized,
- 12 -
Martínez Ramírez, Erik January 2018
the response tends to go to infinity. With the non-linear model it would go to the
stable position of equilibrium and oscillate around it.
This linearization will be the starting point to stabilize the system with different
methods.
- 13 -
Martínez Ramírez, Erik January 2018
A state observer is a system that provides an estimate of the internal state of a given
real system. The only measurements that it takes are the input and the output of the
system in real time. The benefit of this method is that it allows to know the physical
state of the system even if this is not observable, which happens quite often in all
kinds of systems.
𝑢 = −𝐾𝑥
And therefore, the state-space equations for the closed-loop feedback system are:
𝑥̇ = (𝐴 − 𝐵𝐾)𝑥
𝑦 = (𝐶 − 𝐷𝐾)𝑥
- 14 -
Martínez Ramírez, Erik January 2018
The stability of the closed-loop feedback system is determined by the location of the
poles of the matrix (𝐴 − 𝐵𝐾). Since the matrices (𝐴) and (𝐵𝐾) are both four-by-four,
there will be four poles for the system. By choosing an appropriate 𝐾 matrix, these
poles can be placed anywhere they need to be. This 𝐾 matrix can be calculated with
MATLAB using the function place and specifying the desired poles.
In this case, several 𝐾 values need to be tested. Having too small 𝐾 values could lead
to a too slow response and having too high 𝐾 values could lead to having an input
signal higher than the saturation of the real system. Both cases need to be avoided in
order for the system to be stable.
The first two poles are always placed at the same location and the other two are
placed five times farther away, so they are not dominant.
In case that the position of the cart had to be kept at a certain point, a constant, often
called 𝑁𝑏𝑎𝑟 should be calculated as an offset to the reference. This is not needed in
this case, since the position of the cart is irrelevant and is the variation of its position
and speed what matters.
𝑝1 = −2
𝑝2 = −2.01
𝑝3 = −10
𝑝4 = −10.01
- 15 -
Martínez Ramírez, Erik January 2018
𝑝1 = −4
𝑝2 = −4.01
𝑝3 = −20
𝑝4 = −20.01
The responses of these poles can be found in the Figures 12 and 13.
- 16 -
Martínez Ramírez, Erik January 2018
- 17 -
Martínez Ramírez, Erik January 2018
The observer is basically a copy of the plant. It has the same input and almost the same
differential equation. An extra term compares the actual measured output 𝑦 and the
estimated output 𝑦̂. This causes that the estimated states 𝑥̂ to approach the values of
the actual states 𝑥. A schematic of the observer that will be implemented can be found
in Figure 14.
Since the dynamics of the observer need to be much faster than the system itself, the
poles need to be placed at least five times farther to the left than the dominant poles
of the system. In this case, they will be placed ten times to the left.
As previously said, the only variables known are the positions of the cart and the
pendulum, which means that the matrix 𝐶 needs to be changed to reflect that the
information of the velocities is unknown. From now on:
1 0
0 1
C
0 0
0 0
- 18 -
Martínez Ramírez, Erik January 2018
The velocities are the derivate of the positions and this can be simulated in Simulink,
however is not information measured from the model and after trying this route the
result was that the derivatives were too unreliable and not precise enough to stabilize
the system.
Using poles ten times faster to calculate the matrix 𝐿 when the dominant poles of the
matrix 𝐾 are at −2, the following is obtained:
39.6387 0.0171
1.6898 39.7255
𝐿=
381.2327 0.0527
65.9157 411.2417
The response of the system with the observer of the previous example can be
observed in Figures 15 and 16.
- 19 -
Martínez Ramírez, Erik January 2018
Several dominant poles have been tested successfully, from 𝑝 = −1.5 to 𝑝 = −4. The
idea behind this is to have different options to test in the laboratory. Higher absolute
values for the poles mean that the control will be better at the expense of a higher
control force. Since the system has saturation for this, some limit should be reached to
balance both.
Again, using poles ten times faster to calculate the matrix 𝐿 when the dominant poles
of the matrix 𝐾 are at 𝑝 = −4, the following is obtained:
79.6414 0.0166
1.6906 79.7228
𝐿=
1562.332 0.5457
133.3271 1595.511
The response of the system with the observer of the previous example can be
observed in Figures 17 and 18.
- 20 -
Martínez Ramírez, Erik January 2018
The responses corresponding to the controller designed with the dominant poles at
𝑝 = −4 are faster and oscillate less in steady state.
As previously said, it is not needed to stabilize the cart position to a different position
that zero. However, this can be done creating a step input. There is proportionality
between the step size and the cart position. With trial and error, it is found that the
ratio is 1𝑚 for a step of 20.25 units for the controller with dominant poles at 𝑝 = −2.
With this is mind and with different steps at different times, the position of the cart
can be controlled easily.
- 21 -
Martínez Ramírez, Erik January 2018
An example of controlling the position of the cart with different steps at different
times can be observed in Figures 19 and 20.
Trying the same with the controller with dominant poles at 𝑝 = −4 it is found that the
relation is 1𝑚 for a step of 320 units. The responses of this system can be found in
Figures 21 and 22. Since the steps are considerably larger in this case, the second step
has been divided into two smaller steps, so the system does not saturate. The
response is much faster and less oscillating in steady state, although saturation
problems start appearing.
- 22 -
Martínez Ramírez, Erik January 2018
- 23 -
Martínez Ramírez, Erik January 2018
The response of the proportional term is proportional to the error and if there is no
error, there is no proportional response.
The integral term accounts for past values and integrates them over time. When the
error becomes zero, the integral term will cease to grow.
The derivative term is an estimate of the future trend of the error based on its current
rate of change. This means that the derivative term alone cannot bring the error down
to zero. This is why it is also called anticipatory control. Implementations of controllers
that include a derivative action tend to also include a low-pass filtering for the
derivative term to limit high-frequency gain and noise.
Where 𝐾𝑃 , 𝐾𝐼 and 𝐾𝐷 denote the coefficients of the respective terms. In the standard
form:
- 24 -
Martínez Ramírez, Erik January 2018
𝐾𝑃
𝐾𝐼 =
𝑇𝐼
𝐾𝐷 = 𝐾𝑃 𝑇𝐷
The balance of these effects is achieved by loop tuning to produce the optimal control
function. The terms must be derived for each application, since they depend on the
response characteristics of the complete loop. Even though there are only three
parameters, this is a difficult problem because it must satisfy complex criteria within
the limitations of the PID.
Designing and tuning a PID can be hard in practice if multiple and often conflicting
objectives are to be achieved. Often, initial designs need to be adjusted repeatedly
until the controller performs as desired.
Also, some processes have a degree of non-linearity and parameters that work well at
steady state do not work in the transitory regime.
If the PID controller parameters are chosen incorrectly, the controlled process can be
unstable and is limited only by saturation or mechanical breakage.
- 25 -
Martínez Ramírez, Erik January 2018
When multiple sensors are available for measuring conditions in a controlled process,
a cascade control system can often perform better than a traditional single-
measurement controller.
A cascade control system cannot solve every feedback control problem, but it can
prove advantageous under the right circumstances:
• The inner loop has influence over the outer loop. The actions of the inner
controller must affect the primary process in a predictable and repeatable way
or else the primary controller will have no mechanism for influencing its own
process.
• The inner loop is faster that the outer loop. This allows the secondary controller
enough time to compensate for inner loop disturbances before they can affect
the primary process.
• The inner loop disturbances are less severe than the outer loop disturbances.
Otherwise, the secondary controller will be unable to apply consistent
corrective efforts to the primary process.
The first process that needs to be tuned is the inner process. In this case, it is the
pendulum position. In order to do this, the linearized system will be used again.
- 26 -
Martínez Ramírez, Erik January 2018
Figure 25 Bode diagram of the response of the pendulum of the linearized system
𝐾𝐼
𝐷(𝑗𝑤) = 𝐾𝑃 + 𝑗 (𝐾𝐷 𝑤 − ) = |𝐷(𝑗𝑤)|/𝜃
𝑤
The problem is to choose 𝐷(𝑤) (i.e. 𝐾𝑃 , 𝐾𝐼 and 𝐾𝐷 ) so:
𝐷(𝑗𝑤)𝐺(𝑗𝑤) = 1/180º + 𝜙𝑚
Where:
𝜃 = −180º + 𝜙𝑚 −/𝐺(𝑗𝑤)
𝜙𝑚 = 𝑝ℎ𝑎𝑠𝑒 𝑚𝑎𝑟𝑔𝑖𝑛
𝐾𝐼
𝐾𝑃 + 𝑗(𝐾𝐷 𝑤1 − ) = |𝐷(𝑗𝑤1 )|(cos 𝜃 + 𝑗 sin 𝜃)
𝑤1
Therefore,
cos 𝜃
𝐾𝑃 = |𝐷(𝑗𝑤1 )| cos 𝜃 =
|𝐺(𝑗𝑤1 )|
𝐾𝐼 sin 𝜃
𝐾𝐷 𝑤1 − =
𝑤1 |𝐺(𝑗𝑤1 )|
- 27 -
Martínez Ramírez, Erik January 2018
These two last equations are the design equations. For a given plant, choosing the
frequency 𝑤1 and the phase margin 𝜙𝑚 only determines 𝐾𝑃 . However, 𝐾𝐷 and 𝐾𝐼 are
not determined. These results lead to two equations with three unknowns.
Generally, there must be a proportion between the derivative action and the integral
action so that:
𝑇𝐼
𝑇𝐷 =
4
In practice, feedback amplifiers must be designed with phase margins higher than 0º,
even though amplifiers with phase margins of 1º are theoretically stable. The reason is
that there are a lot of practical factors that can reduce the phase margin below the
theoretical minimum. Therefore, 45º degrees is considered as the minimum for
operational amplifiers and 60º is what is often used. In this case, 80º is what will be
used as phase margin.
Now, for a given frequency, a set of PID parameters can be calculated. The idea is to
test these parameters in a simulation and check which ones perform better. After that,
the new model of PID controller and pendulum will be linearized. After that, the PID
parameters of the outer loop can be determined using the same method as the one
used with the inner loop.
This method does not work with an unstable system. Having a pole in the right half of
the complex plane makes the concepts of phase margin and gain margin not enough to
guarantee the stability of the system and a more elaborate study would be needed
with a method related to the Nyquist stability criterion. Therefore, this method would
need to be modified considering this fact.
To do this test, the transfer function of the pendulum is needed. This is obtained from
the matrices of the linearized system using the MATLAB functions:
𝜃(𝑠) 2.239 𝑠
= 𝑡𝑓(𝑛𝑢𝑚, 𝑑𝑒𝑛) = 3
𝑈(𝑠) 𝑠 + 1.096 𝑠 2 − 26.4𝑠 − 14.97
- 28 -
Martínez Ramírez, Erik January 2018
The aim of this is to design a PID controller. Considering that the transfer function of a
PID is:
𝐾𝐷 𝑠 2 + 𝐾𝑃 𝑠 + 𝐾𝐼
𝑃𝐼𝐷(𝑠) =
𝑠
Therefore, the denominator of the system with feedback is:
𝐾𝐷 𝑠 2 + 𝐾𝑃 𝑠 + 𝐾𝐼
𝐷(𝑠) = 𝑠 3 + 1.096 𝑠 2 − 26.4𝑠 − 14.97 + 2.239 𝑠( )
𝑠
According to the criterion, it is needed that all the coefficients in 𝐷(𝑠) have the same
sign and also that all the terms of the first column of the Routh table have the same
sign too.
s3 1 2.239 K P 26 .4
s 2
1.096 2.239 K D 2.239 K I 14 .97
s 1
2.239 K P K D 2.454 K P 59 .11K D 2.239 K I 13 .964
2
0
s 0
2.239 K I 14 .97
From the polynomial some conditions can be obtained. Since the first coefficient is
positive, the rest must also be positive, giving the following restraints:
𝐾𝑃 > 11.79
𝐾𝐷 > −0.49
𝐾𝐼 > 6.68
𝐾𝑃 = 12.8
𝐾𝐷 = 0.5
𝐾𝐼 = 7
- 29 -
Martínez Ramírez, Erik January 2018
Figure 26 Response of the pendulum to the PID with small values with 𝑥2 = 0.1rad
As it can be observed in Figure 26, the controller stabilizes the pendulum but does not
meet any supplementary requirements. This makes the response rather slow. A second
controller based on the previous one can be designed in order to improve the
response. The objective is to achieve a good phase margin.
Assuming a filter for the derivative action of the PID that cuts any frequency above
𝑤 = 200 rad/s, the PID transfer function is the following:
0.5𝑠 2 + 12.8𝑠 + 7
𝑃𝐼𝐷(𝑠) =
1
𝑠(1 + 200 𝑠)
- 30 -
Martínez Ramírez, Erik January 2018
The bode diagram of this transfer function can be found in figure 25. From there it can
be observed that there is a maximum phase margin of 50º if the transfer function is
multiplied by a constant equivalent of 35 dB. This constant is:
35
𝐾 = 1020 = 56
Then, a set of new and much more stable and fast parameters are:
56 · 𝐾𝑃 = 716.8
56 · 𝐾𝐷 = 28
56 · 𝐾𝐼 = 392
The response of this new controller can be seen in Figure 28. The system becomes
stable after only 0.25 seconds.
Figure 28 Response of the pendulum to the PID with improved phase margin values
However, the previous calculated values are quite big, and this could amplify
excessively the noise in the laboratory. A constant value of 𝐾 = 10 should also
improve the speed and the stability of the response. Therefore:
10 · 𝐾𝑃 = 128
10 · 𝐾𝐷 = 5
10 · 𝐾𝐼 = 70
- 31 -
Martínez Ramírez, Erik January 2018
The response can be found in Figure 29. The response and the speed of the controller
are still much better than the first controller.
One last PID controller can be calculated using the SIMULINK tool of auto tuning.
Adjusting the parameters with a slow enough response as to not have big values for
the parameters the following optimal values are automatically obtained:
𝐾𝑃 = 51.18
𝐾𝐷 = 6.251
𝐾𝐼 = 103.4
𝑁 = 1528
𝐾𝐼 𝑁
𝑃𝐼𝐷(𝑠) = 𝐾𝑃 + + 𝐾𝐷
𝑠 1
1+𝑁𝑠
The response of this last controller can be found in Figure 30. The response is a bit
slower than in the previous examples but the overshoot is considerably reduced.
- 32 -
Martínez Ramírez, Erik January 2018
Figure 30 Response of the pendulum to the PID with optimal values with 𝑥2 = 0.1rad
After having tuned the inner PID corresponding to the pendulum, the outer PID
corresponding to the cart needs to be tuned. Now that the system is stable the
Frequential method can be applied. In order to control the cart only a PD controller is
needed. From the values of the previously auto-tuned PID controller the bode diagram
is obtained and can be found in Figure 31.
Figure 31 Bode diagram of the system with the pendulum and the PID
Using the equations of the section Frequential method the parameters of the PD
controller are:
𝐾𝑃 = 0.0229
𝐾𝐷 = 0.096
- 33 -
Martínez Ramírez, Erik January 2018
The responses of the cart and the pendulum controlled by the cascaded PID can be
observed in Figures 32 and 33.
With the other sets of values for the PID controller there were no values found for the
PD controller that made the system stable in both, the linear and the non-linear
model.
- 34 -
Martínez Ramírez, Erik January 2018
6. Laboratory tests
• MATLAB
• Simulink
• RTW
• RTWT
• Visual C++ Professional
MATLAB is the host application of the environment in which the rest of the
MathWorks tools run. It provides a range of tools for solving complicated
mathematical problems.
RTW automatically builds a C++ source program from the Simulink model.
The C++ compiler compiles the code created by RTW to produce and executable
program.
RTWT communicates with the executable program created acting as the control
program and interfaces with the inverted pendulum hardware through an I/O board.
- 35 -
Martínez Ramírez, Erik January 2018
- 36 -
Martínez Ramírez, Erik January 2018
There are several options to test this controller with, depending on where the poles
are located. After checking that all the signs and initial values matched correctly in the
model and in the laboratory test, the first model that got tested was the one with
dominant poles at 𝑝 = −1. This system is not stable with computer simulation and is
not stable either in the laboratory.
The next test is the model that corresponds with dominant poles at 𝑝 = −2. The
responses can be observed in Figures 36 and 37. The system is stable but has some
oscillations.
The offset observed in both responses is the result that the system starts always at
zero whatever the initial positions are. Before the simulation starts, the pendulum
must be kept vertically manually, and this leads to small errors of some degrees. This
later translates in an offset in the position of the cart since the pendulum is trying to
achieve the value of zero which does not exactly correspond to the vertical value.
One way to fix this is to make the pendulum start at the bottom with a speed of zero
and make it swing all the way up and then switch to the controller that stabilizes the
pendulum.
- 37 -
Martínez Ramírez, Erik January 2018
- 38 -
Martínez Ramírez, Erik January 2018
In all the previous tests the position is stabilized around zero. The response of the
system to changes of the input in form of step to change the value of the position in
steady state can be found in Figure 39.
The system receives a first step at 5 seconds in order to move 0.2 meters to the right.
The cart has an offset of −0.1 meters due to the initial conditions not being perfect
and moves to −0.3. After that, at 12 seconds, receives a second input to move the cart
0.5 meters to the left and it ends near the 0.2 mark. From this can be concluded that
the position of the system can be controlled successfully within a reasonable precision.
- 39 -
Martínez Ramírez, Erik January 2018
A second controller is tested with the values corresponding to the dominant poles 𝑝 =
−4. The responses can be observed in Figures 40 and 41. The system is stable and it
has less oscillations compared with the previous test.
In Figure 42 it can be seen how this system performs against perturbations. All
perturbations are done at the extreme of the pendulum except the fourth one which is
applied at the cart. The system stabilizes much faster than the previous example at the
expense of a higher control action, which leads the system to saturation during a few
moments, however it is not enough to destabilize the system.
- 40 -
Martínez Ramírez, Erik January 2018
In Figure 43 it can be observed a cart position control similar to the previous example.
The system receives a first step at 5 seconds in order to move 0.2 meters to the right.
The cart has a small offset of −0.02 meters due to the initial conditions not being
perfect and moves to −0.22. After that, at 12 seconds, receives a second input to
move the cart 0.6 meters to the left and it ends near the 0.38 mark. This second step is
divided into two smaller steps one applied at 12 seconds and the other at 12.5
seconds. This must be done to avoid saturating the system for too long. From this can
be concluded that the position of the system can be controlled successfully with good
precision.
- 41 -
Martínez Ramírez, Erik January 2018
The response of the system to the auto-tuned controller with the PD controller for the
cart can be found in Figure 44.
The system is unstable in contrast with the simulations done with MATLAB and
Simulink, which were stable. Observing the response, it can be noticed that the
pendulum is stable until the cart runs out of the guide. This means that the cart is not
being properly controlled.
Trying to adjust the parameters of the controller of the cart with the auto-tune
function of Simulink leads to the following values:
𝐾𝑃 = 0.1
𝐾𝐼 = 0.05
𝐾𝐷 = 0.17
𝑁 = 2.5
From these values, 𝑁 stands out for being small, which means that the derivative
action will not act in higher frequencies. The response of the system to this controller
can be found in Figure 45.
- 42 -
Martínez Ramírez, Erik January 2018
The system is not stable. One possible reason could be that the discretization of the
sensors has not been taken into account and this could be affecting the action of the
derivative controller. This would also explain why the controller for full-state observer
worked since no derivative action is applied there. A deeper study and maybe a
different approach should be taken to make the system stable using PID controllers.
- 43 -
Martínez Ramírez, Erik January 2018
A swing-up controller could also be developed in order to avoid having to start the
pendulum from its upright position, which causes a different offset error each time
due to the human factor.
- 44 -
Martínez Ramírez, Erik January 2018
8. Planning
The planning and scheduling followed to organize and develop the project in order to
finish all tasks in time is detailed in this section.
- 45 -
Martínez Ramírez, Erik January 2018
- 46 -
Martínez Ramírez, Erik January 2018
9. Budget
The budget is detailed in a separate document. This section only gives a small summary
of the costs of the study:
- 47 -
Martínez Ramírez, Erik January 2018
- 48 -
Martínez Ramírez, Erik January 2018
11. Conclusions
The conclusions of the study are drawn and developed in this section. Considering the
initial requirements, the full-state feedback system meets them widely. This controller
works as intended and it is easily modified once the linearized model has been
obtained. The system responds well to perturbations and the cart can be controlled
without losing pendulum stability. Therefore, the requirements have been met since
the pendulum can be stabilized in its upright position while keeping the control of the
position of the cart.
On the other hand, the cascaded PID controller is not stable in laboratory conditions
and is much slower than the full-state feedback controller in computer simulation. It is
unclear why this controller does not work in the laboratory system, but one possible
explanation could be that the discretization of the sensors has not been considered
and this generates an issue with the derivative action of the PID controller.
In the end, a modeled system is just an approximation of the reality and will not
behave exactly in the same way as the real system.
The focus of future studies will be in trying different control methods to the inverted
pendulum and developing swing-up controller in order to avoid human errors during
each test in the laboratory.
- 49 -
Martínez Ramírez, Erik January 2018
12. Bibliography
[1] S. Mori, H. Nishihara, and K. Furuta, “Control of unstable mechanical system
control of pendulum†,” Int. J. Control, vol. 23, no. 5, pp. 673–692, May 1976.
[8] Y. Xu, M. Iwase, and K. Furuta, “Time Optimal Swing-Up Control of Single
Pendulum,” J. Dyn. Syst. Meas. Control, vol. 123, no. 3, p. 518, Sep. 2001.
[9] R. Chinichian, M., Kashani, “State space controller design for a spatial inverted
cart/pendulum system,” in IEEE Proceedings of the 32nd Midwest Symposium on
Circuits and Systems, 1989, pp. 633–636.
- 50 -
Martínez Ramírez, Erik January 2018
pendulum-on-a-cart.html?requestedDomain=www.mathworks.com. [Accessed:
02-Nov-2017].
[14] V. der and Me. Manusak Janthong, “Design and Implementation of Control
Concepts for Image-Guided Object Movement,” 2006.
- 51 -