Simulation and Control Two Wheeled Self
Simulation and Control Two Wheeled Self
Abstract—A two-wheeled self-balancing robot is a special variables, nonlinear and strong coupling properties and
type of wheeled mobile robot, its balance problem is a hot mobility [12]. The two-wheeled robot is the combination of
research topic due to its unstable state for controlling. In this wheeled mobile robot and inverted pendulum system. It also
paper, human transporter model has been established. brings the concept of creating a transporter for human. The
Kinematic and dynamic models are constructed and two inverted pendulum is not actuated
control methods: Proportional-integral-derivative (PID) and by itself, it uses the gyroscopes and accelerometers to sense
Linear-quadratic regulator (LQR) are implemented to test the inclination off the vertical axis. In order to overcome the
the system model in which controls of two subsystems: self- inclination, the controller generates torque signals to each
balance (preventing system from falling down when it motor for preventing system from falling down to the
moves forward or backward) and yaw rotation (steering ground. It is a control model in which the object can be
angle regulation when it turns left or right) are considered. controlled only by adding loads on it. This kind of novel
PID is used to control both two subsystems, LQR is used to challenge is implemented and such controller has attracted
control self-balancing subsystem only. By using simulation interests of many researchers.
in Matlab, two methods are compared and discussed. The Although there are many research works in this field [14]-
theoretical investigations for controlling the dynamic [17], only few of them have developed the big human
behavior are meaningful for design and fabrication. Finally, transporter vehicles [2], [7], [10]. Even though some
the result shows that LQR has a better performance than PID researches focus on the human transporter vehicles, but none
for self-balancing subsystem control. of them made clear comparisons between the PID and the
LQR control methods [13]. The following discussions will
I. INTRODUCTION be around these topics. Based on the dynamic theory, we
In recent years, two-wheeled inverted pendulum robot has will analyze self-balance system, establish the mathematical
been developed quickly. Self-balancing robot like the model, and explain both the proportional-integral-derivative
Segway has been absolutely recognized and used as a human (PID) and linear-quadratic regulator (LQR) control theories
transporter especially for policeman. It is an ideal object of in detail. Eventually, the simulation will be performed,
mechatronics, which includes electronic device and which demonstrates that LQR has a better performance in
embedded control. A small mobile inverted pendulum called controlling this kind of system.
JOE [1] is controlled by a joystick, which can be kept in
balance whenever moving and turning. A feedback control II. MECHANICAL DESIGN
educational prototype HTV [2] is developed, which can In this model, the structure of a self-balancing robot is exp
move either on the ground or on the sloped surface. It has ressed. The robot is able to afford a maximum 100kg load. If
great robust and matured mechanical structure. But it is a a big load is added to the robot, it will have a large inertial.
little bit of less comfortable compared to Segway. Segway
[7] is fabricated as a first human transporter. Lego company
designed a LegWay robot [8]. In Legway robot, the
differential driven method has been brought into design. So
the robot could move either on inclined plane or irregular
surface by using remote control operation. A simple self-
balancing robot with Lego is constructed, which includes
AVR controller and some sensors [9]. A low cost self-
balancing vehicle has been developed in Brno university
[10]. An intelligent two-wheeled robot called Balance Bot
[11] is made. Then the obstacle function can be
implemented. Many researchers and engineers are working
on that because of its unstable nature, high order multi-
Fig. 1. A model of the robot via Solidworks.
This work was supported in part by National Natural Science Foundation
of China (Grant No. 61128008), Macao Science and Technology Here, we use two DC motors of 24V, 24A with 1:6 gear
Development Fund (Grant NoS. 016/2008/A1 and 108/2012/A3), Research
Committee of University of Macau under Grant Nos.: MYRG183(Y1- ratio. The two motor controllers with 24V power supply
L3)FST11-LYM and MYRG203(Y1-L4)-FST11-LYM). export currents with the maximum of 30A to control the two
W. An and Y. Li are with ¹Department of Electromechanical DC motors through PWM signal. The motors and tires are
Engineering, University of Macau, Taipa, Macao SAR, China. combined together through chain transmission. It must be
Y. Li is also with ²School of Mechanical Engineering, Tianjin University
sure that the axes of them are parallel. We adopt
of Technology, Tianjin 300191, China. *Corresponding author e-mail:
[email protected]. Atemega128A (AVR series 8-bit RISC MCU) for
456
978-1-4799-2744-9/13/$31.00 ©2013 IEEE
microcontroller because it has good functtionality of rapid
data transfer and low cost.
In mechanical structure design, the lowerr part is consisted
of wheels, motors, wheel brackets and plattform. The upper
part is steer bar which is used to turn the boody system. In the
mathematic model, the variables are definedd as follows:
z Center of mass: c
z Mass of body system:
z Mass of wheel:
z Wheel radial: r
z Distance between center mass of thee body and wheel (a)
axle: L
z Motor gear ratio: n
z Pitch angle: θ b
z Distance between two wheels: d
z Angle velocity of left wheel: θlw
z Angle velocity of right wheel: θrw
(b)
Fig. 2. (a) Free body diagram of the oveerall system, (b) Free body
z Momentum of inertia of the body rotaating along center
diagram of the wheel.
w
of wheel (z-axis):
z Momentum of inertia of the body rrotating along y-
axis: V2 z = sin δ
(
r θlw +θlw )
z Momentum of inertia of wheels rotatting along y-axis: 2 (6)
457
The kinetic energy of wheels can be written as: U = mv gL cos θb (19)
k
w ( ) (
= klw + k L|r + k L|z + krw + kr |r + kr |z = )
(13) Dissipation energy of the whole system is
1
2 w
( lw )(
m r 2 + J y θ2 +θrw
4 w
)
2 + 1 m r 2 (θ −θ ) 2
lw rw G=
1
2 2 ⎣⎢
( )
μ ⎡α 2 + β 2 + 2 α + β θb + 2θb ⎤⎥ +
⎦
(20)
1 2 1 2
where K is the translational kinetic energy of the left μ α + μ 2 β
2 2 2
wheel, K is the translational kinetic energy of the right
wheel. The rotational kinetic energies for each wheel are C. The Lagrange Equation
K and K . K and K are the kinetic energies of the d ∂k ∂k ∂U ∂G
left wheel and the right wheel respectively when the wheels ( )− + + =τ l
dt ∂α ∂α ∂α ∂α
rotate along the z-axis.
d ∂k ∂k ∂U ∂G
The total kinetic energy of the body can be expressed as: ( )− + + =τ r
dt ∂β ∂β ∂β ∂β
1 2 2
vw 8 w ( lw rw )
k =k +k +k = m r θ +θ d ∂k ∂k ∂U ∂G
v vm vy
( )− + + =− (τ l +τ r ) (21)
dt ∂θb ∂θb ∂θb ∂θb
1
( )
1
(
+ mv L2 + J vwc θ2 + mv Lrθb θlw +θrw cosθb
2 b 2 ) where , is the reaction torques of the left wheel and the
right wheel respectively. Substitute (18), (19), and (20) into
1 R2
+ ( )
m L2 sin 2 θb + J vy (θlw −θrw )
2 D2 v
2
(21). Then the nonlinear equation is linearized by Setting
(14)
(α −β )2 =0 , θb (α − β ) =0 , θb2 =0 , sin θb =θb , cosθb =1 . (22)
where K is the kinetic energy of the body when it
rotates along the center of wheel, K is the kinetic energy of After that we can obtain the state equation
the body when it rotates along the y- axis, and K is the ⎡θb ⎤ ⎡θb ⎤
kinetic energy of the lower part when it rotates along the y- ⎢ ⎥ ⎢α ⎥
α
⎢ ⎥
axis. ⎢ ⎥
⎢ β ⎥ ⎢β ⎥
The kinetic energy of the rotor of the motor is: ⎢ ⎥ =A ⎢ ⎥ +Bu (23)
⎢θb ⎥
1 ⎡ 2 2⎤ ⎢θb ⎥
2 ⎣
( ) (
km = J m n 2 ⎢ θlw −θb + θrw −θb ⎥
⎦
) ⎢ ⎥
⎢α ⎥
⎢ α ⎥
⎢ ⎥
(15)
⎢β ⎥
⎣ ⎦ ⎢⎣ β ⎥⎦
The total kinetic energy k of overall system can be
divided into three parts: the wheel kinetic energy kw , the where
⎡ 0 0 0 1 0 0 ⎤ ⎡ 0 0 ⎤
body kinetic energy kv and the kinetic energy of the rotor of ⎢ ⎥ ⎢ ⎥
⎢ 0 0 0 0 1 0 ⎥ ⎢ 0 0 ⎥
the motor k m . ⎢ 0 ⎥ ⎢ 0
0 0 0 0 1 0 ⎥
A=⎢ ⎥,B = ⎢ ⎥,
⎢ A41 0 0 A44 A45 A46 ⎥ ⎢ B41 B42 ⎥
k = km + kv + k w ⎢A
(16) 0 0 A54 A55 A46 ⎥ ⎢B B52 ⎥
⎢ 51 ⎥ ⎢ 51 ⎥
Substituting θlw and θrw by ⎢⎣ A61 0 0 A64 A65 A66 ⎥⎦ ⎢⎣ B61 B62 ⎥⎦
⎢⎣
1
2 ( 1
)
2 ⎜ 2
m mv L sin θb + Jvy ⎟ 1
k = ⎢⎢ mwr2 + J z + r2 ⎜ w +
D2
+ Jmn2mwr2 ⎥⎥
⎟ 16
⎥⎦ V. ROBOT SYSTEM CONTROL
⎝ ⎠
458
elimination. (2). The integral part which is used to average B. LQR Control
past error. (3). The derivative part is to predict the further The linear-quadratic regulator (LQR) is to run a dynamic
error through past error variation. The final control value system under optimal solution. We assume that the robot
can be calculated by simply adding these three terms system has the state equation
together
de ( t ) ( ) ( ) (29)
u = k p e ( t ) + ki ∫ e ( t ) dt + kd . (24)
dt
The desired output performance can be achieved by tuning where A and B are two constant matrices calculated from
and designing three gains. There are many methods of the dynamics model. And this state equation can also be
choosing suitable values of the three gains to achieve the explained as
satisfied system performance. (30)
Substituting (30) to (29), the state equation becomes
cl θb
input(t ) u
θb ( ) (31)
cr
Here we assume 0 . In order to find the optimum
control vector ( ) under two chosen constants Q and R, the
Fig. 3. Robot Control System. function
( ) (32)
Fig.3 shows the whole dynamic control system. We set must be minimum. Where Q is positive semi-definite
the sample time T equal to 0.05s. We denote as the control ( 0) and R to be positive definite ( 0). In
value which is calculated from PID controller and further this robot system, we use output as feedback signal.
decoupled it into and (the input torques for right and left
motors respectively) for controlling the two motors. is Substitute (30) into (32), we have
used in self-balance control and is used in yaw control.
, are transformed to , in the process called ( ) (33)
decoupling:
459
τl θb
•
θ
s b
τr
−−−
U'
+
+
+
(c)
Fig. 5. (a) PID simulation diagram for self-balancing control,
(b) Result of tilt angle, (c) Result of tilt angle rate.
Fig. 4. LQR control of robot.
Fig. 5 shows the performances of the inclined angle and
VI. ROBOT SYSTEM SIMULATION the inclined angle velocity in self-balance control. While the
Both PID with LQR are tried and compared in the aspects rider is moving forward and backward, PD controller
of the performance of the control system. Then the better outperforms a relative fast steady-state response.
one is adopted in our robot system and a more accurate and The yaw control subsystem is:
fast system response can be achieved. Essentially, system
can be stable within 4s. Otherwise, the operation will be x 2 = A2 x2 + B2u 2 (40)
failed and cause physical injury to human.
A. Simulation of PID Control which is = + [ ], where
The self-balancing subsystem described by
− ( μ1 + μ 2 )
x1 = A1 x1 + B1u1 , Y1 = C1 x . (39) A = = −0.12,
2 r2
2
2( mwr + J z + 2 2
J vy + J m n )
which is in detail as d2
⎡θb ⎤ ⎡ 0 1 0 ⎤ ⎡ 0 ⎤ r
B = = 0.07.
⎢θ ⎥ = ⎢ 25 −1.85 19 ⎥ x + ⎢ −0.3⎥ τ +τ 2 r2
⎢ b⎥ ⎢ ⎥ 1 ⎢ ⎥ [ l r] d (2 mwr 2 + J z + 2 J vy + J m n 2 )
⎢⎣ s ⎥⎦ ⎢⎣ −43 −0.17 1.075⎥⎦ ⎢⎣ 0.4 ⎥⎦ d2
⎛ θ ⎞
Y1 ⎜ ⎡⎢ b ⎤⎥ ⎟ = , c1 = ⎡⎢1 0 0 ⎤⎥
⎝ ⎣θb ⎦ ⎠ 0 1 0
⎣ ⎦
.
(a)
(a)
(b)
460
Fig. 6 shows the system result undder yaw control generate the control value, the systeem will be failed without
circumstance. The subsystem has relatively slow steady-state a precise feedback signal of tilt an ngle if PID is used. The
by using PD controller. advantage of LQR is that it can integrate
i all output state
variables (tilt angle, tilt angle rate, position) to calculate the
B. Simulation of LQR Control
control value. The robot system can c still get stabilization
After trying the values of Q and R for many times, we from other output state variables signal even though one of
conclude that associated with inclinationn angle would be state output variables is inaccurate. This
T allows robot to hold
either positive or negative. However, to approach stable the stabilization in a desired time. We have found that the
system, , can never be negative. If setting a high R time to achieve the steady state off robot by LQR is faster
value, the response time of system will bbe relatively low than by PID.
because that would reduce the control abiility of the motor.
And in the other way, the response time off system would be VII. CONCLUSSION
faster with a lower R value. So we sett R equals to 1.
Essentially, how to choose a suitable Q Q, represented by In this paper, based on mechanicaal structure and dynamic
0 0 models, the modeling and analysiss of self-balancing robot
matrix 0 0 , must be taken into conssideration. Where are discussed by using Lagrangee equation and energy
0 0 conservation principle, PID and LQ QR control algorithms are
a is associated with tilt angle, b is associatted with tilt angle tried. It is concluded that LQR has a better performance than
rate and c is associated with system displlacement. Setting PID in self-balancing control. In ouro future work, we will
larger a in the matrix can lead to quick incclination response use LQR method to control a physiccal two-wheeled robot to
of the system. In our system, the performannce will almost be further verify the controller’s perform
mance.
the same whatever the value of a is taken rranging from 2 to
50 times more of b, or c. Therefore we set the value of Q as References
[1] F. Grasser, A. D. Arrigo, and S. Colom mbi, “JOE: A mobile, inverted
⎡ 200 0 0 ⎤ pendulum”. IEEE Trans. Ind. Electron, vol. 49, pp. 107–114, 2002.
⎢ ⎥
⎢ 0 10 0 ⎥ . Eventually the gain k can b
be calculated as [- [2] S.-C. Lin and C.-C. Tsai, “Develop p of a self-balancing human
⎢⎣ 0 transportation vehicle for the teachingg of feedback control,” IEEE
0 10⎥⎦ Trans. Education, vol.52, no.1, pp.157--168, 2009.
23.32 19.21 63.85] by applying lqry() funnction in Matlab. [3] T. Tomašić, A. Demetlika, M. Crnekov vić, “Self-balance mobile robot
We obtain the simulation result as shown inn Fig.7 (b). tilter,” Transactions of FAMENA, vol.36 6, no.3, pp.23-32, 2012.
[4] F. L. Lewis, Linear Quadratic Regu ulator (LQR) State Feedback
Design, 1998.
[5] T. Takei, R. lmamura, S. Yuta, “Baggag ge transportation and navigation
by a wheel inverted pendulum mob bile robot,” IEEE Trans. Ind.
Electron., no.56, pp.3985-3994, 2009.
[6] L. Sun, J. Gan, “Researching of two o-wheeled self-balancing robot
based on LQR combined with PID,,” International Workshop on
Intelligent systems and Applications, pp
p.1-5, 2010.
[7] http://www.segway.com.
[8] http://www.teamhassenplug.org/robot/leegway.
[9] H. Ferdinando, H. Khoswanto, S. Tjok kro, “Design and evaluation of
two-wheeled balancing robot chassis,” IEEE International Conference
on Communications, Computing and Control Applications, pp.1-6,
2011.
[10] Grepl, R., Zouhar, F., Štěpánek, J., Horrák, P. , “The development of a
self-balancing vehicle: A platform fo or education in mechatronics,”
Faculty of Mechanical Engineering, Brno University of Technology.
[11] http://www.art-of-invention.com/roboticcs
[12] S. Kim, S. Kwom, “SDRE based nonliinear optimal control of a two-
(a) wheeled balancing robot,” Journal off Institute of Control, Robotics
and Systems, pp.1037-1043, 2011.
[13] Y. Yun and Y. Li , “Active vibration control based on a 3-dof dual
compliant parallel robot using LQR L algorithm,” IEEE/RSJ
International Conference on Intelligen nt RObots and Systems (IROS),
October 11 - 15, 2009, St. Louis , MO, USA , pp.775-780.
[14] J.-G. Wang and Y. Li, “Analysis on n the Interaction between the
Nonholonomic Mobile Modular Robott and the Environment,” IEEE
International Conference on Robotics and Biomimetics(ROBIO),
December 18-22, 2009, Guilin, Guangx xi, China, pp.86-91.
[15] J.-G. Wang and Y. Li , “Kinematic an nalysis of a mobile robot with
two-body frames,” IEEE Internationa al Conference on Information
Automation(ICIA) , June 20-23, 2008, Hunan,
H China, pp.1073-1078.
(b) [16] Y. Liu and Y. Li, “Dynamics and model-based control for a mobile
Fig. 7. (a) LQR simulation diagram, ((b) LQR control modular manipulator,” Robotica, vol. 23, pp. 795-797, 2005.
simulation. [17] J.-G.Wang and Y. Li, “Static Force An nalysis for a Mobile Humanoid
Comparing those two control methods, itt is observed that Robot Moving on a Slope,” IEEE International Conference on
LQR has a better performance than PID in self-balancing Robotics and Biomimetics (ROBIO), Baangkok, Thailand, February 22-
25, 2009, pp.371-376.
control. Since PID can only use one feeedback signal to
461