Design, Simulation and Optimal Control of Two-Wheel Self-Balancing Robot Using LQR and PID
Design, Simulation and Optimal Control of Two-Wheel Self-Balancing Robot Using LQR and PID
ISSN: 1001-4055
Vol. 45 No. 3 (2024)
_______________________________________________________________________________________
1. Introduction
Technological advancements in the 21st century have seen so many developments in the field of automation with the
mass production of both industrial and domestic devices and machines that are faster, efficient and more convenient
when used. This has significantly contributed to improving human life and creating a safer environment. One device
that has garnered considerable attention in the research field is the Two-Wheel Self-Balancing Robot (TWSBR) [1].
Despite its inherent instability, the two-wheeled robots, in various applications, present a compact and user-friendly
mobile platform. This necessitates an optimized system capable of delivering enhanced performance, user satisfaction,
and ultimately and value for the money invested. The mobile robot finds applications in local transportation, hotels and
catering, surveillance, warehouses, patient wheelchairs, and more [2]. Wide range of applications and the challenges
related to stability control of mobile robot were among others the motivating factors for undertaking this project.
In this paper, design, simulation and optimal control of TWSBR are presented. The control objective is basically aimed
at balancing the robot whenever an external force act on it causing a change in the vertical equilibrium state thereby
prevent the TWSBR from falling. The sequence of physical actions which characterized the control action of the two-
wheel self-balancing robot is a similitude of balancing a vertical bar place or fixed on a horizontal surface, for instance
a stick on a flat surface of human finger. Similar concept can be applied in the Self-balancing robot system by
signalling the actuator (the DC motor) to move the robot in the direction where the main body inclinedto. This forces it to
maintain its equilibrium position [2-3].
1681
Tuijin Jishu/Journal of Propulsion Technology
ISSN: 1001-4055
Vol. 45 No. 3 (2024)
_______________________________________________________________________________________
1.1 Structure of the Self-Balancing Robot.
The two-wheeled balancing robot is associated with the concept of a free-fall system, emphasizing its inherent
instability due to the utilization of only two wheels. In the absence of internal or external forces, this robot is prone to
tipping either forward or backward, resembling an inverted pendulum that demands dynamic adjustments for
maintaining equilibrium. In a scenario where the robot faces a loss of balance, the need for actuator, whether a DC
motor or stepper motor becomes crucial. Its rapid response and adjustments in the direction of the impending fall are
vital for counteracting destabilizing forces and ensuring that the chassis remains in an upright position.
Unlike a stable system, the two-wheeled robot constantly contends with delicate equilibrium, similar to the intricacy of
balancing an inverted pendulum. This continuous balancing act necessitates ongoing adjustments by the actuator,
presenting a captivating and complex engineering challenge [4]. Figure 1 below shows the free body diagram of the
TWSBR. Fundamentally, the free-fall characteristic of the two-wheeled balancing robot underscores its perpetual
interaction with gravitational forces and thus requires real-time control action to preserve stability. This concept not
only highlights the engineering complexities involved but also forms the basis for the development of robust control
strategies, ensuring the robot's effective self-balancing across diverse conditions and scenarios.
1682
Tuijin Jishu/Journal of Propulsion Technology
ISSN: 1001-4055
Vol. 45 No. 3 (2024)
_______________________________________________________________________________________
set of resources and technologies to achieve proper balancing of the robot. Sensors such as Infrared sensors and
gyroscope were employed in balancing the robot while the likes of ultrasonic sensor, “LiDAR”sensor and others are used
for obstacle avoidance and Navigation [3-5]. Back in time when curiosity and industrial demands rose significantly
about new emerging technologies in automation and artificial intelligence for navigation applications, the first
autonomous electronic robot known as Elsie and Elmer was introduced by William Grey Walter in the year 1948[6].
Moving fast forward, initial attempts were made to produce the inverse pendulum type robot in the year 1991-1992. In
the year 1996 a 2-dimensional mobile inverse pendulum robot was designed capable of moving with constant velocity
using control algorithm [7]. The most popular application of mobile robot was the Segway PT invented in 2001 by D.
Kamen was the first commercialized in the year 2021 [8]. The vehicle shown in Figure 2 is powered by a battery and has
the capability of balancing itself with the help of a complex control system and uses five gyroscope sensors to measure
tilt angle [9]. It was the first successful commercial robot vehicle which brought Segway Inc. great fortunes and
recognition. A novel approach to the design of mobile robot using linearization technique was adopted to formulate its
state space equation. Researchers reported that several controllers were designed to maintain the desired angular
orientation while separate other controllers were used to maintain the horizontal position of the mobile robot. A
comparative was conducted to investigate the performance of Proportional–Integral–Derivative (PID), Linear–
Quadratic Regulator (LQR), and Artificial Neural Network (ANN) controllers. The performance of each control
algorithm was assessed after subjecting the system to external disturbance. Results of their experiments showed that
Artificial Neural Network(ANN) controllers have better performance in terms of disturbance rejection [10].
1683
Tuijin Jishu/Journal of Propulsion Technology
ISSN: 1001-4055
Vol. 45 No. 3 (2024)
_______________________________________________________________________________________
values in the LQR regulator, which significantly influence the accuracy of the desired control signals. The study
recommends the incorporation of a Kalman filter to mitigate noise from the gyro data. [13]. Recent studies have focused
on improving the stability, control, and performance of two-wheel self-balancing robots. The integration of advanced
sensors, such as gyroscopes and accelerometers, has enabled precise measurement of orientation and motion, thereby
enhancing the balancing capabilities of these robots. Researchers have also utilizedPID control techniques, including the
Ziegler-Nichols and Cohen-Coon tuning methods, to achieve efficient control and stability [14]. The design and control
of two-wheel self-balancing robots pose several challenges, including maintaining dynamic balance, responding to
external disturbances, and achieving accurate positioning. Researchers have addressed these challenges through
innovative control algorithms, sensor fusion techniques, and robust hardware implementations. The use of feedback
systems, motor control modules, and microcontrollers, such as the Arduino Mega 2560, has facilitated precise control
and real-time adjustments in these robots [15-16]. Two-wheel self-balancing robots have found diverse applications
across various industries, including surveillance, logistics, entertainment, and education. These robots offer mobility,
agility, and versatility, making them suitable for tasks that require dynamic movement and precise control. The
integration of Bluetooth modules, such as the HC-05, has enabled wireless communication and remote-control options,
enhancing the functionality and usability of these robots [16-18]. Ryuichi T et a proposed a self-balancing obstacle
avoidance robot using a combination of PID and Fuzzy Logic Controller (FLC) algorithms. The FLC takes input
distance data between the robot and obstacles, and outputs control commands that steer the robot away from obstacles.
The proposed method utilizes a cost-effective, fixed-point digital signal processor (DSP) control system that reduces
computational complexity and costs compared to floating- point arithmetic. The system's calculations were tested
and compared against those of a conventional software. implementation, showing that the custom instructions were
faster than libfixmath. The authors' simulation results revealed that the proposed method has lower computational
complexity and cost compared to other approaches such as dynamic window algorithm and potential field method [19].
Aldhalemi et al. presented the design and implementation of a remotely controlled two-wheel self-balancing robot. The
control system's hardware development consists of two Arduino boards, a Bluetooth HC05, a gyroscope sensor, a
stepper motor, and a motor driver. The robot is controlled through an Android GUI application on a smartphone. The
authors analyzed the dynamic model and control algorithms for the robot's responses in moving mode. They also
discussed potential applications of the proposed robot in surveillance, exploration, and entertainment, and suggested
further research for system optimization. However, the use of a stepper motor may limit the long-term usage of the
robot due to its higher battery drain capability compared to other types of DC motors [20]. Nguyen H.V. et al. proposed
a balancing method for a unicycle robot using a PD controller. The authors developed a PD controller for a two-
wheeled self-balancing robot and a reaction wheeled inverted pendulum. They performed simulations and experiments
to find a suitable set of PD controllers and calibrate the control parameters, with a focus on the proportional gain Kp.
The authors used genetic algorithms and trial-and-error tests to find a set of PD controllers that balance the unicycle
robot well. They noted that increasing Kp causes the system to vibrate more, while decreasing it results in insufficient
control signals. The paper includes comparison graphs of system response for different cases, demonstrating the success
of the proposed PD control method in balancing the unicycle robot [21].
2.2 Review analysis
This review highlights the evolution and development of two-wheel self-balancing robots as a dynamic and
multidisciplinary research field, with significant milestones from the first autonomous electronic robot, Elsie and
Elmer, in 1948 to the commercialization of the Segway PT in 2021. Researchers have utilized various sensors,
including Infrared sensors, gyroscopes, ultrasonic sensors, and LiDAR sensors, for balancing and navigation. Recent
research has focused on enhancing stability, control, and performance, with researchers integrating advanced sensors
and PID control techniques for efficient control and stability. The literature survey also highlights the diverse
applications of two-wheel self-balancing robots across various industries, including surveillance, logistics,
entertainment, and education. The integration of Bluetooth modules has enabled wireless communication and remote-
control capabilities, enhancing functionality and usability. Recent studies on novel control algorithms provide insights
into the future directions of research in this field. The study demonstrates the potential of hybrid controllers in
1684
Tuijin Jishu/Journal of Propulsion Technology
ISSN: 1001-4055
Vol. 45 No. 3 (2024)
_______________________________________________________________________________________
achieving better performance and robustness in controlling two- wheel self-balancing robots [22-24]
3. Methodology
3.1 Model Preparation
This section of the paper presents a detailed description of the proposed electromechanical system. It is an unstable
system with a basic framework built on the principle of Inverted pendulum. A Set of differential equations describing
the laws governing the motion of the robot were developed and expressed in state-space form. The proposed robot is
designed in such a way that the chassis (pendulum arm) which stands on a horizontal platform about a movable pivot
must balance itself, otherwise it will fall in either forward or backward direction. A key component in this project
work is the Inertial measurement unit (MPU6050) carrying in it a gyroscope and accelerometer measures angular
position of the chassis and provide such signal in closed loop feedback to the PID controller for generating the
required control command.
3.2 Mathematical modelling
Three sub-sections of the physical model namely: the Chassis, DC motor and the wheels were presented here. analyzing
the forces acting at a given reference point in each of the subunits, differential equations were developed using
Newton’s second law of motion. The major parts of the inverted pendulum as shown in Figure 3 include a movable cart
of mass, M rolling sideways on two identical wheels, pendulum arm of mass m hinged on a movable cart. The center of
gravity is located at a distance l from one end which is half the length of the pendulum arm for a uniformly distributed
arm, the tilt angleθ.
1685
Tuijin Jishu/Journal of Propulsion Technology
ISSN: 1001-4055
Vol. 45 No. 3 (2024)
_______________________________________________________________________________________
𝐼𝑊 𝒌 − (4)
𝜔̇ = 𝒎
𝒌 𝒎𝒌 𝒆 𝜔
𝑽
𝒂 𝑅
𝑅
Since the rotor speed of the DC motor is given by 𝜔 = 𝜃̇. Therefore, the linear model of the DC motor can be writtenas:
1686
Tuijin Jishu/Journal of Propulsion Technology
ISSN: 1001-4055
Vol. 45 No. 3 (2024)
_______________________________________________________________________________________
Combining the equations (11) and (12) gives the state-space model of the two-wheel self-balancing robot as
1688
Tuijin Jishu/Journal of Propulsion Technology
ISSN: 1001-4055
Vol. 45 No. 3 (2024)
_______________________________________________________________________________________
1689
Tuijin Jishu/Journal of Propulsion Technology
ISSN: 1001-4055
Vol. 45 No. 3 (2024)
_______________________________________________________________________________________
3.4.2
Linear Quadratic Regulator (LQR)
The control objective is to determine the matrix gain K such that for any initial state x(0), the control law
𝑢(𝑡) = −𝐾𝑥(𝑡)(18)
Minimizes the performance index:
∞
𝐽 = ∫(𝑥𝑇𝑄𝑥 + 𝑢𝑇𝑅𝑢)dt (19)
0
𝑤ℎ𝑒𝑟𝑒 𝑄 ≥ 0 𝑎𝑛𝑑 𝑅 > 0
Subject to the dynamics of the systems represented in state space model (equation 13 and 14) A, B, C, and D
represent the dynamics of the system and the optimal feedback gain is given by:
𝐾 = 𝑅−1𝐵𝑇𝑃 (20)
The NUCLEO-F401RE development board built with STM32F401REE microcontroller based on Cortex- M4
architecture from STMicroelectronics was selected for this project. The development board can be powered with a DC
voltage range of 1.7V-3.6V in addition to a wide range of 7V–12V and has a 32-bit RISC core operating at maximum
frequency of 4MHz with a floating–point unit (FPU). It is equipped with 512Kilobytes flash memory for program
storage offering 96 Kilobytes of RAM for data storage. It also has 50 GPIO pins with external interrupt capability as
well as 12-bit ADC pins on board. Communication interfaces available on the board include USART, SPI, I2C and
USB 2.0 OTG FS. STM32CubeIDE is used for programming the board which also has Arduino UnoV3 connectivity
and ST morpho headers [25]. The development board support for advanced motor control makes it suitable for precise
motor control required in this project. Figure 9 shows the front image of the development board. Direct current (DC)
geared motor is chosen to drive the wheels whenever the tilt angle deviates from thereference set-point.
1691
Tuijin Jishu/Journal of Propulsion Technology
ISSN: 1001-4055
Vol. 45 No. 3 (2024)
_______________________________________________________________________________________
4. Results
This section of the paper presents the simulation results obtained during the project implementation. Using the state
space model presented in equation (15) and (16), a MATLAB program for the parameter setting and generation of the
model matrices was developed as shown in Figure 9. Table 1 shows the parameters of the developedtwo-wheel robot.
The moment of inertia for the chassis and the wheels were calculated using equation (22) and (23) respectively:
𝑊 2 𝑊
After arranging the simulation setup, the first test conducted was that of controllability test to determine whetherthe state
variables of the system could be steered from any initial state to another state by applying suitable control action.
Equation 24 gives the controllability matrix Qc as follows:
1692
Tuijin Jishu/Journal of Propulsion Technology
ISSN: 1001-4055
Vol. 45 No. 3 (2024)
_______________________________________________________________________________________
It could be seen from the equation (26) that only two of the open-loop poles are located on tt half of thecomplex s-plane,
one is located at the origin and the other at the right half of the complex s-plane. Figure 11 shows unbounded output
(Tilt angle) response to a bounded step input. This is due to the existence of the open-lop pole on the right half of the
complex s-plane. This made it clear that the open-loop system of the robot is unstable.
Table 1: Parameters of the developed robot
Parameter Value Unit
1693
Tuijin Jishu/Journal of Propulsion Technology
ISSN: 1001-4055
Vol. 45 No. 3 (2024)
_______________________________________________________________________________________
Figure 12 shows the parameter settings of the Linear Quadratic Regulator as implemented in the MATLAB
environment. The result shows critical value of LQR gain which is used for regulating the desired state variables to
zero. Having obtained the gain constant K of the LQR, its value was used to implement LQR whose block diagram
shown in Figure 7. The result is shown in Figure 13 in which the robot’s displacement is made to track a reference
signal while the remaining three state variables namely linear velocity, tilt angle, and the angular velocity are regulated to
zero. Figure 14 shows the block diagram of the hybrid model.
1694
Tuijin Jishu/Journal of Propulsion Technology
ISSN: 1001-4055
Vol. 45 No. 3 (2024)
_______________________________________________________________________________________
1695
Tuijin Jishu/Journal of Propulsion Technology
ISSN: 1001-4055
Vol. 45 No. 3 (2024)
_______________________________________________________________________________________
5. Discussion
This section discusses the results obtained, which aimed to compare the performance of two control strategies for two-
wheel self-balancing robots. The findings demonstrate the potential of hybrid controllers in achieving better
performance and robustness in controlling these robots, highlighting the significance of integrating advanced sensors
and control techniques for optimal control.
5.1 Tilt angle response
Considering the parameters obtained from the tilt angle response, the hybrid controller algorithm outperforms the LQR
controller in several aspects when controlling the tilt angle response of model mobile robot.
i. Percentage overshoot: The hybrid controller has a significantly lower percentage overshoot (13.3%)
compared to the LQR controller (40%). This indicates that the hybrid controller has better stability and reduces the risk
of oscillations or instability, which is crucial for maintaining balance in a two-wheel self- balancing robot.
ii. Rise time: The rise time of the hybrid controller (0.002 seconds) is considerably faster than that of the LQR
controller (1 second). A faster rise time implies that the hybrid controller can quickly respond to changes in the tilt
angle, allowing the robot to maintain balance more efficiently.
iii. Settling time: The settling time of the hybrid controller (0.19 seconds) is also much shorter than that of the
LQR controller (5 seconds). A shorter settling time indicates that the hybrid controller can reach the desired tilt angle
more quickly, which is essential for the robot's stability and manoeuvrability.
iv. Steady-state error: Both the LQR and hybrid controller have zero steady-state error, which means that the tilt
1697
Tuijin Jishu/Journal of Propulsion Technology
ISSN: 1001-4055
Vol. 45 No. 3 (2024)
_______________________________________________________________________________________
= 130ms, ts = 1 s and ess = 0. However, a slightly lower percentage overshoot was recorded in hybrid mode (10.00%)
as against (16.67%) in the LQR controller configuration. These performance metrics have fully satisfied the set
specification (%O.S ≤ 20%, ts = 2s and minimal steady-state error). The results of this study suggest that the hybrid
controller (LQR+PID) is more effective in controlling the tilt angle and linear velocity of the two-wheel self-balancing
robot compared to the LQR controller. The hybrid controller's superior performance can be attributed to the integration of
PID control, which provides better robustness and disturbance rejection capabilities. The study's findings have
1698
Tuijin Jishu/Journal of Propulsion Technology
ISSN: 1001-4055
Vol. 45 No. 3 (2024)
_______________________________________________________________________________________
significant implications for the development of control algorithms for two-wheel self-balancing robots, as they
demonstrate the potential of hybrid controllers in achieving better performance and robustness.
In summary, this paper presents a comparison between the performance of LQR and hybrid controllers in controlling
the tilt angle and linear velocity of a two-wheel self-balancing robot. The results show that the hybrid controller
produced a better performance in both control variables, with stable responses and minimal steady-state error. The
study's findings highlight the potential of hybrid controllers in achieving better performance and robustnessin controlling
two-wheel self-balancing robots.
References
[1] Rubio F, Valero F, Llopis-Albert C. “A review of mobile robots: Concepts, methods, theoretical framework, and
applications”. International Journal of Advanced Robotic Systems.16(2). 2019. doi:10.1177/1729881419839596
[2] Rabani M. R. M., Ibrahim A. M., Toha S. F. & Rashid M. “Two-wheel Balancing Robot; Review on Control
Methods and Experiments”. International Journal of Recent Technology and Engineering. 7, 2019.
[3] Mohamed Gad O. M., Saleh S. Z. M., Bulbul M. A. and Khadraoui S., "Design and Control of Two Wheeled Self
Balancing Robot (TWSBR)," Advances in Science and Engineering Technology International Conferences
(ASET), Dubai, United Arab Emirates, 2022, pp. 1-6, 2022. doi: 10.1109/ASET53988.2022.9735004.
[4] Katsuhiko Ogata. “Modern Control Engineering,” Pearson Education, Inc., publishing as Prentice Hall, One Lake
Street, Upper Saddle River, New Jersey 07458. 2010.
[5] Zimit A. Y., Hwa. J. Y., Mukhtar F. H. and Indrazno S. “Modelling and Experimental Analysis Two-Wheel Self
Balancing Robot Using PID Controller” Springer International Publishing AG, part of Springer Nature. 2018.
Doi: https://doi.org/10.1007/978-3-319-95165- 2_48
[6] Iwendi C., Alqarni M. A., Anajemba J. H., Alfakeeh A. S., Z. Zhang, and A. K. Bashir, “Robust Navigational
Control of a Two-Wheeled Self-balancing Robot in a Sensed Environment,” IEEE Access, vol. 7, 2019.
[7] Koyanagi E., Iida S., K. Kimoto and Yuta S. “A wheeled inverse pendulum type self-contained mobile robot and
its two-dimensional trajectory control”, Proceedings of ISMCR’92, pp.891-898, 1992.
[8] Kamen D., “Segway PT”, 2001. Available online on: https://www.segway.com/ Accessed 26 March 2024.
[9] Matsumoto O., Kajita S. and Tani K. “Attitude estimation of the wheeled inverted pendulum using adaptive
observer”, Proceedings of 9th Academic Conference of the Robotics Society of Japan, pp.909-910, 1991.
[10] Vinod K. P. and Kamala N. “Design, Dynamic Modelling and Control of Two-wheeled Self-Balancing Robot
(TWSBR)” International Journal of Mechanical Engineering Vol. 7 (Special Issue 5, April-May 2022)
[11] Fabian R. J. L., Ilber A. R. R. and Andrés F. J. L. “Modelling and Control of a Two Wheeled Auto-Balancing
Robot: A Didactic Platform for Control Engineering Education” 18th LACCEI International Multi-Conference for
Engineering, Education, and Technology: July 27-31, 2020. DOI http://dx.doi.org/10.18687/LACCEI2020.1.1.556
[12] K Akhilesh R., Makani R., Jency M., Shriya V. S.1 and Harsha H. IoT Enable Self- Balancing Robot using
LabView RV Journal of Science Technology Engineering Arts and Management vol 2 (1) (2021)
[13] Lwin M. M. T. and Ye C. Application of LQR Control for Two-Wheel Self-Balancing Robot J. Myanmar Acad.
Arts Sci. 2020 Vol. XVIII.No.2C.
[14] Vicky M. & Jayant D. Self-Balancing Robot With Bluetooth Control International Research Journal of
Modernization in Engineering Technology and Science Volume (04) Issue:06 June-2022
1699
Tuijin Jishu/Journal of Propulsion Technology
ISSN: 1001-4055
Vol. 45 No. 3 (2024)
_______________________________________________________________________________________
[15] Mathew A., Ananthu R., Binsy P., Vahid A. Thomas C. & Sidharthan, S. Design and control of a two-wheel
self-balancing robot. IOP Conference Series: Materials Science and Engineering. 2021 DOI:
https://dx.doi.org/10.1088/1757-899X/1114/1/012058
[16] Basant K., Riya C. & Indu B. Two-Wheeled Self-Balancing Robot International Journal of Research in
Engineering and Science (IJRES)
2021.Volume 9, Issue 6, PP. 47-51
[17] Meheswara N. Venkata S. S. Greeshma S. G. & Ajith K.R. Design and Development of Self Balancing Robot”,
International Journal of Research in Engineering, IT and Social Science, ISSN 2250-0588, Impact Factor: 6.565,
Volume 09, Special Issue 2, May 2019, Page 20- 32.
[18] Wang, C., Jianliang, X., & Zhang, C. Fuzzy Neural Network Active Disturbance Rejection Control for Two-
Wheeled Self-Balanced Robot.Journal of Information Processing Systems, 18(4), 510-523. (2022). DOI:
10.3745/JIPS.01.0089
[19] Ryuichi T., Trong-Thuc H. & Cong-Kha P. “An Obstacle Avoidance Two-Wheeled Self-Balancing Robot”
International Journal of Mechanical Engineering and Robotics Research Vol. 11, No. 1, January 2022
[20] Aldhalemi1 A. A., Chlaihawi1 A. A. and Al-Ghanimi1 A. Design and Implementation of a Remotely Controlled
Two-Wheel Self-Balancing Robot 4th International Conference on Engineering Sciences (ICES 2020) 5th-6th
December 2020, Kerbala, Iraq. https://doi.org/10.1088/1757-899X/1067/1/012132
[21] Nguyen H. V. et al. A method of PD control for Balancing a Unicycle Robot. Indonesian Journal of Engineering
and Science, Vol. 4, No. 1, 2023 Nguyen et al. https://doi.org/10.51630/ijes.v4i1.81
[22] Tandan, N., and Swarnkar, K. K. Tuning of PID Controller using Modified Particle Swarm Optimization,
International Journal of Electronics, Electrical and Computational System, 2015. 4, 62-66.
[23] Alkhafaji, F., Wan Hasan, W., Sulaiman, N. & Mohd, M. A Novel PID Robotic for Speed Controller Using
Optimization Based Tune Technique. IntechOpen 2021. DOI: https://doi.org/10.5772/intechopen.95892
[24] NUCLEO-F401RE development board datasheet https://www.st.com/en/evaluation-tools/nucleo-f401re.html
Accessed 2nd February 2024.
[25] Kankhunthod, K, Kongratana, V, Numsomran, A, & Tipsuwanporn, V “Self-balancing Robot Control Using
Fractional-Order PID Controller”, International Multi-Conference of Engineers and Computer Scientists, vol. 7,
no. 4, (2019).
1700