Design and Implementation of a Remotely Controlled Two-Wheel Self-Balancing Robot

This research included the design and implementation of a real-time remotely controlled Two-Wheel Self-Balancing Robot (TWSBR). The aim was to build a low cost TWSBR that could be remotely navigated using Bluetooth wireless technology. Experimentally, the TWSBR consists of two parts: the hardware device and the software algorithm. Bluetooth protocols were used to facilitate communication between a smartphone device and a gyroscope sensor. As the dynamic structure of the robot is inherently unstable, self-stabilisation represents a major challenge, and a robust control algorithm was thus required for this task. A Proportional-Integral-Derivative (PID) was employed to achieve this in real-time with the help of an 8-bit microcontroller. The feedback signal was fed to the PID controller through the gyroscope sensor with the aim of maintaining TWSBR stability and balance based on adjusting its longitudinal angle in response to the gyroscope feedback signal. A prototype robot was then built to validate the proposed algorithm.


Introduction
Two-Wheel Self-Balancing Robots (TWSBRs) have attracted a lot of interest from researchers over the last decade based on their practical multi-disciplinary usage in large-scale industries. TWSBRs offer flexible vehicular solutions to carrying persons or items over a flat floor in a variety of industries. They can easily cover short distances on prepared surfaces for ease of transportation, and their varying tilt angles allow quick manoeuvring [1][2][3]. This kind of robot is, in practice, an inverted pendulum, which is considered inherently unstable and which displays highly nonlinear dynamics systems [4]. As this has been developed to become a human transport vehicle [5], different types of controllers have thus been implemented on TWSBRs, such as Fuzzy Logic Controllers [6], Linear Quadratic Regulators [7], Pole-Placement Controllers [8], sliding mode controllers [9], and Fractional order PID Controllers [10].
Recently, smart systems have improved rapidly, allowing much easier control over appliances and further facilitating lifestyle choices [11]. Smart remote-controlled robot systems are now typically integrated with multiple small and inexpensive embedded microprocessors that allow the use of software with wireless communication interfaces [12,13]. The current project thus seeks to exploit the recent growth in technologies such as smartphones and their applications to extend the field of mobile robot control and guidance. Android smartphones can ow be used to implement and design Graphical User Interface (GUI) programs for various purposes; these phones are also usually equipped with fascinating communication protocols such as Bluetooth. These features make them suitable candidates for IOP Publishing doi:10.1088/1757-899X/1067/1/012132 2 controlling mobile robots. Based on this communication technology, smartphones can be used as a remote-control unit for sending and receiving multi range signals [14]. Bluetooth is now a standard for wireless short-range communication, being commonly used to offer real-time connections between devices. It is a simple, safe, and easy, with low power and low-cost requirements, and it can be used to send information in a range of up to 100 meters [14].
The control of autonomous and semi-autonomous mobile robots has become a popular area of research, with a focus on the different types of user interfaces used to control such robots. As a special kind of mobile robot, the TWSBR has been the focus of multiple studies in this area. For instance, a PID controller was used to control a TWSBR by Ren et al (2008), who used a simple TWSBR as the design platform. They presented a moving control and balance analysis of a two-wheel car based on a selftuning PID controller and guided using two independent wheel drive motors, upon which the car frame was mounted [15]. Liu et al (2011) [16] described the use of Kalman filtering and a PID algorithm as a high-order, multiple-variable, nonlinear, strong-coupling, unstable system, while Velazquez et al (2016) proposed balancing, motion, and velocity control of a self-balancing vehicle. The application of a cascade controller strategy was also presented for both angular velocity control and balancing control [17], and Zhou et al (2018) presented a fractional order PID control method for a two-wheeled electric vehicle using particle swarm optimisation to develop control parameters and to manage state feedback gains, with simulation results that achieved good performance and a larger setting range [10]. Sumantri et al (2019) introduced a two-wheeled electric skateboard based on Fuzzy-PID control to improve the energy consumption of personal cars, based on reducing electric energy consumption by the application of a Fuzzy-PID TWS instead of a conventional PID [19].
This research aimed to design and implement a real time remote controlled (semi-autonomous) TWSBR integrated with the most recent communication and control technologies. The rest of the paper is organised as follows: Section two describes the mathematical modelling, while section three presents the hardware development and section four discusses the PID controller. Finally, section five discusses the results in detail.

Mathematical modelling
A mathematical model of a TWSBR is an essential part that of developing and simulating such a robot in a safe and virtual environment. The physical problems with TWSBRs lie in the limited capability of such a robot to balance on its two wheels without tipping over. Managing a TWSBR involves several different physics and control theories. Theoretically, the TWSBR is an inverted pendulum system, which is a naturally unstable system. In general, a two-wheel self-balancing robot is thus an electric vehicle structure composed of two parts: a moving part and a rigid chassis. Figure 1 shows a typical two-wheel self-balancing robot.

Electrical mathematical model.
In the basic model, two DC motors are used to provide straight line and rotor motion for the TWSBR. The TWSBR consists of coupled wheels that allow it to move and manoeuvre around itself, a motion very beneficial in applications with confined space. The electrical circuit of such a DC motor is shown in Figure 2. Kirchhoff's voltage law of the DC motor is introduced in equation 1, where Vs is DC applied voltage, R and L are the equivalent resistance and inductance of the stator windings, is the back emf voltage, and is the armature current [20]. The motor electrical inductance, L, is assumed to be zero due to the small electrical time constant (L / R) when the motor is at rest. Equation 1 can thus be rewritten as equation 2.
The output of the DC motor consists of rotational speed (w) and torque (τ), which are proportional to the strength of the magnetic field and armature current.
The sum of all torques produced on the shaft is linearly related to the acceleration of the shaft by the inertial load of armature (JR).
where τf is friction torque. The state-space equations for the DC motor can therefore be written as [21] [̇̇] = [

Mechanical mathematical model
The mathematical description of the TWSBR was analysed using Newton's second law. The side view of model is shown in Figure 3. The balance of robot is affected by the radius of the wheel, the centre of gravity, and the robot mass [22]. Equations 8 and 9 introduce the Newton's second law for the right wheel and equations 10 and 11 apply to the left wheel. Where mw is mass of the wheel connected to the left and right wheels, mp is mass of the chassis, Hr, Hl, Pr, and Pl represent reaction forces between the different free bodies, fr and fl are disturbance forces applied to the centre of the wheel, R is the radius of the wheel, Jw is wheel inertia moment, Jp is chassis inertia moment, Cr and Cl are right and left wheel torques, g is gravity, and L is the distance between the centre of gravity of the chassis and the z-axis.
The sum of forces in the horizontal direction on the pendulum is presented in Equation 12.
The sum of forces in the vertical direction is shown in Equation 13.
( + ) The sum of moments around the centre of mass of the pendulum is thus

Hardware development
The performance of the TWSBR was determined by analysing the robot's responses while it was in moving mode. The efficiency of the TWSBR potentially relies on the effectiveness of the adopted control algorithms and the dynamic model. This section thus discusses the hardware development of the control system. Figure 4 depicts the block diagram structure of the TWSBR hardware components. The experiment setup was in two main groups, the data acquisition and control unit, represented by two 8- bit low cost microcontrollers (Arduino boards), a Bluetooth HC05, a Gyroscope sensor, a stepper motor and a motor driver; the second group was the Android GUI application on the smartphone. The Arduino is a small computer developed by the Interaction Design Institute of Ivrea in the early 2000s. It is low-cost computer with significant free software resources that are useful to researchers. It is basically an 8-bit microcontroller board based on the ATmega168, with 16kB of flash memory, 23 digital input and output ports, a pulse width modulator, a 10-bit analogue to digital converter, and extra hardware resources, making it highly suitable for the development of TWSBRs. The Arduino board is fully programmable using high-level interactive C language, allowing it to act as a "brain" for the required task [23].
The Bluetooth HC05 is a Serial Port Protocol (SPP) module that allows wireless transmission or reception of information with specific radio frequencies. The Bluetooth HC-05 can work in two modes: the order-response work mode and by automatic connection, and it can be used in Master-Slave or Loopback configurations in the automatic connection work mode. Bluetooth modules offer universal wireless connection for products such as MP3 players, TVs, and smartphones. Bluetooth has been developed for short-range control and monitoring applications to allow a maximum information exchange rate of 3Mbps, with fully qualified Bluetooth V2.0+EDR (Enhanced Data Rate), at a modulation frequency of 2.4 GHz and range of 10 meters [24].
Android is an operating system (OS) that is widely used in smartphone devices due to its permissive licensing that allows developers to design and develop applications freely. Android also provides various tools for creating Graphical User Interface Applications that can take advantage of the hardware capabilities available on each device. The Android SDK also provides the API libraries and developer IOP Publishing doi:10.1088/1757-899X/1067/1/012132 6 tools necessary to build, test, and debug apps for Android. A Graphical User Interface (GUI) is a login page that provides an interface whereby a human user can interact with the system, with different screens for different applications. Such a GUI can be used as remote control device to permit interfaces with complex appliances [25].

PID controller
The proportional-integral-derivative (PID) controller is now used ubiquitously in a wide range of engineering applications [10,20]. PID controllers are used for improving both transient and steady-state responses [26,27], and in terms of process control, PID controllers provide simple structure and strong robustness, and they are widely used to correct the set point of the demand in a series [18]. In the 21st century, the rapid development of micro-computer and micro electronic technology has had a dramatic influence on the further development of PID controllers [26]. A typical structure of a PID control system has three areas: Proportional gain ( ), Integral gain (ki), and Derivative gain ( ), as shown in Figure  5 [27,28]. Equation 16 shows the continuous-time PID controller related to the initial adjustment equation for the control signal and the control error, where ( ) is the output control signal, ( ) is the error signal, and , , and kd are the proportional, integral and derivative gains, respectively.
In order to balance a two-wheel robot, the error value is calculated as The set point of the robot must be 0, which means that the left angular velocity ( ) and right angular velocity ( ) of the wheels can be calculated as where ∆ is the data from the gyroscope.

Simulation software and results
This project aimed to design a real-time remotely controlled two-wheel self-balancing robot that may be maneuverer semi-autonomously by means of a customised Android application. From a communication perspective, the software system acts as a server on the mobile phone and the client is the controller. Android Apps were thus written and developed in MIT App Inventor that could be installed on a smartphone to control the TWSBR. Typical images of such a smart phone app window are shown in Figure 6. There are five buttons that cause the robot to turn right, turn left, move forward, move backward, and stop. The server sends the relevant signal through the Bluetooth low energy (BLE) protocol to be communicated with the client, which connects the transmitter and the receiver devices. When the server sends the signal to the client, it then waits for connection data from the client for as long as it takes. After this pairing of the HC-05 Bluetooth module with the server, the server should have control of the robot, however.

Figure 6. Smartphone app window
In order to evaluate the performance of the presented TWSBR, experimental tests were done to measure accuracy and effectiveness. When the power was turned on, the TWSBR was unstable, though the TWSBR reached dynamic balance within 2 s, as the PID controller was used to achieve the balance of the TWSBR with parameters kp=55, ki=380 and kd=2.2. The experimental setup showed the pitch angle to be limited within an acceptable boundary. Based on the speed and direction information from the server, the TWSBR began to move; the experimental setup thus demonstrated the ability of the proposed TWSBR to move forward and backward according to server commands. The yaw angle and response motion of the TWSBR is shown in Figure 7.

Conclusion
In this work, the creation of a semi-autonomous two-wheel self-balancing robot was achieved based on the design and implementation of hardware and software capable of wireless communication and instantaneous stabilisation. The direction of the TWSBR is controlled through a Bluetooth connection by an Android application. The self-balancing and desired command execution of the two-wheel robot was experimentally verified, and a significant improvement in response time achieved of less than 2 seconds. The tracking performance of the vertical pendulum angle was also satisfactory, being less than 5° during the robot's movement.  Figure 7. Responses of the two-wheel self-balancing robot.