Está en la página 1de 48

FINAL PROJECT: The goal of this

HOW TO Project is to make a robot that can balance


itself, but it has only two points of contact
with the ground.

BALANCE A AUTHOR: Borja Gómez Ortigosa

TWO-WHEELED
ROBOT
HOW TO BALANCE A TWO-WHEELED ROBOT Borja Gómez Ortigosa
Technical University, Spring Semester 21/05/2017

INDEX
1. Introduction .......................................................................................................................... 2
1.1. General information ...................................................................................................... 2
1.2. Field of application ........................................................................................................ 3
1.3. Classification.................................................................................................................. 5
1.4. Statement of the project goal ....................................................................................... 8
2. Mathematical modelling of the robot and methods for the control .................................... 9
2.1. The two-wheeled robot-standard modelling and control .......................................... 11
2.1.1. Modelling of system dynamics ............................................................................ 11
2.1.2. Summary of models ............................................................................................ 13
2.2. Control of two-wheeled robots................................................................................... 15
2.2.1. Linearisation ........................................................................................................ 15
2.2.3. Adaptive and self-learning non-linear controllers .............................................. 23
2.2.4. Disturbance observers......................................................................................... 26
2.2.5. Summary ............................................................................................................. 27
3. Robot test-bench description.............................................................................................. 29
3.1. Plant ............................................................................................................................ 29
3.2. Control system ............................................................................................................ 30
3.3. PID controller .............................................................................................................. 31
3.3.1. Introduction......................................................................................................... 31
3.3.2. PID behaviour ...................................................................................................... 32
3.3.3. Proportional action ............................................................................................. 34
3.3.4. Integral action ........................................................ ¡Error! Marcador no definido.
3.3.5. Derivative action ................................................................................................. 36
4. Cascade PID controller for robot test-bench ...................................................................... 38
5. Conclusion. .......................................................................................................................... 44
6. Bibliography ........................................................................................................................ 45
HOW TO BALANCE A TWO-WHEELED ROBOT Borja Gómez Ortigosa
Technical University, Spring Semester 21/05/2017

INDEX OF FIGURES
Fig. 1. Picture of a Segway PT ...................................................................... 3
Fig. 2. Two wheeled-robot .......................................................................... 10
Fig. 3. Robot coordinates ............................................................................ 12
Fig. 4. Linear reference tracking controller. ............................................... 18
Fig. 5. PID controller for two-wheeled robot.............................................. 19
Fig. 6. Backstepping control design ............................................................ 19
Fig. 7. Adaptively estimating changing centre of mass height – robot from
Li et al.(2010). ............................................................................................. 23
Fig. 8. Supervisor in artificial neural network controller............................ 24
Fig. 9. Critic and action neural network...................................................... 25
Fig. 10. Map of controllers used by researchers on two-wheeled robots ... 28
Fig. 11. Two wheeled robot of the laboratory in self-balancing mode ....... 29
Fig. 12. Block-diagram of the control system. ............................................ 31
Fig. 13. Typical PID algorithms. ................................................................. 33
Fig. 14. Different responses for Kp values ................................................. 34
Fig, 15. Oscillations for different values of Kp .......................................... 35
Fig. 16. Integral control behaviour. ............................................................. 36
Fig. 17. Closed-loop interconnection of cascade PID control .................... 38
Fig. 18. Body tilt angle of the robot ............................................................ 39
Fig. 19. Body angular velocity of the robot ................................................ 40
Fig. 20. Wheels angular velocity of the robot ............................................. 40
Fig. 21. Body angular velocity of the robot ................................................ 41
Fig. 22. Control signal ................................................................................. 42
Fig. 23. Cascade PID implementation......................................................... 43

1
HOW TO BALANCE A TWO-WHEELED ROBOT Borja Gómez Ortigosa
Technical University, Spring Semester 21/05/2017

1. Introduction
1.1. General information
A quick look at the range of mobile robots in existance reveals an
enormous diversity in shape, form, and models of mobility. However, one
thing that most of them have in common is that they are passively balances
(i.e. their bodies are constantly in a state of stable equilibrium). While this
is perfectly logical in most cases, there are certain applications, such as
Segways and humanoid robots, that take advantage of an unstable-
equilibrium, inverted pendulum design to enhance their capabilities. While
their self-balancing mechanisms may increase the complexity of their
design, the benefits, which include greater manoeuvrability and stability,
outweigh the costs. [1]
Two-wheeled robots have several applications which make them
interesting from theoretical and practical point of view. The most popular
commercial product, built on the idea of self-balancing two-wheeled robot
is the Segway® Personal Transporter, produced by Segway in the USA.
Some of this robots have maximum speed of 20 km/h and can travel as far
as 38 km on a single battery charge.
Two motors are necessary and sufficient in a robot to make it move
in any given direction on the ground. Each motor is attached to a wheel
which makes one of the two robot’s supporting points. Having no
additional supporting point, it has simpler mechanical design but it has to
have more elaborate control system. The two-wheeled robots have
dynamics which is similar to the inverted pendulum dynamics so that they
are inherently unstable and should be stabilized around the vertical position
using a control system. Linear-quadratic or proportional-integral-derivative
(PID) control laws are usually implemented in order to achieve vertical
stabilization and desired position in the horizontal plane. [2]

2
HOW TO BALANCE A TWO-WHEELED ROBOT Borja Gómez Ortigosa
Technical University, Spring Semester 21/05/2017

1.2. Field of application


The field of robotics has dominated the minds of people around the
world. It was actually the dream of humans to create such a machine that
replicates them in every aspect of daily life. Such a machine that reflects
their thoughts, gestures, postures and perform the daily life activities.
Development in this field for a last couple of decades has transformed
dreams into reality. With the use of efficient microcontrollers and sensitive
sensors has helped a lot in achieving this milestone. Now robots can be
seen in our daily life. Robots are employed on production lines in factories,
appeared as intelligent machines to do a specific task or used as
commercial products.
Two wheel self-balancing robot is also a development in the field of
robotics. This two wheel self-balancing robot is actually based on the
concept of Inverted pendulum theory. This type of robot has gained fame
and interest among researchers and engineers because it utilizes such a
control system that is used to stabilize an unstable system using efficient
microcontrollers and sensors. Two-wheeled balancing robots can be used in
several applications with different perspectives such as an intelligent
gardener in agricultural fields, an autonomous trolley in hospitals, shopping
malls, offices, airports, healthcare applications or an intelligent robot to
guide blind or disable people. These types of robots can effectively work in
non-uniform surfaces due to their balanced control system.

Fig. 1. Picture of a Segway PT

3
HOW TO BALANCE A TWO-WHEELED ROBOT Borja Gómez Ortigosa
Technical University, Spring Semester 21/05/2017

One of the most famous application of the two-wheeled robots is the


The Segway PT, a two-wheeled, self-balancing, battery-powered electric
vehicle (shown in Fig. 1) invented by Dean Kamen. It is produced
by Segway Inc. of New Hampshire. The name Segway is derived from the
word segue, meaning smooth transition. PT is an abbreviation for personal
transporter (the old suffix HT was an initialism for human transporter).
Computers, sensors, and electric motors in the base of the Segway
PT keep the device upright when powered on with balancing enabled. The
rider commands the PT to go forward or backward by shifting their weight
forward or backward on the platform. The PT uses gyroscopic sensors and
accelerometer-based leveling sensors to detect the resulting changes in its
pitch angle and, to maintain balance, it drives its wheels forward or
backward as needed to return its pitch to upright. In the process, the rider
establishes and then maintains a desired speed by modulating the extent
and duration of their fore/aft weight shifts. To turn and steer, the rider shifts
the handlebar to the left or right. The PT responds by adjusting the speeds
of the wheels in opposite directions causing the PT to yaw and, if not
traveling forward or backward, turn in place. At speed, the amount of shift
of the handlebar corresponds to the amount of left or right lean required by
the rider to balance themselves on the platform during a turn.
The maximum speed of the Segway PT is 12.5 miles per hour
(20.1 km/h). The product is capable of covering 24 mi (39 km) on a fully
charged lithium-ion battery, depending on terrain, riding style, and the
condition of the batteries. [3]

4
HOW TO BALANCE A TWO-WHEELED ROBOT Borja Gómez Ortigosa
Technical University, Spring Semester 21/05/2017

1.3. Classification
Robots can be classified according to various criteria such as their
degrees of freedom, kinematical structure, drive technology, work-shop
geometry and motion characteristics.
a) Classification by Degrees of Freedom: A manipulator should have 6
degrees of freedom to manipulate an object freely in three
dimensional spaces. From this point of view a robot may be a
 General purpose robot: if it possesses 6 degrees of freedom.
 Redundant robot: if it possesses more than 6 degrees of
freedom. It provides more freedom to move around obstacles
and operate in a tightly confined work space.
 Deficient robot: if it possesses less than 6 degrees of freedom.

b) Classification by Kinematic Structure: according to kinematic


structure robots can be classified as
 Serial Robot or Open- loop Manipulator: A robot is said to be
a serial robot or an open- loop manipulator if its kinematic
structure takes the form of an open-loop chain. Example:
Adept-One Robot.
 Parallel Manipulator: if it is made up of a closed-loop chain.
In general, a parallel manipulator has the advantages of higher
stiffness, higher payload capacity, and lower inertia to the
manipulation problem than a comparable serial manipulator, at
the price of a smaller workspace and more complex
mechanism
 Hybrid Manipulator: if it consists of both open and closed
loop chains. Example: Fanuc S-900 W. Many industrial
robots employ this type of robot construction.

c) Classification by Drive Technology: Manipulators can also be


classified by their drive technology. The three popular drive
technologies are:
 Electric: Most manipulators use either electric DC servomotor
or stepper motors because they are clean and relatively easy to
control.

5
HOW TO BALANCE A TWO-WHEELED ROBOT Borja Gómez Ortigosa
Technical University, Spring Semester 21/05/2017

 Hydraulic: used for high speed and/or high-load-carrying


capabilities. A major disadvantage associated with this is the
possibility of leaking oils. A hydraulic drive is inherently
flexible, due to bulk modulus of oil.
 Pneumatic: Also used for high speed and/or high-load-
carrying capabilities. A pneumatic drive is clean and fast but it
is difficult to control because air is a compressible fluid.

d) Classification by Workspace Geometry: the workspace of a


manipulator can be defined as the volume of space the end of
effecter can reach. The workspace can be of two types: A reachable
workspace is the volume of space within which every point can be
reached by the end effecter in at least one orientation. A dextrous
workspace is the volume of space within which every point can be
reached by the end effecter in all possible orientation.
 Cartesian robot: In this the kinematic structure of a robot arm
is made of three mutually perpendicular prismatic joints. The
wrist center position of a Cartesian robot can be conveniently
described by three Cartesian co-ordinates associated with the
three prismatic joints. The regional work-space of a Cartesian
robot is a rectangular box.
 Cylindrical Robot: A robot arm is called cylindrical robot if
either the first or second joint of a Cartesian robot is replaced
by a revolute join. The wrist center position of a cylindrical
robot can be described by a set of cylindrical coordinate
system associated with the three joint variables. The
workspace of a cylindrical robot is confined by two concentric
cylinders of finite length.
 Spherical Robot: A robot arm is called a spherical robot if
either the first or second joint of a Cartesian robot is replaced
by a revolute joint. The wrist center position of a spherical
robot can be described by a set of spherical coordinate system
associated with the three joint variables. The workspace of
cylindrical robot is confined by two concentric spheres.
 Articulated Robot: A robot arm is said to be an articulated
robot if all three joints are revolute. The workspace of an
articulated robot is very complex, typically a crescent shaped
cross section. Puma robot is an articulated robot.
6
HOW TO BALANCE A TWO-WHEELED ROBOT Borja Gómez Ortigosa
Technical University, Spring Semester 21/05/2017

 The SCARA (selective compliance assembly robot arm) Robot:


it is a special type of robot consisting of two revolute joints
followed by a prismatic joint. All three joint axes are parallel
to each other and usually point along the direction of gravity.
The wrist has one degree of freedom and hence the entire
robot has 4 degrees of freedom. This type of robot is useful for
assembling parts on a plane.

e) Classification by Motion Characteristics: robot manipulators can


also be classified by according to their nature of motion.
 Planar: A manipulator is called a planar manipulator if its
mechanism is a planar mechanism. Planar manipulators are
useful for manipulating an object on a plane.
 Spherical: A rigid body is said to be under a spherical motion
if all particles in the body describe curves that lie on
concentric spheres. A mechanism is said to be a spherical
mechanism if all the moving links perform spherical motion
about a common stationary point. A manipulator is called a
spherical manipulator if it is made up of a spherical
mechanism.
 Spatial Manipulator: A rigid body is said to perform a spatial
motion if its motion cannot be characterized as planar or
spherical motion. A manipulator is called a spatial manipulator
if at least one of the moving links in the mechanism possesses
a general spatial motion. Planar and spherical mechanisms can
be considered as special cases of spatial mechanisms. [4]

7
HOW TO BALANCE A TWO-WHEELED ROBOT Borja Gómez Ortigosa
Technical University, Spring Semester 21/05/2017

1.4. Statement of the project goal


In this paper we present the design and experimentation of a control
system of two-wheeled robot which implements a Linear-Quadratic
Regulator for vertical stabilization and a proportional-integral controller of
the robot rotation around the vertical axis. Due to the lack of accurate
analytical robot model, the control system design is done by using a model
built with the aid of an identification procedure. Two discrete-time Kalman
filters of 17th order and of 2nd order are implemented to estimate the plant
state in presence of several noises. A software in MATLAB®/Simulink®
environment is developed for generation of control code which is
embedded in the Texas Instruments Digital Signal Controller
TMS320F28335. Results from the simulation of the closed-loop system as
well as experimental results obtained during the real-time implementation
of the controller designed are given. The experimental results confirm the
efficiency of the technical solution implemented.

8
HOW TO BALANCE A TWO-WHEELED ROBOT Borja Gómez Ortigosa
Technical University, Spring Semester 21/05/2017

2. Mathematical modelling of the robot and methods for


the control

Mobile robots are increasingly ubiquitous today, and are used in a


variety of different applications, including exploration, search and rescue,
materials handling and entertainment. While legged robots are able to step
over obstacles, they are more complex to design and control due to the
greater number of degrees of freedom. Wheeled robots are more energy
efficient, tend to have a simpler mechanical structure, as well as simpler
dynamics compared to that required by legged robots to make contact with
the ground and provide a driving force. Robots with at least three wheels
can achieve static stability, further simplifying dynamics. Another the
ground is flat. This paper focuses on two-wheeled robots, specifically of
the statically unstable variety. These robots have two coaxial wheels
mounted on either side of an intermediate body, with a centre of mass
above the wheel axles, and therefore, must actively stabilize themselves to
prevent toppling.
Two-wheeled robots (Fig. 2) have a number of advantages over other
mobile robots. Although they are more difficult to control than statically
stable wheeled robots, two-wheeled robots are still much easier to control
than legged robots. This wheel configuration makes them highly
manoeuvrable, because of their ability to turn on the spot, similar to
differential drive robots. Although two-wheeled robots are non-holonomic,
this is a minor issue, because of their ability to turn on the spot. Being
actively stabilised means that the robot can correct for any disturbances
which may otherwise cause a statically stable robot to tip over, even with a
higher centre of mass. Two-wheeled robots can be taller, with a small
footprint, making them quite suitable for indoor environments, because
they can fit through narrow corridors and tight corners. Because two-
wheeled robots can lean fore and aft to restabilize themselves, they are also
able to maintain stability on inclines, by leaning into the slope. Similarly,
even with a tall profile, two-wheeled robots can accelerate quickly without
tipping over. Having no more than two wheels means more room for larger
wheels, potentially allowing them to traverse rougher terrain.

9
HOW TO BALANCE A TWO-WHEELED ROBOT Borja Gómez Ortigosa
Technical University, Spring Semester 21/05/2017

Fig. 2. Two wheeled-robot

This article reviews the research on modelling and control of two-


wheeled robots thus far particularly the controllers for balancing a two-
wheeled robot. This includes the different models and controllers used, and
how successful they were. The dynamics of two-wheeled robots have some
particular features which complicate their control beyond being unstable in
open loop. Specifically, they are non-minimum phase, and under-actuated.
Because of the coupled dynamics of tilt and forward velocity, to move
forwards from equilibrium, it is necessary to first move backwards,
allowing the intermediate body to tilt forwards, before beginning forward
movement.
We will also review research on two-wheeled robots in environments
where there are obstacles in the terrain, or where the robots have additional
actuators and objectives to meet. However, we mainly consider those
actuators and objectives which affect the dynamics of balancing a two-
wheeled robot significantly. Therefore, higher level path planning and
navigation is out of scope. The sensors that may be used, and how they
may be implemented is not considered. Although some sensors, such as
cameras, may be affected by the tilting of the intermediate body of a two-
wheeled robot, measurement, estimation and filtering of sensors have wide
coverage, and is not uniquely affected by the dynamics of two-wheeled
robots.

10
HOW TO BALANCE A TWO-WHEELED ROBOT Borja Gómez Ortigosa
Technical University, Spring Semester 21/05/2017

2.1. The two-wheeled robot-standard modelling and control


In this section, we consider a standard two-wheeled robot, with only
two independently actuated drive wheels connected to an intermediate
body, travelling on flat surfaces. We will review the different modelling
approaches for this basic scenario, and the control strategies used for
standard control objectives for mobile, two-wheeled robots-balancing and
locomotion. Many approaches for modelling and control strategies have
been attempted for this standard scenario and it is a natural starting point to
review this area.

2.1.1. Modelling of system dynamics


A. Models based on dynamic equations
Generally, the non-linear dynamic model of a two-wheeled robot is
based on derivation via the Euler-Lagrange equation, Newton’s laws of
motion or Kane’s method. The natural assumptions are ideal rigid body
dynamics, flat and horizontal ground surface, zero wheel slip and no
friction. Though here we are mostly considering non-linear models of two-
wheeled robots, they are often linearised in order to simplify the analysis
and design of controllers.
The simplest model only allows for straight-line motion, sometimes
referred to as 1-dimensional motion (as viewed from above). Only motion
in the vertical plane (Fig. 3) is modelled, involving the two degrees of
freedom yielding two states for each degree-longitudinal displacement and
tilt of the intermediate body. Without trying to be complete, there are many
instances of models for 1-dimensional motion without yaw (Åkesson,
Blomdell, & Braun, 2006; Ha & Yuta, 1994; Han, Zhao, Li, & Li, 2008;
Kim, Lee, & Kim, 2011; Li, Gao, Huang, Du, & Duan, 2007; Lien, Tu,
Ross, & Burvill, 2006; Nomura, Kitsuka, Suemitsu, & Matsuo, 2009; Ooi,
2003; Ruan & Cai, 2009). An early example which does not model yaw is
as given by Ha and Yuta (1994). An instructive example of this non-linear
model derived using the Euler–Lagrange equation or Lagrangian is
presented by Kim et al. (2011). Because longitudinal position does not
further affect robot dynamics (other states), sometimes only the other three
states are modelled (Ha & Yuta, 1994; Ruan & Cai, 2009).

11
HOW TO BALANCE A TWO-WHEELED ROBOT Borja Gómez Ortigosa
Technical University, Spring Semester 21/05/2017

Fig. 3. Robot coordinates

When turning, or yaw, is allowed, there exist two additional states


for yaw angle. Another further state can be obtained if instead of
longitudinal distance travelled, both x and y-coordinates in the Cartesian
plane are used for position of the two-wheeled robot. The resulting non-
linear model is much more complex. However, this is often simplified by
disregarding some additional effects. By ignoring the change in moment of
inertia in the yaw axis, as tilt angle changes, and also ignoring the effect of
yaw rate on tilt and longitudinal motion, the yaw states are decoupled from
the other states, simplifying derivation (Grasser, D’arrigo, Colombi,
Ruffer, & Mobile, 2002; Hu & Tsai, 2008; Takei, Imamura, & Yuta, 2009;
Tsai & Hu, 2007; Wu, Liang, & Wang, 2011).
There are two variations of model where moment of inertia around
the yaw axis changes as tilt angle changes. Pathak, Franch, and Agrawal
(2005) used a moment of inertia tensor matrix of the intermediate body to
fully account for the dynamics. This can also be simplified to disregard the
lesser change caused by rotation of the intermediate body, but taking into
account the effect on moment of inertia caused by the change in distance of
the centre of mass of the intermediate body from the yaw axis (Kim, Kim,
& Kwak, 2005; Nawawi, Ahmad, & Osman, 2007; Muhammad, Buyamin,
Ahmad, & Nawawi, 2011) a more common alternative which avoids the
inertia tensor, of which Muhammed et al.’s derivation (Muhammad et al.,
2011) is a good example using Kane’s method.

12
HOW TO BALANCE A TWO-WHEELED ROBOT Borja Gómez Ortigosa
Technical University, Spring Semester 21/05/2017

B. Black-box models
A black-box model of system dynamics can also be identified. This
is a model where we are not concerned with the meaning of every term,
only that the result approximates reality accurately enough. Alarfaj and
Kantor (2010) experimentally estimated the parameters of a discrete time
state-space model. Jahaya, Nawawi, and Ibrahim (2011) estimated various
linear models in the discrete time domain with a sampling time of 0.1 s.
These included the ARX (auto-regressive with extraneous input), ARMAX
(includes moving average), Box-Jenkins, and Output-error models. Model
coefficients can be solved via a suitable least-squares algorithm given
system responses to independent white noise. The primary factor affecting
the accuracy of these models is the order and sampling rate. An excessively
high sampling rate can cause numerical problems – Moore, Lai, and
Shankar (2007) is a good source for how to estimate ARMAX models, and
suggests a sampling time around 10% of the settling time of the system.
A Takagi-Sugeno (T-S) fuzzy model was used by Qin, Liu, Zang,
and Liu (2011) to approximate the non-linear model. A linear combination
of linear state-space models weighted by a membership function can
approximate the non-linear state-space equations. A suitable controller was
designed based on the fuzzy model of the system.

2.1.2. Summary of models


The various models used can thus be categorised along two major
dimensions-model fidelity and model type, as shown in Table. 1. Model
fidelity involves the degrees of freedom that are modelled, as well as
whether their interactions are modelled. Model type is first classified by
whether it is a theoretical or white-box approach, or if it is a black box
model. For theoretical models, the resultant equations are generally the
same, but may be categorised into the method by which they were derived.
Black box models can be categorised by their structure.

13
HOW TO BALANCE A TWO-WHEELED ROBOT Borja Gómez Ortigosa
Technical University, Spring Semester 21/05/2017

Table. 1. Models categorised by fidelity and type.

14
HOW TO BALANCE A TWO-WHEELED ROBOT Borja Gómez Ortigosa
Technical University, Spring Semester 21/05/2017

2.2. Control of two-wheeled robots


The primary objective in the control of two-wheeled robots is always
to remain balanced and avoid toppling. Secondary objectives may include
tracking a certain speed or trajectory. The sensors and state measurements
available vary, but most commonly include wheel encoders, and an inertial
measurement unit (IMU), which includes gyroscopes and accelerometers.
These basic sensors yield forward speed and angular rotation directly, as
well as tilt angle over time – normally from a Kalman filter in the IMU.
The accuracy of the tilt angle primarily depends on the gyroscopes, beyond
which there is a trade-off between the effect of sensor noise, and
acceleration. It is also possible to estimate tilt without an accelerometer,
since the angular acceleration of the intermediate body can perform as a
crude accelerometer.

2.2.1. Linearisation
Two-wheeled robots are often controlled by some variant of linear
state feedback of a linearised model. Normally, Jacobian linearization is
used for its simplicity, and is quite successful since the two-wheeled robot
system is quite linear for small tilt angles. Non-linearity in the system is
due to trigonometric sine and cosine functions as well as gyroscopic forces
(depending on angular speed). When tilted at 10_, the error in linearity of
the cosine function is still only 1.5%. This amount of tilt is more reasonable
for two-wheeled robots with a relatively high centre of mass. Note that
Jacobian linearisation approximation ignores the non-linear effects which
intertwine the tilt and yaw states, resulting in two apparently decoupled
state-space systems. Many papers (Åkesson et al., 2006; Grasser et al.,
2002; Takei et al., 2009; Kim et al., 2005) use Jacobian linearisation before
designing linear controllers based on the linear approximation of the
system.
While Jacobian linearisation approximates the non-linear system,
feedback linearisation is an exact linearisation via a change of state and
input variables. Non-linear effects are cancelled by feedback dependent on
the state of the system. Because feedback linearisation does not
approximate, it results in better performance for larger tilt angles, where
there is increasing non-linearity. For two-wheeled robots, partial feedback
linearisation is the most common approach (Pathak et al., 2005;

15
HOW TO BALANCE A TWO-WHEELED ROBOT Borja Gómez Ortigosa
Technical University, Spring Semester 21/05/2017

Hatakeyama & Shimda, 2008; Shimada & Hatakeyama, 2007; Shimada &
Hatakeyama, 2008; Shimizu & Shimada, 2010; Yongyai, Shimada, &
Sonoda, 2009). Teeyapan, Wang, Kunz, and Stilman (2010) used a simpler
input-output feedback linearisation. Normally, feedback linearization can
cause internal states to disappear, which can make the system
unobservable. Because many states in the two-wheeled robot system are
almost directly measurable from IMUs, the possibility of certain states
becoming unobservable can be avoided. However, feedback linearisation is
quite sensitive to the accuracy of the model, to correctly cancel out non-
linear effects. It is important to note that full state linearisation is not
possible, because the system is under-actuated. Feedback with a single
actuator (the drive wheels) can only be used to linearise either tilt or
longitudinal position.

2.2.2. Linear controllers


Given a linearised model, a linear controller can be easily connected
to track a reference state as shown in Fig. 4, requiring only a gain matrix K
to be designed. One way is via pole placement, which can be used to
control rise time and overshoot to obtain satisfactory performance. Grasser
et al.’s JOE (Grasser et al., 2002) is an early paper using this technique,
but it is also used in a number of other papers (Han et al., 2008; Nawawi et
al., 2007; Feng et al., 2011; Li, Gao, Huang, & Matsumoto, 2008). Pole
placement involves finding a gain matrix K such that the desired poles in a
linear plant are:

𝑒𝑖𝑔 (𝐴 − 𝐵𝐾) (2.1.3.1)

For optimal control, linear quadratic regulation (LQR) is a very


common choice. This involves finding a controller to minimise the cost
function:

𝑥
𝐽 = ∫0 (𝑥 𝑇 𝑄𝑥 + 𝑢𝑇 𝑅𝑢) 𝑑𝑡 (2.1.3.2)

Although it involves slightly more calculation, its optimality


guarantees are attractive enough that many more researchers design their
controllers using LQR (Åkesson et al., 2006; Ha & Yuta, 1994; Takei et al.,
2009; Kim et al., 2005; Alarfaj & Kantor, 2010; Butler & Bright, 2008;

16
HOW TO BALANCE A TWO-WHEELED ROBOT Borja Gómez Ortigosa
Technical University, Spring Semester 21/05/2017

Coelho, Liew, Stol, & Liu, 2008; Kim, Kim, & Kwak, 2006). This often
yields better convergence to stability, and assuming knowledge of the
system states, has a guaranteed 60° phase margin. A cross-term cost 𝑥 𝑇 Nu
has not been used for balancing of two-wheeled robots.
Comparisons between LQR and other linear controllers have been
conducted (Lien et al., 2006; Ooi, 2003; Ghani, Ju, Othman, & Ahmad,
2010; Sun & Gan, 2010; Wu & Zhang, 2011a) by a few researchers. Their
analysis is, at times, contradictory. Ghani et al. (2010) and Lien et al.
(2006) found that pole placement is superior in settling time and smaller
deviations. Wu and Zhang (2011a) found that pole placement has smaller
overshoot but similar settling time. Sun and Gan (2010) found the PID
controller to have a larger region of stability, but with vibrations at
equilibrium. Ooi (2003) found pole placement has inferior robustness.
These assessments are not very useful because they are specific to the
particular tuning and system, and cannot be generalised. The controllers
that can be obtained by pole placement or LQR can greatly differ
depending on the poles selected, or the Q and R weighting matrices. In
general, a higher gain (therefore better convergence, but perhaps larger
vibrations at equilibrium) can be obtained by selecting poles further in the
left half plane for pole placement, or larger Q gains for the LQR controller.
However, LQR can be more useful in selecting those states for which faster
settling time is desired, whereas this is not possible with pole placement.
LQR therefore allows the trade-offs between states and actuators to be
managed more precisely, and to conserve actuator work over time. The
trade-off between multiple actuators is not straight forward with pole
placement. The LQR controllers all use measured states. These are often
filtered, and therefore the controller is, in a sense, a linear quadratic
Gaussian (LQG) controller – consisting of the optimal LQR controller, and
Kalman filter observer. However, supposing that the observer dynamics are
much faster than system dynamics, LQR is an adequate design strategy
mostly retaining its phase margin guarantees, particularly since the Kalman
filter is often an integral part of an IMU, if it is used. Lupian and Avila
(2008) explicitly designed an LQG controller. If an LQG controller is
unstable, loop transfer recovery may be necessary. However, this does not
appear to be a problem for two-wheeled robots, because of the
comparatively fast dynamics that IMUs have in measuring absolute tilt
angle.

17
HOW TO BALANCE A TWO-WHEELED ROBOT Borja Gómez Ortigosa
Technical University, Spring Semester 21/05/2017

Fig. 4. Linear reference tracking controller.

Other optimal linear controllers - 𝐻∞ and 𝐻2 controllers, which use


different cost functions have been implemented. They are more robust
because of their lower sensitivity to model errors and other disturbances.
Hu and Tsai (2008) and Ruan and Chen (2010a) designed an 𝐻∞
controller. Kanada, Watanabe, and Chen (2011) designed an 𝐻2
controller. Kanada et al. compared the LQR and 𝐻2 controller, showing
that while the LQR controller achieves superior performance for the
nominal plant, when there are model uncertainties, the 𝐻2 controller can
maintain its performance, while LQR performance degrades significantly.
PID controllers are very popular, whether by themselves or in
conjunction with other controllers. They are widely used in many other
areas in industry, because no model of the plant is required, with tuning of
just three gains, with PD (Hatakeyama & Shimada, 2008) and PI (Liao &
Li, 2010; Takahashi, Ishikawa, & Hagiwara, 2001) controllers appearing
when one of the gains is zero. Two-wheeled robots have a number of states
therefore the control system will often have a PID controller for each
degree of freedom one for tilt, one for speed (shown in Fig. 5), and where
applicable, one for yaw. The PID gains are often selected, and reasonable
gains can be found easily just from experimentation. Otherwise, Ziegler–
Nichols can be used for an initial set of gains as shown by Nasir, Ahmad,
Ghazali, and Pakheri (2011). Nasir et al. used two separate PID control
loops – for longitudinal position, and tilt, in an implementation of a purely
PID controller.

18
HOW TO BALANCE A TWO-WHEELED ROBOT Borja Gómez Ortigosa
Technical University, Spring Semester 21/05/2017

Fig. 5. PID controller for two-wheeled robot.

Among non-linear control methods, backstepping is a common


solution. Essentially, it involves first regulating just part of the system with
a virtual input. For just balancing of a two-wheeled robot, a suitable control
law using tilt rate can stabilize tilt error e1 = θref – θ to the origin in a sub-
plant, as shown in Fig. 6; Fig. 6a. The virtual input cannot be controlled
directly however, as the first step uses one state, for example tilt rate, to
control another state, tilt angle. We therefore define an error between actual
tilt rate and the first virtual input, using another input to regulate this error
to zero. Each step until the real control involves controlling a new error
between a virtual control, and the actual state (shown in Fig. 6b).
Lyapunov stability can be proven by showing that the derivative of a
candidate function at each step of the states is negative definite.
Backstepping is used by a number of researchers, but often in conjunction
with other control strategies.

(a) Step 1: if 𝜃̇ could be controlled directly

(b) Step 2: stabilize 𝜃̇ to virtual control α using the real control u

Fig. 6. Backstepping control design

19
HOW TO BALANCE A TWO-WHEELED ROBOT Borja Gómez Ortigosa
Technical University, Spring Semester 21/05/2017

A good initial backstepping example is provided by Thao, Nghia,


and Phuc (2010), where backstepping is used to control tilt angle, along
with a PD controller for longitudinal position, and a PI controller for yaw
angle. Nomura et al. (2009) present another example of a controller
designed via backstepping, though this time with an adaptive approach
using a parameter update law to track unknown system functions.
Otherwise, the same steps are used to regulate tilt angle as in the first
paper. Nomura et al. also compares the backstepping controller with an
LQR controller in simulation, which illustrates the advantages and
disadvantages of each approach – the LQR controller performs better at
small tilt angles because it is locally optimal, and at small tilt angles, the
system is approximately linear. However, at a large initial tilt angle of 35°,
the backstepping controller remains stable, while the LQ controller is
unstable.
Sliding mode controllers involve simplifying the dynamics by
applying a large switching control input to force the system state to a
desired hyper-surface. The remainder of the control input needs only to
ensure asymptotic stability on the hyper-surface, rather than the full state-
space. Usually, the control input is the sum of the switching input and a
controller for the reduced-order system. This type of controller tends to be
more robust to model uncertainties. However, due to switching around the
sliding surface, there can be significant chattering. For the chosen
hypersurface:

𝜎 (𝑡) = 𝐶𝑥(𝑡) = 0 (2.1.3.3)

for some vector C, the sign of r(t) is used to determine that of the switching
input. To mitigate the effect of chattering, instead of using the sign of r, a
σ
saturating or more sophisticated function may be used, for example, |σ|+σ
by Ghani, Yatim, and Azmi (2010).
Other examples of the sliding mode controller, without the
complications of other control strategies in a two-wheeled robot include
Wu et al. (2011), Ghani et al. (2010) and Yau, Wang, Pai, and Jang (2009).
In particular, Wu et al. simulated external disturbances as well as
perturbation of system parameters to show the robustness of the sliding
mode controller for two-wheeled robots. Nawawi, Ahmad, Osman, Husain,
and Abdollah (2006) used a proportional integral sliding mode controller

20
HOW TO BALANCE A TWO-WHEELED ROBOT Borja Gómez Ortigosa
Technical University, Spring Semester 21/05/2017

(PISMC) which aimed to improve tracking compared to the conventional


sliding mode controller – they demonstrated less overshoot compared to
pole placement. For a PISMC, the hypersurface is given by:

𝑡
𝜎(𝑡) = 𝐶𝑥(𝑡) − ∫0 (𝐶𝐴 − 𝐶𝐵𝐾)𝑥(𝑡) + 𝑑𝜏 (2.1.3.4)

for chosen constant matrices C and K.


Sliding mode controllers are often used in conjunction with other
control strategies. Nasrallah, Michalska, and Angeles (2007) used a sliding
mode controller as an outer loop. Some papers combine backstepping with
a sliding mode control approach, as shown by Tsai and Ju (2010).
Disturbance observers may improve the performance of sliding mode
controllers. Xiang-zhong, Xin-Wen, Ya- Jing, Jing, and Yu-Heng (2012)
have compared the performance of the sliding mode controller with routine
and dynamic switching surface, to a sliding mode controller with
disturbance compensation. The compensation corrects any internal or
external disturbance perpendicular to the sliding surface. They have
demonstrated in simulation that using this method, chattering is suppressed.
Gain scheduling involves the selection of control gains depending on
the system states, and can be used to maintain good performance in non-
linear systems when the apparent linear dynamics changes. A fuzzy PID
control strategy is presented by Wu, Ma, and Wang (2010), but is
essentially gain scheduling of the PID controller. Like fuzzy control, gain
scheduling can approximate other non-linear control laws, although the use
of gains slightly alters the effects of interpolation.
Fuzzy control is another oft used strategy for non-linear systems.
Depending on the number of fuzzy sets, it can approximate and approach
any non-linear control law. Compared to backstepping, the theory is
probably simpler. However, because of the piecewise nature of the control
law, it would not be straightforward to prove Lyapunov stability. Because
the two-wheeled system has a number of states (at least three even when
considering straight line motion, and ignoring longitudinal position), the
number of fuzzy sets needed to appropriately divide the state space can be
large. Therefore, the system will normally consist of two fuzzy control
loops, naturally one for balance, and one for speed/position control (similar
to that for PID as shown in Fig. 4), so that each fuzzy controller is only
affected by two states at once as in Chiu and Peng (2006), or with yaw

21
HOW TO BALANCE A TWO-WHEELED ROBOT Borja Gómez Ortigosa
Technical University, Spring Semester 21/05/2017

rotation, three fuzzy control loops (Nasir et al., 2011). Wu and Zhang
(2011b) used a fuzzy controller in the position control loop, and a PID
controller for balancing.
Li et al. (2011) have designed a fuzzy controller based on a Takagi-
Sugeno model, demonstrating a fuzzy model-based approach to designing
the controller. A control law based on such a model can be expressed as:

𝑢 = 𝑘𝑥⃗ + 𝑏 (2.1.3.5)

A Lyapunov function-based controller have been designed and


simulated by Kausar, Stol, and Patel (2011, 2012a). The stability region
and performance of an optimal LQR controller was compared to a
controller designed using a constructive-Lyapunov function. Comparisons
were made, first keeping settling time constant, then keeping initial control
signal constant. Keeping one of these performance metrics constant allows
fair comparisons based on other metrics, by removing bias introduced by
arbitrarily choosing controller gains. Because there is more than one gain,
further reduction of bias could use multiple performance metrics as control
variables.
It is not possible to derive an optimal control analytically for non-
linear systems in general. No researchers have investigated numerical
methods of approximating the Hamilton-Jacobi-Bellman solutions to find a
non-linear optimal controller.
There is the state-dependent Riccati equation (SDRE) for nonlinear
systems that finds a sub-optimal controller. Representing the state-space
matrices A(𝑥⃗), B(𝑥⃗), C(𝑥⃗), D(𝑥⃗) as functions that depend on state, the
Riccati equation can be solved for all states. While the LQR controller is
optimal only at the equilibrium point, the SDRE further improves the cost
of the controller for the region around the equilibrium. However, there is
no unique set of state-space functions, and the SDRE does not guarantee
global optimality. Kim and Kwon (2011) have shown that SDRE improves
transient performance compared to LQR – the time when the system is
most likely in its most non-linear region away from equilibrium. Controller
performance is fairly comparable because control action at equilibrium
involves the same gains.

22
HOW TO BALANCE A TWO-WHEELED ROBOT Borja Gómez Ortigosa
Technical University, Spring Semester 21/05/2017

2.2.3. Adaptive and self-learning non-linear controllers


Various adaptive control strategies have also been used. Li et al.
(2010) demonstrates the use of an adaptive controller which tracks the
height of the centre of mass. A change in the height of the centre of gravity
can be detected by checking if the states deviate from what is expected, and
if so, the height is re-estimated. This was experimentally tested to show
that the adaptive controller can maintain stability when the height changes
(Fig. 7), whilst becoming unstable without the adaptive controller.

Fig. 7. Adaptively estimating changing centre of mass height – robot from Li et al.(2010).

An adaptive fuzzy controller has been used by Ruan, Chen, Cai, and
Dai (2009). Because the precision of fuzzy controllers depends on the
number of rules, an adaptive fuzzy controller can be used instead to reduce
the number of rules required, where the output for each rule in a static set
of membership functions can adapt to changes in the system. It also means
that the fuzzy rules do not need to be designed initially. Nomura et al.
(2009) used an adaptive integral backstepping controller because of
limitations in transforming the system equations into a triangular form.
An adaptive fuzzy controller has been used for a sliding mode
controller (Su, 2012), where the switching function is derived by using
selecting fuzzy sets based on the distance from the sliding surface, to
establish a boundary layer. The width of each fuzzy set is adaptively
adjusted based on an estimated optimal width.

23
HOW TO BALANCE A TWO-WHEELED ROBOT Borja Gómez Ortigosa
Technical University, Spring Semester 21/05/2017

Artificial neural networks (NNs) are quite a popular adaptive control


strategy for two-wheeled robots. Neural nets can approximate and control
non-linear systems. However, to train the internal weights of the neurons, a
supervisor is needed. A standard arrangement is shown in Fig. 8, the neural
network is a feed-forward controller adding to the PD supervisor, to
account for nonlinear effects. The neural network learns by back-
propagation of the error given by the PD supervisor. This arrangement
allows the robot to balance somewhat even with an untrained neural
network. However, balance will improve over time as the neural network
learns and corrects the non-linearities of the system. The multi-layer
perceptron (MLP) is a neural network for general use, but their use for two-
wheeled robots has not been published. Cerebellar models are quite similar
to the MLP and they have been used by Tanaka, Ohata, Kawamoto, and
Hirata (2010) (with clear equations for the weighted sum and activation
function), and Ruan and Chen (2010b).

Fig. 8. Supervisor in artificial neural network controller.

A cerebellar model articulation controller (CMAC) can be used as a


neural network. It uses much less processing power, but a large amount of
memory use. Compared to other neural networks, it also learns more
rapidly, with local generalisation abilities. Each memory location is
associated with a region of state-space (often a hyper-rectangular shape),
overlapping with other regions. The output is calculated by the average of
memory locations associated with the current state. CMACs are quite
common in other robotic fields where movement is to be controlled. For
two-wheeled robots, their implementation is demonstrated by Li, Jiao,
Qiao, and Ruan (2008). Chiu (2010) demonstrates the use of the adaptive
output recurrent CMAC (AORCMAC), which adds a recurrent feedback

24
HOW TO BALANCE A TWO-WHEELED ROBOT Borja Gómez Ortigosa
Technical University, Spring Semester 21/05/2017

path to the standard CMAC. Chiu experimentally compares the


AORCMAC neural network with controllers derived from the Adaptive
CMAC, the Elman NN, and the supervisory enhanced genetic algorithm
controller (SEGAC). The conclusion is that the AORCMAC is most able to
capture un-modelled system dynamics.
Another method of reinforcement learning uses internally recurrent
neural networks, composed of a Critic Neural Network and an Action
Neural Network, as shown in Fig. 9. This method was used to balance a
two-wheeled robot by Sun and Gan (2011) and Ren, Ruan, and Li (2009).
The Critic Neural Network approximates the Hamilton– Jacobi–Bellman
equations, and learns the cost-to-go, so that the Action Neural Network can
learn the control action. The Critic Neural Network can update its model
using a temporal difference method. Compared to using a PD supervisor,
this type of neural network does not rely on an external stabilizing
controller, which may be important before the neural network is trained.

Fig. 9. Critic and action neural network.

Fuzzy neural networks were demonstrated by Su and Chen (2010)


and Wu and Jia (2011). In both cases, the simulation or experimental
results show that they can be successful. A radial basis function neural
network (where the activation function is a radial basis function), was
demonstrated by Tsai, Huang, and Lin (2010) for two-wheeled scooters.
The radial basis function provides some degree of local generalisation. Tsai
et al. used a NN for self-balancing, and another NN separately for yaw
control. Currently, the NN provides appropriate control actions for slow
speeds. It is unclear how the NN will perform if further developed for
higher speeds.

25
HOW TO BALANCE A TWO-WHEELED ROBOT Borja Gómez Ortigosa
Technical University, Spring Semester 21/05/2017

The Boltzmann machine, a stochastic neural network, described as a


Monte Carlo version of a Hopfield network, has also been demonstrated by
Zhao and Ruan (2009) on a two-wheeled robot with a flexible lumbar.
In many cases, the researchers have only investigated a single neural
network and control strategy, so it is unclear how each type of neural
network compares with other neural networks and/or control strategies,
though some general trends may be inferred from the use of these neural
networks in other problems.
2.2.4. Disturbance observers
A number of researchers use a disturbance observer (Fig. 9) in their
work to reject low frequency disturbances, caused by unmodelled system
dynamics or external disturbances. While not a controller by itself, a
disturbance observer helps to improve the control action of an existing
controller.
System parameters can influence the relative importance of
unmodelled dynamics, which can be seen as a disturbance. Linearity of the
two-wheeled robot depends on the height of the centre of mass, the inertia
of the system and motor power.
A disturbance observer is simply an estimator of a state – often
representing the size of a step disturbance. Disturbance estimation can be
achieved by comparing expected system states (based on an internal model
of the system) to the measured system states. The resulting estimated
disturbance can be added to the output of the controller.
Shimada and Hatakeyama (2008), Shimizu and Shimada (2010) and
Yongyai et al. (2009) give more detailed equations of how a disturbance
observer can be implemented in a two-wheeled robot.

26
HOW TO BALANCE A TWO-WHEELED ROBOT Borja Gómez Ortigosa
Technical University, Spring Semester 21/05/2017

2.2.5. Summary
As shown in Fig. 10, a variety of controllers has been investigated
for two-wheeled robots. Though many papers have experimental results,
more such results would be preferable. Experimental results are particularly
lacking for the non-linear controllers. Though simulations can be used to
show robustness to disturbances and model uncertainties, there may be
problems implementing them in practice, including sensor noise, sampling
time and the total system lag time. Experimental data would be better able
to show the robustness of the controllers to these effects. It is also uncertain
how training of artificial neural network controllers can be done in practice,
particularly where the NN may be unstable before training.
There is also a lack of comparison between different controller
strategies, particularly for the non-linear controllers. There exist a number
of papers making some comparison, but often they cannot be generalised.
This is because the performance of a controller is influenced not only by
the strategy, but also by the gains chosen. Moreover, it may be possible to
obtain a range of similar gain matrices of a linear full-state feedback
controller, via different methods, such as pole placement, LQR or H1,
given appropriate input poles or cost matrices, making it difficult to make
conclusive comparisons. Good comparisons between different control
strategies are able to choose the gains of the different controllers fairly, for
example, by selecting gains to match a particular metric to prevent bias.
A numerical solution to the Hamilton-Jacobi-Bellman for two-
wheeled robots, to test the effectiveness of an optimal non-linear controller,
is still an open topic. It would be useful to investigate how much
performance is improved, compared to non-optimal controllers or optimal
linear controllers.
Model predictive control has not been investigated. This approach
may be a way to approximate an optimal controller, after a finite horizon.
The challenge of model predictive control is in how it can be implemented,
and what trade-offs might be necessary, to find an optimal solution at each
time step, in a fast dynamic situation suitable for balancing a two-wheeled
robot. [5]

27
HOW TO BALANCE A TWO-WHEELED ROBOT Borja Gómez Ortigosa
Technical University, Spring Semester 21/05/2017

Fig. 10. Map of controllers used by researchers on two-wheeled robots

28
HOW TO BALANCE A TWO-WHEELED ROBOT Borja Gómez Ortigosa
Technical University, Spring Semester 21/05/2017

3. Robot test-bench description


3.1. Plant
The robot is equipped with two servo drives for actuation, micro-
electromechanical (MEM) inertial sensor ADIS16350 for measuring the
angular velocities φ̇ and ψ̇ of robot body in the vertical plane and around
the vertical axis, respectively, quadrature encoders for measuring the
position of the wheels and a digital signal controller Texas Instruments
TMS320F28335 implementing a discrete real-time stabilization algorithm
with sampling period T0 = 0.005 s. The robot balancing is achieved by
rotating the wheels in appropriate direction. The computation of control
actions to both DC brushed drive motors is realized in single precision on
the basis of signals from the gyro sensor measuring the angular rate (and,
after integration, the tilt angle φ) and signals from rotary encoders
measuring the wheels rotation angles. The control of the DC motors is
executed by Pulse Width Modulated (PWM) signals. Since the gyroscope
measurements are subject to bias, random walk and noise, the body tilt
angle and the wheel angles are estimated by using a 17th order Kalman
filter. Additional 2nd order Kalman filter is used to estimate the yaw angle
ψ.
The general view of the two-wheeled robot in self-balancing mode is
shown in Fig. 11.

Fig. 11. Two wheeled robot of the laboratory in self-balancing mode

29
HOW TO BALANCE A TWO-WHEELED ROBOT Borja Gómez Ortigosa
Technical University, Spring Semester 21/05/2017

3.2. Control system


The idea that the robot will have to balance itself means that if it tips
forward, the robot will have to accelerate forward at a sufficient rate to stop
the tipping and vice versa.
So the simplest algorithm would be:
 Drive the motor forward if the robots is tipping forward and
vice versa.
 Make the speed of the motors proportional to the robot tipping
angle.
This is called proportional control and the number that converts from
angle to PWM duty cycle is the proportional gain (KP). If you had a
superfast microcontroller and motors that reacted instantaneously the signal
and supply enough pair to stabilize the robot, this would work good. The
problem is that you don’t usually have the first two requirements.
Now we are going to analyse the effects of having a microcontroller
that takes some time (around ten milliseconds) to process IMU (inertial
measurement unit) data and calculate PWM input to the motors.
When you free your robot from its vertical position, it will tip in one
direction. The controller takes a few milliseconds to realise this, and tells
the motors to speed forward, slowly at first, because the angle is small.
Note that the robot has been tipping all this time. Two thing can happen
now:
 If KP is smaller than a ‘magic value’, the pair commanded to the
motors will not be enough to offset the tipping of the robot and it
will fall all its merry way.
 If KP is larger than the ‘magic value’, the robot will over-accelerate a
bit, so then it will cross over and tip in the other direction. There will
be a strong response to this too, which will send the robot tipping in
the previous direction. The oscillations will feed themselves and
keep growing (unstable system) causing the robot falling to the
ground.
 You cannot find the exact ‘magic value’ for KP, so you have to forget
about using just proportional control.

30
HOW TO BALANCE A TWO-WHEELED ROBOT Borja Gómez Ortigosa
Technical University, Spring Semester 21/05/2017

How do we combat this? Derivative and integral control are the


answer. In short, the PID controller.
The block-diagram of the two-wheeled robot control system is
shown in Fig. 12. With respect to the stabilization in upper equilibrium
state and to the control of forward-backward motion, the robot is described
by Auto Regressive Moving Average with external input (ARMAX) and
Box-Jenkins (BJ) discrete-time models.

Fig. 12. Block-diagram of the control system.

3.3. PID controller


3.3.1. Introduction
A Proportional-Integral-Derivative (PID) controller is a three-
termcontroller that has a long history in the automatic control field, starting
from the beginning of the last century (Bennett, 2000). Owing to its
intuitiveness and its relative simplicity, in addition to satisfactory
performance which it is able to provide with a wide range of processes, it
has become in practice the standard controller in industrial settings. It has
been evolving along with the progress of the technology and nowadays it is
very often implemented in digital form rather than with pneumatic or
electrical components. It can be found in virtually all kinds of control
equipments, either as a stand-alone (single-station) controller or as a
functional block in Programmable Logic Controllers (PLCs) and
Distributed Control Systems (DCSs). Actually, the new potentialities
offered by the development of the digital technology and of the software
packages has led to a significant growth of the research in the PID control

31
HOW TO BALANCE A TWO-WHEELED ROBOT Borja Gómez Ortigosa
Technical University, Spring Semester 21/05/2017

field: new effective tools have been devised for the improvement of the
analysis and design methods of the basic algorithm as well as for the
improvement of the additional functionalities that are implemented with the
basic algorithm in order to increase its performance and its ease of use. The
success of the PID controllers is also enhanced by the fact that they often
represent the fundamental component for more sophisticated control
schemes that can be implemented when the basic control law is not
sufficient to obtain the required performance or a more complicated control
task is of concern. In this chapter, the fundamental concepts of PID control
are introduced with the aim of presenting the rationale of the control law
and of describing the framework of the methodologies presented in the
subsequent chapters. In particular, the meaning of the three actions is
explained and the tuning issue is briefly discussed. The different forms for
the implementation of a PID control law are also addressed.
Proportional-Integral-Derivative (PID) control is the most common
control algorithm used in industry and has been universally accepted in
industry control. The popularity of PID controllers can be attributed partly
to their robust performance in a wide range of operating conditions and
partly to their functional simplicity. [6]

3.3.2. PID behaviour


To start off, I’m going to explain a general idea of what a PID
algorithm is and why it is used. First, an algorithm for our purposes can be
defined as a step-by-step procedure for solving a problem especially by a
computer. The end we want to accomplish is making a robot balance on
two wheels, and the PID part is a type of algorithm that follows certain
steps in order to make that happen. Next, PID stands for Proportional-
Integral-Derivative. The integral and derivative part are related to calculus,
but if you haven’t taken calculus you can still understand and use PID
controllers.

32
HOW TO BALANCE A TWO-WHEELED ROBOT Borja Gómez Ortigosa
Technical University, Spring Semester 21/05/2017

The typical PID algorithms is shown (Fig. 13) in the next diagram:

Fig. 13. Typical PID algorithms.

From left to right:

 The desired state is the position you want your robot to be in. In the
case of the balancing robot, that would be straight up.
 The e(t) part is the error experienced. So if you want your robot
perpendicular to the surface (90 degrees), and it is actually 95
degrees, then e(t) is 5 degrees.
 The Kp × e(t) part is the proportional part (explained later).
 The Ki × ∫ e(t) part is the integral part (explained later).
d
 The Kd × e(t) part is the derivative part (explained later).
dt
 The plus sign means they are all added together into a control signal
that is passed on to the system. In our case the system is a self-
balancing robot.
 Finally the sensor sends the new current position of the robot back.
This is called feedback, and makes this type of control loop a closed-
loop system (as opposed to an open-loop system, which is easier but
much less accurate). [7]

33
HOW TO BALANCE A TWO-WHEELED ROBOT Borja Gómez Ortigosa
Technical University, Spring Semester 21/05/2017

3.3.3. Proportional action


The proportional term (gain) makes a change to the output that is
proportional to the current error value, according to the expression
u(t) = Kp e(t) = Kp (r(t) – y(t)), (3.3.3.1.)
, where Kp is the proportional gain. Its meaning is straightforward,
since it implements the typical operation of increasing the control variable
when the control error is large (with appropriate sign).

Larger values typically mean faster response. However, an


excessively large proportional gain will lead to instability and oscillation.
So if your robot is wobbling a lot or is very off balance, you might need a
larger Kp term to offset that because the robot is going to be further off
balance. Here is a picture (Fig. 14) where we can see different responses
for different Kp values:

Fig. 14. Different responses for Kp values

, where A is e(t), and the value before A is the Kp value. You can see
that larger values of Kp help the system achieve stability faster. However,
you can’t overdo it. Too much Kp will give severe oscillations, as seen in
the next figure (
Fig, 15).

34
HOW TO BALANCE A TWO-WHEELED ROBOT Borja Gómez Ortigosa
Technical University, Spring Semester 21/05/2017

Fig, 15. Oscillations for different values of Kp

3.3.4. Integral action


An integral term in your controller responds to the (time) integral of
your control variable.

sumErr = 0;
loop:
sumErr = sumErr + err; (3.3.4.1.)
I = kI * sumErr;
end
In next figure (Fig. 16), it’s explained the integral controller
behaviour for our robot. In case that the proportional gain was not set
enough to arrest his tipping, the integral gain will respond in proportion to
the angle from the vertical.

35
HOW TO BALANCE A TWO-WHEELED ROBOT Borja Gómez Ortigosa
Technical University, Spring Semester 21/05/2017

Fig. 16. Integral control behaviour.

The integral controller could be useful when you don’t want to set
your proportional gain above a certain limit. For example: to avoid the
robot oscillating very frequently around the vertical.
I accounts for past values of the error.
I = kI * sumErr (3.3.4.2)

In engineering talk, the Integral term is proportional to the amount of


time the error is present. The integral term accelerates the movement of the
process towards the set value and eliminates any residual steady-state error
that occurs with a proportional only controller. The contribution from the
integral term is dependent both on the magnitude of the error and on the
duration of the error.

What that means is that robots are only as accurate as you program
them to be, and as accurate as their motors are. Without going into detail,
just because you program the robot to turn a wheel a certain amount
doesn’t mean it will turn that exact amount. Usually it will be a little off
(due to friction, motor deadzones, power losses, etc.). The integral term
(KI) takes this error and adds it up until it is large enough to make a
difference.

3.3.5. Derivative action

Finally is the Kd term. With the derivative term, the controller output
is proportional to the rate of change of the measurement or error. The
derivative term slows the rate of change of the controller output, most
notably near the controller set value. It therefore reduces the magnitude of
36
HOW TO BALANCE A TWO-WHEELED ROBOT Borja Gómez Ortigosa
Technical University, Spring Semester 21/05/2017

the overshoot produced by the integral component and improves stability.


Larger Kd values decrease overshoot, but slows down transient response
and may lead to instability from signal noise amplification from
differentiation of the error.

The differential response depends on how fast the error is changing,


in our case how fast the robot is falling. This is very important in the
problem that we are studying because we have an unstable system (a self-
balancing robot).
D accounts for possible future trends of the error.
D = kD + (currenterr – previouserr) (3.3.5.1)

Obviously PID algorithms are complex and are different for each
robot you will build. Hopefully this brief overview gives some insight into
how one goes about constructing a PID algorithm.

37
HOW TO BALANCE A TWO-WHEELED ROBOT Borja Gómez Ortigosa
Technical University, Spring Semester 21/05/2017

4. Cascade PID controller for robot test-bench


The multivariable character of the plant is limiting the application of
simple control techniques as PID control which are widely applied
throughout the industry. In such a situation the solution is to connect
several PID control modules in a cascade structure in an effort to increase
their capacity to control the robot. The first level of control will measure
the angular velocity of the body and will apply voltage to motors to
minimize the angular velocity. Next control level measures the angular
velocity of the wheels and compensate it by supplying the reference signal
to first level of control. As a result to stabilize the angular velocity of the
wheels the robot will make some tilt in the appropriate direction. And the
third level of control is about following reference trajectory generated by
joystick or preprogrammed in the microcontroller. The third PID controller
measures angular rotation of the wheels which is proportional to linear
translation of the body and supplies the reference signal to wheel angular
velocity PID. Fig. 17 shows the closed-loop interconnection which is used
to stabilize the laboratory test bench of two-wheeled robot.

Fig. 17. Closed-loop interconnection of cascade PID control

The PID controllers of the cascade systems are tuned in sequence


starting from the innermost PID and ending with the outermost. The
performance of the inner loop limit the performance of the outer loop. So
the designer should try to maximize the performance in terms of bandwidth
(meaning fast response) and stability in each PID tuning task.

38
HOW TO BALANCE A TWO-WHEELED ROBOT Borja Gómez Ortigosa
Technical University, Spring Semester 21/05/2017

Fig. 18. Body tilt angle of the robot

We can see from Fig. 18 that the body tilt angle of the robot remain
around 0 degrees meaning the robot stays in vertical position during the
experiment. The figure compares simulation vs experiment recordings of
the body angle where we can see differences due to the unmodelled
dynamical effects as friction phenomena. However these difference are not
large enough to cause the falling down of the robot thanks to the cascade
structure of control.
Besides we can say that the weight of the robot is not distributed
homogenously. This is why the graph that we see on Fig. 18 of the
experiment do not oscillate until 0 degrees (vertical position) and it
oscillates until -4 degrees. If we want to establish it in a more efficient way
we have to put more weight in the lighter side or divide it correctly.

39
HOW TO BALANCE A TWO-WHEELED ROBOT Borja Gómez Ortigosa
Technical University, Spring Semester 21/05/2017

Fig. 19. Body angular velocity of the robot

Fig. 19 shows recording of angular velocity which is derivative of


the angle and measured by the gyroscope. Here the experiment and
simulation behaviour is pretty similar. A relatively high level of oscillations
is due to the micromechanical structure of the gyroscope (MEMS type)
which makes it sensitive to a lot of external factors.

Fig. 20. Wheels angular velocity of the robot

40
HOW TO BALANCE A TWO-WHEELED ROBOT Borja Gómez Ortigosa
Technical University, Spring Semester 21/05/2017

Performance of the second PID controller is presented on Fig. 20


where the dynamics of wheels angular velocity is recorded. We can see that
it stay in the range from -100 deg/s to 100 deg/sec and has oscillatory
nature which are due to following factors: deviations from symmetric of the
robot construction, measurement noise caused by rotary encoder.
Next of Fig. 21 we see the action of third PID controller responsible
for position tracking. As the figure presents the robot follows well enough
the trapezoidal trajectory with oscillations in range of 10-20 degrees. There
is also good fit between experimental and simulated data which
demonstrate that mathematical model is adequate.

Fig. 21. Body angular velocity of the robot

41
HOW TO BALANCE A TWO-WHEELED ROBOT Borja Gómez Ortigosa
Technical University, Spring Semester 21/05/2017

presents the control signal generated by cascade PID interconnection


Fig. 22
in order to stabilize the robot. We observe that oscillations from sensors are
transferred by PID controllers in the control signal also. The control signal
stays well below its maximal amplitude which is around 100 units.

Fig. 22. Control signal

Cascade PID interconnection used to stabilize the robot is developed


as a Simulink model presented in Fig. 23. The first and second PID
controller are included in a subsystem PID stab which are critical to
stabilization. The third PID controller responsible for position tracking is

42
HOW TO BALANCE A TWO-WHEELED ROBOT Borja Gómez Ortigosa
Technical University, Spring Semester 21/05/2017

left outside because it is not critical to stabilize the robot and just to achieve
some desired performance. The presented control system can be embedded
in most of modern microcontrollers for example by directly generating C
code from this Simulink model.

Fig. 23. Cascade PID implementation

43
HOW TO BALANCE A TWO-WHEELED ROBOT Borja Gómez Ortigosa
Technical University, Spring Semester 21/05/2017

5. Conclusion.

In conclusion, we can deduce that robotics is one of the most


complete fields of technology. A single robot requires knowledge of
Microtechnology; Computer Science to program it; Physics to be able to
calculate its limitations, transport objects; Telecommunications if they
require remote control, or communicate with each other; Electronics to set
up its entire electrical installation, ...

Nowadays, although we do not realize it, robotics is not essential,


but very common in our lives (the kitchen robot, home automation, some
children's toys, some systems that incorporate certain cars ...).

What I want to say with this? Modern robotics has developed very
fast, just as it has entered in our daily lives in just one decade, which means
that very probably in the next decade we can see something completely
different from what we know today, something much more advanced and
perfected, a kind of technology that makes our lives a simple walk full of
facilities.

Therefore, we believe that we must continue to research and


develop this science as we have done in recent years. Who knows? Maybe
someday we'll treat them like one more person.

44
HOW TO BALANCE A TWO-WHEELED ROBOT Borja Gómez Ortigosa
Technical University, Spring Semester 21/05/2017

6. Bibliography

[1] Caulley D., Nehoran N., Sherry Z. (2009). Cornell University,


Electrical & Computer Engineering. A Segway style self-balancing robot.
[2] Majczak, M. (2011). Institute of Control and Computation Engineering
Warsaw University of Technology. Comparison of two efficient control
strategies for two-wheeled balancing robot.
[3] Sample information technology essay from a student. Two wheeled self
balancing robot information technology essay.
[4] Mechanical blog (19th June, 2010). Classification of robot.
[5] Ronald Ping Man Chan, Karl A. Stol, C. Roger Halkyard (11th April,
2013). Mechanical Engineering Department, University of Auckland, New
Zealand. Review of modelling and control of two-wheeled robots.
[6] Visioli A. (2006). Electronic Department, University of Brescia, Italy.
Practical PID. Taken from:
[7] Polyengineer. Self-balancing robot, PID.

45

También podría gustarte