Semi-Adaptive Control Systems on Self-Balancing Robot using Artificial Neural Networks

— A self-balancing type of robot works on the principle of maintaining the balance of the load's position to remains in the center. As a consequence of this principle, the driver can go forward reverse the vehicle by leaning in a particular direction. One of the factors affecting the control model is the weight of the driver. A control system that has been designed will not be able to balance the system if the driver using the vehicle exceeds or less than the predetermined weight value. The main objective of the study is to develop a semi-adaptive control system by implementing an Artificial Neural Network (ANN) algorithm that can estimate the driver's weight and use this information to reset the gain used in the control system. The experimental results show that the Artificial Neural Network can be used to estimate the weight of the driver's body by using 50-ms-duration of tilt sensor data to categorize into three defined classes that have been set. The ANN algorithm provides a high accuracy given by the results of the confusion matrix and the precision calculations, which show 99%


Semi-Adaptive Control Systems on Self-Balancing Robot using Artificial Neural Networks
Sistem Kendali Semi-Adaptif pada Robot self-balancing menggunakan jaringan saraf Tiruan

I. INTRODUCTION
These days, many electric vehicles replace fuel vehicles sold in the market [1]. Personal electric vehicles are generally used to transport one driver without other passengers. These personal vehicles include self-balancing vehicles, electric scooters, electric bicycles, electric wheelchairs, and electric skateboards. A survey conducted by Shin shows that self-balancing vehicles are more commonly used than other personal vehicles in indoor, outdoor, or semioutdoor environments [2].
Segway Inc. first introduced Self-balancing personal vehicles at the end of 2001, named Segway personal transporter (PT). It went on public sale in 2002 and was promoted as a new method of transportation [3]. When it was introduced to the market, Segway PT was able to sell around 80,000 units which were used for the tour, personal, police, military, and emergency handling units [4]. A self-balancing vehicle has two wheels placed on one axis, and each of them is powered by a battery-powered electric motor. This vehicle can balance itself and keep the driver's position on it so as not to fall. This capability is known as self-balancing. Forward control is examined by tilting the driver's position forward to balance by following the driver's movements. Turning is done by tilting the steering lever to the right or left, which causes the vehicle to change the speed between the two motors, resulting in a turning motion.
The most important part of a self-balancing vehicle is a control system that keeps the vehicle's wheels to be able to follow the driver's body tilt. The first control system used in self-balancing vehicles is a linear control system including PID [5], [6], and LQR [7], [8]. PID control system stands for Proportional-Integral-Derivative, which provides a control loop feedback mechanism to control the process and variation of output. The Linear-Quadratic-Regulator (LQR) control is also a feedback controller in which the engineer is required to specify cost function parameters and eventually compare the result and the design. The linear control system was often chosen because it is simple. Based on the simulation results, the LQR control system can return the vehicle to its initial condition in less than 2 seconds when a disturbance is given [9]. Linear control system requires linearization of the nonlinear model, which means that the linear control system only works well at a limited working point.
Several nonlinear control systems have also been proposed to overcome the limitations of this linear system. A fuzzy control system, a nonlinear control system, can be used to maintain the balance of the vehicle [10], [11]. According to the simulation findings, the fuzzy control system can restore vehicle equilibrium in less than ten seconds [11]. Even the combined Fuzzy and PID simulated using Simulink showed that the error could be reduced to 60% [12]. Several variants of the sliding-mode control system are also used to maintain balance. Hierarchical sliding-mode is the best type of sliding mode which can return the system to a stable state in about 5 seconds [13].
The control system that has been previously proposed can control well, but the determination of the control parameters uses the assumption of fixed vehicle and driver weights. It is not following the actual conditions because the weight of the driver may vary so that a control system needs to be reset. The weight and location of the driver's center-of-mass will affect the gain value in the control system [14]. Drivers who are not too tall and light will make it easier for self-balancing vehicles to remain stable.
This study proposes a semi-adaptive mechanism in the vehicle control system that can change the control system parameters based on the driver's weight. The linear control system will be chosen as the primary control system because of the ability of the control system to respond quickly to changes. The driver's weight will be estimated using Artificial Neural Network (ANN) on changes in driver tilt angle. The weight information aimed to change the gain in the control system.

II. RESEARCH METHOD
This study proposes a semi-adaptive method to the control system as described in Figure 1.
The initial step that will be carried out is to construct a mathematical model of the selfbalancing vehicle. After the mathematical model is verified, the next step is to arrange a filter to reduce noise on the sensor [15]. The PID control system will be applied to the system after ensuring that the sensor reading noise can be adequately suppressed. The artificial neural network (ANN) will then be designed and arranged to determine the optimal configuration in estimating the user's weight. The entire system will be combined according to Figure 1 and tested to find out how effective the method is in solving problems in personal self-balancing vehicles.
The mathematical equation will design a control system that keeps the driver upright on the  wheel that rotates freely and is permanently attached to the ground. The wheels of selfbalancing vehicles must always touch the ground to ensure the vehicle can be controlled. Any movement that keeps one of the wheels off the ground will result in system instability and the driver falling. One technique can change the wheel axle mechanism [17] or change the driver's position [18].
The mathematical equation that applies to vehicles is derived by assuming that the wheels are permanently attached to the ground or no wheel slip. The friction between the wheels and the ground is neglected. The sketch of the vehicle, when viewed from the side, is shown in The IB's upper inertia can be compared to a homogeneous cylinder or rod rotating at one end. Therefore, rotational kinetic energy and translational kinetic energy make up the kinetic energy of the bottom or both wheels. The EKW's lower kinetic energy may be expressed as follows: The mass of the two wheels is denoted by mW with the radius of the wheel r. the wheel's inertia resembles the inertia of a cylinder rotating in the center. The angle of the wheel φ can be converted into a translational form using x and r. The potential energy produced by the top of the vehicle can be calculated using the following equation.
Personal vehicles have two types of forces that work, namely translational force and rotational force. Both forces come from the torque τ generated by the right-motorbike and the left-motorbike. The translational force is converted from torque using wheel radius r as follows.
The x position used as the q coordinate system will produce the following equation for motion.
The second coordinate used to find the equation of motion is the angle of inclination θ. The resulting motion equation is then shown as follows. The torque of a motor τ is determined by the motor voltage v so that the torque of the two motors can be assumed as follows.
The value of K is a constant between the voltage and the resulting torque. By substituting the torque value, the equation of motion of a personal self-balancing vehicle can be written as follows.
A. State Space The equation of motion produced in the previous chapter is nonlinear. This equation can be approximated by linearization at the equilibrium point θ = 0. The Taylor series will be used to find the linear equation of the sin and cos functions to produce the following equation.
By substituting linearization for the equations of vehicle motion, the linear equation at the equilibrium point can be written as follows.
The overall mathematical model of this vehicle can be represented in a matrix form as follows.
The inverse of the matrix E is as follows.  (17) The mathematical model of personal vehicles can be represented in state-space through matrix manipulation to produce the following matrix form.
The state-space form of the personal self-balancing vehicle system is represented in the following matrix equation.
Matrix X is a state. The U matrix is the input from the system. The Y output of a vehicle is the tilt angle, one of the system states. So, the state-space equation for the output is as follows.  accelerometer sensor and gyroscope will be used as input from the system to read the vehicle's tilt. The readings from the sensor will be forwarded to the microcontroller to be processed using the PID control system and the Artificial Neural Network adaptive system. The output from the PID control system will then be forwarded to the L298 DC motor driver. The motor driver will control the right and left motors of the vehicle at the same speed. The HC-06 Bluetooth module is also embedded in the vehicle prototype for data retrieval. Data retrieval is carried out wirelessly so as not to affect system performance in balancing the vehicle. The Bluetooth module will send tilt data to the computer continuously. The data received by the computer will then be used in analyzing system performance.
The prototype implementation of the personal self-balancing vehicle is shown in Figure 3 This study used additional weights as a simulation for riders who have different weights.
The load will be placed on the vehicle when the robot is running. There are three types of vehicle load scenarios that will be used in this study. The three types of vehicle loads were examined to analyze the effect of the load on the vehicle's response. The PID parameters applied in the system need to be tuned first to keep the vehicle in an upright position. The first step, taken before the tuning process, is to determine the vehicle's parameters that affect the transfer function as listed in the previous section. Parameter measurement is done by weighing each component and measuring the radius of the wheel and vehicle height, as shown in Figure 4. The complete measurement results are shown in Table 1.  The general working principle of the system is to use the PID parameter for "no-load" regardless of the type of load when it is on the first run. Over time, the accelerometer sensor will acquire the value of the robot's balance stability. The correct PID parameter for the suitable class will make the robot stable in its balanced pose. However, the mismatch of the PID parameter will cause the robot to tend to be less stable in balancing itself. Thus, it is necessary for the three classes to each have their respective PID parameters tuned and tested that these parameters are stable enough for each class.

Sensor signal acquisition and training data formulation
After determining the correct class and PID parameters for each class, the accelerometer sensor data (tilt) was collected from the robot to get how stable the robot is in its balance pose.
As already explained, the robot initially used the "no-load" PID parameter. Then, the robot was conditioned in no-load, battery load C; and battery load D. Furthermore, the robot was run for each condition. The sensor was acquired and then sent to the programming computer via Bluetooth for data logging for a certain period. The shape of the signal shows that the no-load condition, with the PID parameter at no-load, shows a signal that tends to be stable, indicating that the robot tends to be stable in balancing itself. Furthermore, it is necessary to crop the signal data so that the training data is balanced and focused during self-balancing conditions. In this case, each signal would be truncated for nearly 900 milliseconds, at which point the robot has started trying to balance itself. Figure 5 shows the results for cutting nearly 900 milliseconds in each condition.
In the cropping process, a total of 888 value reading data were generated for each class.
Furthermore, to be able to predict class, it is not enough just to input one value. Therefore, 50 data sequences would be used as classification input. The 50 data represent the reading of the sensor value for 50 ms. It is considered sufficient as a characteristic of each condition. Thus, 50 data framing/windowing would be carried out on a total of 888 data for each class. The results of the framing extraction are used as training data for each class. The illustration of the 50 data framing running on a total of 888 data is shown in Figure 6.

Training process and evaluation
The Scikit-learn tool [19] used the Python programming language through the Jupyter Notebook to train the ANN algorithm [20]. First, the data extracted from the sensor signal readings (2517 lines of data) was converted into a CSV file. Next, the process of preparing the dataset into training data and test data is carried out. In this case, 20% (504 data) of the data will be used as test data, the remaining 80% (2013 data) was used as training data. Furthermore, before performing machine learning algorithms, the standardization process is first carried out

III. RESULT AND DISCUSSION
The purpose of this experimental test is to determine the system response to load changes, whether it can adaptively change the PID parameters according to the installed load. Since the robot was run, the robot would be set to balance itself with the PID parameter at no-load for approximately 850 ms, which would then apply the classification from 50 ms data so that at 900 ms, the correct PID parameter is used according to the load. The result of plotting the signal for "load 2" is shown in Figure 9(a). From the image, after 900 ms, the robot had started to stabilize in balancing itself and did not oscillate like before. It can be seen from the oscillation value, which was in the range of 178o-182o. Besides, when the parameters are incorrect, the oscillations were in the range of 175o-184o with a massive swing. The result of plotting the signal for "load 3" is shown in Figure 9 also is interesting if the system can fully adaptively tune the control system based on the weight directly, which eliminates the need for classification of load's weight.

IV. CONCLUSION
This research aims to develop a method to semi-adaptively tune and control a self-balancing robot using an Artificial Neural Network to estimate the type of current load on the robot. The experiment result shows that the Artificial Neural Network can estimate the weight of the driver's body by using the value of the tilt sensor in the form of a sequence for a duration of 50 ms as the input parameter to classify the classes that had been set. However, we limit only three weight classes to be used as prototypes to show the semi-adaptive concept. According to the class, the classification results from the Artificial Neural Network can be used as a determining indicator to select the correct PID parameters. Of course, it is required that prior proper tuning for each class is done so that the control system responds as expected. According to the paper, the confusion matrix and precision of the ANN algorithm confirm high accuracy (99 percent), with 0 misclassifications of load 1 (no load), one misclassification of load 2 (battery C), and only five misclassifications of load 3 (battery D). The final test also shows that the system response is also good in switching the PID parameters indicated by the tilt signal on the self-balancing robot.
Currently, there are only three predefined classes of robot load. In the future, it is suggested to add more categories for robot load. If possible, tune the PID parameters directly from their weights, eliminating the need for class division. In addition, the ANN parameter is set by default, so related research can compare performance by changing ANN parameters. It is recommended to implement it in the actual self-balancing vehicle with a human driver so that the performance can be accurate in actual conditions.