Inverted Pendulum Cart

Download as pdf or txt
Download as pdf or txt
You are on page 1of 64

Polytechnic University of Catalonia (UPC)

Terrassa School of Industrial, Aerospace and Audiovisual Engineering

(ESEIAAT)

Study and design of the control


system of an inverted pendulum

Final Degree Project – Report

Bachelor’s Degree in Aerospace Technology Engineering

Author: Erik Martínez Ramírez

Director: Joseba Quevedo Casin

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

10. Environmental implications ................................................................................................. 48


11. Conclusions........................................................................................................................... 49
12. Bibliography ......................................................................................................................... 50

- 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

Figure 34 Control System Development Flow Diagram .............................................................. 36


Figure 35 Laboratory environment ............................................................................................. 37
Figure 36 Cart response .............................................................................................................. 38
Figure 37 Pendulum response ..................................................................................................... 38
Figure 38 Response of the system to perturbations.................................................................... 39
Figure 39 Response of the system to changes in the input in form of steps ............................... 39
Figure 40 Cart response .............................................................................................................. 40
Figure 41 Pendulum response ..................................................................................................... 40
Figure 42 Response of the system to perturbations.................................................................... 41
Figure 43 Response of the system to changes in the input in form of steps ............................... 41
Figure 44 Response of the system ............................................................................................... 42
Figure 45 Response of the system with the auto-tuned controller ............................................. 43
Figure 46 Preliminary Gantt chart .............................................................................................. 46

- viii -
Martínez Ramírez, Erik January 2018

Abbreviations
UPC – Polytechnic University of Catalonia

LQR – Linear-Quadratic Regulator

PID – Proportional-Integral-Derivative controller

RTW – Real Time Workshop

RTWT – Real Time Windows Target

PCI – Peripheral Component Interconnect

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:

• State of the art. It is a bibliographic study concerning previous studies about


the different types of inverted pendulums.
• Choose the different alternatives that will be studied and designed.
• Simulation and stabilization of each alternative with the modeled system in the
Simulink environment.
• Testing the different control systems in the laboratories at the automatic
control department in the Terrassa Campus of the UPC.
• Drawing conclusions

- 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

Justification and utility


The goal of the project is to be able to stabilize an unstable system. The most practical
way to do it is to use an inverted pendulum since the laboratories of the UPC already
have one. The results can be applied to other unstable systems such a rocket that must
keep its trajectory despite the gravity or a robot that must keep the equilibrium. Using
different alternatives will result in different control systems, which some of them
might be more appropriate in some circumstances than others.

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

1. State of the art


The stability of an inverted pendulum has become a common engineering challenge
for researchers. It is a classic problem in the field of automatic control which interests
in many other different disciplines such as mechanics, physics, mathematics, etc.,
because the inverted pendulum is an unstable and non-linear system.

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.

1.1. Planar inverted pendulum


The planar inverted pendulum mounted on a cart is the basic control problem of the
inverted pendulum. It has a few variants like single pendulum, double pendulum and
triple pendulum. These multiple pendulums are segmented pendulums which make
the control of the system more difficult. There are two problems in which the control
problem can be divided, the stabilization of the system and the swing-up.

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

Figure 1 Single inverted pendulum schematic [1]

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].

For a triple inverted pendulum, the controlled is based on a discrete-time linear


quadratic regulator theory via a reduce order estimator to stabilized the pendulum[5].

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.

1.2. Rotary inverted pendulum


The rotary inverted pendulum is more challenging than the previous types of inverted
pendulums. Furuta from the Tokyo Institute of Technology first developed this
pendulum and it has his name thanks to that. This type of pendulum is based on
another platform. It has the pendulum attached to a rotating arm. The main objective
is to be able to stabilize the pendulum from the unstable position of equilibrium[6].

-2-
Martínez Ramírez, Erik January 2018

A non-linear controller is developed by using the approximate linearization technique


and transforming the non-linear system that is this rotary inverted pendulum into the
Brunowsky canonical form[7]. Then, the feedback matrix is solved by the LQR. The
minimum time swing-up problem is solved by Pontryagin’s Maximum principle[8].

Figure 2 Rotary inverted pendulum schematic

1.3. 2DOF inverted pendulum


This pendulum is similar to the planar inverted
pendulum but the cart can move freely in any
direction, thus adding a degree of freedom. This
type of pendulum can also be mounted on a drone.
The main difference is that the pendulum is not
able to swing completely because now it rotates
around a point and not an axis. This forces the
pendulum to always start from the upright position
and the main objective of the system is to stay
stabilized around the position.

There are several controllers to stabilize the 2DOF


inverted pendulum. The pole placement technique
can be used to later develop a full state feedback
controller. It can also be controlled by a state-space
controller with a feedback gain matrix calculated
accordingly to the LQR design method[9]. Figure 3 2DOF inverted pendulum

-3-
Martínez Ramírez, Erik January 2018

1.4. Real-life applications


There are quite a few examples in the real world of the inverted pendulum, both made
by humans and in the natural world.

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

2. Characteristics of the inverted pendulum


The inverted pendulum is known as one of the most important and classical examples
of the control theory. It is inherently unstable, non-linear and often used as an
academic example.

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:

• Applying a torque at the pivot point.


• Moving the pivot point horizontally.
• Changing the rate of rotation of a mass mounted on the pendulum on an axis
parallel to the pivot axis.
• Oscillating the pivot point vertically.

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

Figure 4 Schematic of the forces applied to the inverted pendulum

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:

(𝑚𝑐 + 𝑚𝑝 )(𝑥1 + 𝑙 sin 𝑥2 )′′ = 𝑈 − 𝑇𝑐

(𝑚𝑐 + 𝑚𝑝 )(𝑙 cos 𝑥2 )′′ = 𝑉 − (𝑚𝑐 + 𝑚𝑝 )𝑔

𝐽𝑥2′′ = (𝑇𝑐 − 𝑈)𝑙 cos 𝑥2 + 𝑉𝑙 sin 𝑥2 − 𝐷𝑝

Where:

𝑚𝑐 : cart mass

𝑚𝑝 : pendulum mass

𝑙 : distance between both mass centers

𝑈 : force applied to the cart

𝑇𝑐 : cart friction with the guide

𝑉 : normal force

𝑔 : gravity force

𝐽 : moment of inertia

-6-
Martínez Ramírez, Erik January 2018

𝐷𝑝 : pendulum friction torque with the axis

′′ : second derivative with respect to time

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 Schematic of the laboratory model

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

3. Linearization of the system


Linearization is a method for assessing the local stability of an equilibrium point of a
system of non-linear differential equations or discrete dynamical systems.
Linearization makes it possible to use tools for studying linear systems to analyze the
behavior of a non-linear system near a given point of equilibrium.

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.

The Simulink model provided by the manufacturers of the pendulum (Appendix A)


cannot be directly linearized by MATLAB or Simulink since it is very non-linear due to
the expression of the friction force. In order to linearize the system a linear expression
for the friction force will be used.

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

𝑎(𝑈 − 𝐹𝑐 𝑥3 + µ𝑥42 sin 𝑥2 ) − 𝑙 cos 𝑥2 (µ𝑔 sin 𝑥2 − 𝑓𝑝 𝑥4 )


𝑥3̇ =
𝐽 + µ𝑙 sin2 𝑥2

𝑙 cos 𝑥2 (−𝑈 + 𝐹𝑐 𝑥3 − µ𝑥42 sin 𝑥2 ) + µ𝑔 sin 𝑥2 − 𝑓𝑝 𝑥4


𝑥4̇ =
𝐽 + µ𝑙 sin2 𝑥2

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

Figure 6 Model of the pendulum in Simulink

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.

The values of the real system in the laboratory are:

𝑚𝑐 = 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.

Figure 8 Open-loop response to non-zero initial condition

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

4. State observer design

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.

4.1. Pole placement


Pole placement, also known as full state feedback, is a method employed in feedback
control system theory to place the closed-loop poles of a plant in determined
locations. This is desirable because the location of the poles corresponds directly to
the eigenvalues of the system, which control the characteristics of the response of the
system. This method is widely used in systems with multiple inputs and multiple
outputs.

Figure 9 Full-state feedback system schematic

The schematic of a full-state feedback system is shown in Figure 9. Assuming the


reference, 𝑟 = 0, the input is:

𝑢 = −𝐾𝑥

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.

For poles placed at:

𝑝1 = −2

𝑝2 = −2.01

𝑝3 = −10

𝑝4 = −10.01

The matrix 𝐾 is the following:

𝐾 = - 20.1647 -105.4968 - 25.2784 -19.1089

The responses can be seen in Figures 10 and 11.

- 15 -
Martínez Ramírez, Erik January 2018

Figure 10 Response of the cart for 𝑥1 = 0m and 𝑥2 = 0.01rad

Figure 11 Response of the pendulum for 𝑥1 = 0m and 𝑥2 = 0.01rad

Trying the following faster poles:

𝑝1 = −4

𝑝2 = −4.01

𝑝3 = −20

𝑝4 = −20.01

The matrix 𝐾 is the following:

𝐾 = - 321.6725 - 487.5278 -199.6528 - 91.0092

The responses of these poles can be found in the Figures 12 and 13.

- 16 -
Martínez Ramírez, Erik January 2018

Figure 12 Response of the cart for 𝑥1 = 0m and 𝑥2 = 0.01rad

Figure 13 Response of the pendulum for 𝑥1 = 0m and 𝑥2 = 0.01rad

4.2. Observer design


In the real system not all states can be measured, in fact, only the positions of the
pendulum and the cart are measured. This means that the previous model cannot be
implemented since information is missing and an observer need to be implemented.

- 17 -
Martínez Ramírez, Erik January 2018

Figure 14 Schematic of a full-state feedback system with an observer

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.

Figure 15 Response of the cart with 𝑥1 = 0m and 𝑥2 = 0.1rad

- 19 -
Martínez Ramírez, Erik January 2018

Figure 16 Response of the pendulum with 𝒙𝟏 = 𝟎m and 𝒙𝟐 = 𝟎. 𝟏rad

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

Figure 17 Response of the cart with 𝑥1 = 0m and 𝑥2 = 0.1rad

Figure 18 Response of the pendulum with 𝑥1 = 0m and 𝑥2 = 0.1rad

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

Figure 19 Cart position change due to step inputs

Figure 20 Pendulum oscillations due to the change of position of the cart

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

Figure 21 Cart position change due to step inputs

Figure 22 Pendulum oscillations due to the change of position of the cart

- 23 -
Martínez Ramírez, Erik January 2018

5. PID controller design

5.1. PID controller


A PID controller is a control loop feedback mechanism widely used in industrial control
systems. A PID controller continuously calculates an error value as the difference
between a desired reference and a measured process variable and applies a correction
based on its proportional, integral and derivative terms. The controller attempts to
minimize the error over time by adjustment of a control variable to a new value
determined by a weighted sum of the control terms.

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.

A schematic of a standard PID controller can be found in Figure 23.

Figure 23 PID loop schematic

The mathematical form of the control function is:


𝑡
𝑑𝑒(𝑡)
𝑢(𝑡) = 𝐾𝑃 𝑒(𝑡) + 𝐾𝐼 ∫ 𝑒( 𝑡′)𝑑𝑡′ + 𝐾𝐷
0 𝑑𝑡

Where 𝐾𝑃 , 𝐾𝐼 and 𝐾𝐷 denote the coefficients of the respective terms. In the standard
form:

- 24 -
Martínez Ramírez, Erik January 2018

𝐾𝑃
𝐾𝐼 =
𝑇𝐼

𝐾𝐷 = 𝐾𝑃 𝑇𝐷

Where 𝑇𝐼 and 𝑇𝐷 represent the integration and derivative time respectively.

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.

5.2. Cascaded PID


One distinctive advantage of PID controllers is that two PIDs can be used together to
yield better dynamic performance. This is called cascaded PID control. In this situation,
one PID is controlling the set point of the other. One PID acts as outer loop controller,
which controls the primary physical parameter and the other PID acts as inner loop
controller, which reads the output of the outer loop controllers as a set point. This
inner loop usually controls a more rapid changing parameter. The schematic of a
cascaded PID control can be observed in Figure 24.

- 25 -
Martínez Ramírez, Erik January 2018

Figure 24 Schematic of a cascaded PID controller

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

5.3. Frequency method


The bode diagram of the pendulum will be used to design the PID controller of the
inner loop. Assuming that the PID has a transfer function given by:
𝐾𝐼
𝐷(𝑤) = 𝐾𝑃 + + 𝐾𝐷 𝑤
𝑤

Figure 25 Bode diagram of the response of the pendulum of the linearized system

Then, the frequency response of the PID controller is given by:

𝐾𝐼
𝐷(𝑗𝑤) = 𝐾𝑃 + 𝑗 (𝐾𝐷 𝑤 − ) = |𝐷(𝑗𝑤)|/𝜃
𝑤
The problem is to choose 𝐷(𝑤) (i.e. 𝐾𝑃 , 𝐾𝐼 and 𝐾𝐷 ) so:

𝐷(𝑗𝑤)𝐺(𝑗𝑤) = 1/180º + 𝜙𝑚

Where:

𝜃 = −180º + 𝜙𝑚 −/𝐺(𝑗𝑤)

𝜙𝑚 = 𝑝ℎ𝑎𝑠𝑒 𝑚𝑎𝑟𝑔𝑖𝑛

For a given frequency:

𝐾𝐼
𝐾𝑃 + 𝑗(𝐾𝐷 𝑤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.

5.4. Routh-Hurwitz stability criterion


The Routh-Hurwitz stability criterion provides a simple algorithm to decide whether or
not the roots of a polynomial are all in the left half of the complex plane. The criterion
is a mathematical test that provides necessary and sufficient conditions of stability.
This means that the polynomial is only stable if it passes the test, and if it does not
pass it, it is unstable.

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𝑡𝑓(𝐴, 𝐵, 𝐶, 𝐷)

𝜃(𝑠) 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.

After grouping terms:

𝐷(𝑠) = 𝑠 3 + (1.096 + 2.239𝐾𝐷 )𝑠 2 + (2.239𝐾𝑃 − 26.4)𝑠 + 2.239𝐾𝐼 − 14.97

From this polynomial the Routh table is calculated as follows:

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

From the table, the following condition is added:

2.2392 𝐾𝑃 𝐾𝐷 + 2.454𝐾𝑃 − 59.11𝐾𝐷 − 2.239𝐾𝐼 − 13.964 > 0

Several values of 𝐾𝑃 , 𝐾𝐷 and 𝐾𝐼 satisfy these restrictions so a few will be selected to


test the PID controller. Some small values that satisfy all the conditions are:

𝐾𝑃 = 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.

Figure 27 Bode diagram of the open-loop system

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

Therefore, the open-loop transfer function is the following:

𝜃(𝑠) 1.119 + 28.66𝑠 3 + 15.67𝑠 2


𝑃𝐼𝐷(𝑠) · =
𝑈(𝑠) 0.005𝑠 6 + 1.005𝑠 5 + 0.9638𝑠 4 − 26.47𝑠 3 − 14.97𝑠 2

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.

Figure 29 Response of the pendulum to the PID with 𝐾 = 10 𝑥2 = 0.1rad

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

Where 𝑁 is a filter coefficient according to the following expression:

𝐾𝐼 𝑁
𝑃𝐼𝐷(𝑠) = 𝐾𝑃 + + 𝐾𝐷
𝑠 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

For a frequency of 𝑤 = 1.013 rad/s a phase of 183.4º and a gain of 𝐺 = 20.12 is


obtained.

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.

Figure 32 Response of the cart with initial conditions 𝑥1 = 0m and 𝑥2 = 0.01rad

Figure 33 Response of the pendulum with initial conditions 𝑥1 = 0m and 𝑥2 = 0.01rad

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

6.1. Laboratory environment


The laboratory equipment, when used properly within the parameters set for its
electrical and mechanical performance, should not cause any danger to safety if
normal engineering practices are followed. Even though, all the laboratory activities
were conducted under supervision.

The virtual environment is formed by MathWorks tools formed by:

• MATLAB
• Simulink
• RTW
• RTWT
• Visual C++ Professional

All of them operating in a Windows system.

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.

Simulink is an application that allows the modeling of processes with a diagram of


blocks. Each block performs a concrete operation and if no suitable block is found in
the Simulink library, the user may write the desired block. The model is then passed to
RTW.

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

Figure 34 Control System Development Flow Diagram

The hardware needed to perform the simulations is the following:

• Computer Pentium 700 MHz with at least 262 MB of main memory


• Advantech PCI1711 I/O card and at least one free PCI slot on the motherboard

This board has the following characteristics:

• Windows Plug and Play device


• 2 digital to analogue converter channels in the 0 to 5 volts range.
• 16 digital inputs
• 16 analogue to digital converters

- 36 -
Martínez Ramírez, Erik January 2018

Figure 35 Laboratory environment

6.2. Full-state observer tests


The main objective is to check if the same controller that works in an idealized
environment, as a computer simulation, it also works in a real-life scenario where not
everything is ideal and, if not, try to make it work.

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

Figure 36 Cart response

Figure 37 Pendulum response

In Figure 38 it can be observed how the system responds to different perturbations.


The first, third and fourth are perturbations done at the end of the pendulum, where it
is easier to influence the system. The second perturbation is applied at the cart and it
is much smaller and barely noticeable since it is harder to influence the system from
there.

- 38 -
Martínez Ramírez, Erik January 2018

Figure 38 Response of the system to perturbations

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.

Figure 39 Response of the system to changes in the input in form of steps

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.

Figure 40 Cart response

Figure 41 Pendulum response

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

Figure 42 Response of the system to perturbations

Figure 43 Response of the system to changes in the input in form of steps

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

6.3. Cascaded PID tests


The main objective is the same as in the previous section, to check if the controller that
works in an idealized environment also works in a real-life scenario and, if not, try to
make it work.

The response of the system to the auto-tuned controller with the PD controller for the
cart can be found in Figure 44.

Figure 44 Response of the system

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

Figure 45 Response of the system with the auto-tuned controller

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

7. Future lines of research


The study developed in this final degree project aims at studying and designing
different controllers for a simple inverted pendulum. This study focuses in two
solutions, a full-state feedback controller and a cascaded PID. However, this last one is
not developed successfully, and it could be improved in future research, for example,
considering the discretization of the sensors.

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.

Moreover, other control strategies could be developed in future studies, such as


neural network control for a self-learning system.

These different methods could also be applied to a different type of inverted


pendulum such a double or triple inverted pendulum, a rotary pendulum or even some
other unstable system such a biped robot.

- 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.

8.1. Brief task description

• Previous analysis: Deciding the scope of the project.


• Project charter: Detailing the tasks of the project, estimating the time needed,
checking for dependencies and planning the project accordingly.
• Search of information.
o State of the art: Research about similar projects.
o Inverted pendulum characteristics: Particular characteristics of an
inverted pendulum.
• Simulation and stabilization of each alternative: Simulation with a modelled
system of each alternative and stabilization of it.
• Laboratory tests
o Testing of the control systems: Testing each alternative with the real
system.
o Refining the control systems: Adapt to the possible unexpected
differences that the real system might have.
• Written report
o Introduction: Aim, requirements, justification, utility…
o State of the art: Previous and current state of this field.
o Inverted pendulum characteristics: Particular characteristics and
equations of an inverted pendulum.
o Simulation and stabilization: Stabilize each alternative in a simulation
with a modelled system.
o Laboratory tests: Try the control system of each simulation with the real
system and make the appropriate changes to make it stable.
o Budget: Economical resources to do the project.
o Conclusions: Extracting the key points from the whole project.
• Oral presentation: Prepare the oral defence.
• Project delivery: Deadline of the project.
• Oral defence: Dates for the defence of the project.

- 45 -
Martínez Ramírez, Erik January 2018

8.2. Preliminary Gantt chart

Figure 46 Preliminary Gantt chart

- 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:

• Engineering work, considering an overhead of 15%, cost estimated at


3507.5€
• Software licenses estimated at 580€
• Laptop amortization estimated at 130.77€
• Laboratory renting estimated at 250€
• Total cost of the study estimated at 4468.27€

- 47 -
Martínez Ramírez, Erik January 2018

10. Environmental implications


This study has no direct environmental implications. The computing power would be
the only real environmental problem and because only one computer is needed for the
simulations there is no real incentive for optimizing the code as long as this does not
change.

- 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.

[2] T. Ishida, N. Shiokawa, T. Nagado, and S. Ganeko, “Learning control of an


inverted pendulum using a neural network,” Proceedings IECON 91 1991
International Conference on Industrial Electronics Control and Instrumentation,
vol. 9, no. 3. IEEE, pp. 31–37, 1991.

[3] T. Henmi, M. Deng, A. Inoue, N. Ueki, and Y. Hirashima, “Energy-based control of


a double inverted pendulum,” IFAC Proc. Vol., vol. 37, no. 12, pp. 173–178,
2004.

[4] T. Fujinaka, Y. Kishida, M. Yoshioka, and S. Omatu, “Stabilization of double


inverted pendulum with self-tuning neuro-PID,” Proc. IEEE-INNS-ENNS Int. Jt.
Conf. Neural Networks. IJCNN 2000. Neural Comput. New Challenges Perspect.
New Millenn., no. 1, pp. 345–348 vol.4, 2000.

[5] G. A. Medrano-Cerda, “Robust stabilization of a triple inverted pendulum-cart,”


Int. J. Control, vol. 68, no. 4, pp. 849–866, Jan. 1997.

[6] T. Sugie, “Controller Design for an Inverted Pendulum based on Approximate


Linearization Division of Applied Systems Science , Proposed Approximate
Linearization Method,” INT. J. ROBUST NONLINEAR Control, vol. 8, pp. 1–7,
1996.

[7] A. J. Krener, “Approximate linearization by state feedback and coordinate


change,” Syst. Control Lett., vol. 5, no. 3, pp. 181–185, Dec. 1984.

[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.

[10] Feedback Instruments Ltd, “Control in a MATLAB Environment,” 2002.

[11] H. Sánchez, P. Aguirre, and P. Patete, “Construcción y Control de un Péndulo


Invertido utilizando la Plataforma Lego MINDSTORMS NXT,” cibelec.org.ve, pp.
978–980, 2010.

[12] “Control of an Inverted Pendulum on a Cart - MATLAB & Simulink Example -


MathWorks España.” [Online]. Available:
https://es.mathworks.com/help/control/examples/control-of-an-inverted-

- 50 -
Martínez Ramírez, Erik January 2018

pendulum-on-a-cart.html?requestedDomain=www.mathworks.com. [Accessed:
02-Nov-2017].

[13] S. K. Mishra and D. Chandra, “Stabilization and Tracking Control of Inverted


Pendulum Using Fractional Order PID Controllers,” J. Eng., vol. 2014, pp. 1–9,
Apr. 2014.

[14] V. der and Me. Manusak Janthong, “Design and Implementation of Control
Concepts for Image-Guided Object Movement,” 2006.

[15] C. L. Phillips and H. T. Nagle, Sistemas de control digital : análisis y diseño.


Gustavo Gili, 1993.

[16] “Ball & Beam State-Space Methods for Controller Design.” .

- 51 -

You might also like