Building embedded quasi-time-optimal controller for two-wheeled self-balancing robot

. In this paper, two-wheeled self-balancing robot problem is introduced, and a quasi-time-optimal approach is applied to synthesize the control law. The result is compared with that of other methods. The process for designing and building the testting model, implementing the synthesized control law is also described.


Introduction
Two-wheeled self-balancing robot is a robot with two coaxial wheels. The idea of building such a robot, proposed firstly by Seway Inc., is based on two pillars, one being the way human-being keeping balance on two feet and the other being the movement of two-wheeled vehicle. Nowadays the robot has been developed to commercial product. Fig. 1 shows a typical two-wheeled self-balancing robot. Two-wheeled self-balancing robot has been extensively used as a means of communication thanks to its advantages, such as: small size, environmental protection, simplicity in controlling, flexibility in various topographies, simplicity in transport, installing and.
Qualitatively, the principle for keeping balance in two-wheeled robots is as follows. A robot in the equilibrium position is titled with an angle φ when subjected to a force. For the robot to regain its equilibrium, a force F is needed to apply to it so that its center of gravity is located in the middle of two wheels as shown in Fig. 2.

Mathematical model of the robot
The mathematical model of two-wheeled self-balancing robot is described in equations set (1) [1]: Where: x -displacement (m); ẋ-velocity (m/s); ẍacceleration (m/s 2 ); φ -angular displacement (rad); φ̇angular velocity(rad/s); φ̈ -angular acceleration(rad/s 2 ); U a -voltage (V); k m -rotation moment constant (Nm/A); k e -reactive power constant (Vs/rad); R -nominal resistance (Ω); l -distance between the weight center of the wheels and the weight center of the robot (m); ggravity acceleration (m/s 2 ); M p -the chassis volume (kg); r -wheel radius (m); I p -moment of inertia of the chassis (Nm); I ω -moment of inertia of the wheeles (Nm); M wthe wheel weight (kg). In addition: The problem of synthesizing control law for twowheeled self-balancing robot is to find the force F via the voltage U a that guarantees the robot to move from the start position (x(0), φ(0)) to the end position (x sp, 0 ) and stand still there.
Controlling a self-balancing robot is equivalent to the problem of controlling an inverted pendulum which is a typical system for simulation and implementation of controlling methods [2][3][4][5][6][7]. The optimal controls for the system were proposed in [2] and [3], in which the law using the signum function was used. This also means that the time optimal problem was not addressed. In this paper, we proposed a method for synthesizing quasitime optimal nonlinear control law to overcome the above-mentioned problem, and implement it in an embedded board.

Using the quasi-time optimization approach
The quasi-time optimization approach for synthesizing control law is developed by Neydorf R. A's group [21,22]. By using this approach, the problem of synthesizing control law for a wide spectrum of nonlinear objects can be solved. It is reported that the synthesized control law has several advantages, such as: quasi-optimal minimum-time, asymptotic stability and robustness.
To simplify model (1), we introduce the following variables: It can be seen that c 1 a = a 1 c, or a -a 1 c/c 1 = 0.
Substituting these values into equation set (1), we get: Changing state variables as follows: It is easy to verify that Jacobian matrix of transformation (3) is not degraded: 0 0 0 1 0 Equations by Y = (y 1 , y 2 , y 3 , y 4 ) T : Equations (4) is in a controllable Jordan form [22]. Virtual system (4), which has asymptotic stability and quasi -time optimum, is used to synthesize the control law u with z 1 = y 1 ; u is found to introduce the system (4) into the virtual system (5) [22]. The obtained control law is a differentiable function of state variables, of which the formula is very long and therefore not given here.
Where h 0 (z, x sp ) is quasi -time optimal function (h 0 (z, x sp ) ≈ sign(z -x sp )) [21].  Fig. 3 demonstrates the synthesized quasi-time optimal control. As compared to fuzzy control shown in Fig. 4, the synthesized quasi-time optimal control has several advantages. First, signal u is smooth. Second, there is no oscillation of control variable x. And finally, the speed of control is faster.

Designing and building embedded control system
To prove the feasibility of the simulation result, the testing model was build using Arduino microcontroller with a 16MHz crystal frequency to implement the control law as shown in Fig. 5. The most challenging issue in controlling a selfbalancing robot is to keep the angle stable to guarantee the balance of the robot. The testing model is designed to keep the angle stable. Where: M1 and M2 are the motor controlling the two wheels, L298P is the power block, and MPU 6050 is the sensing block.
The most difficult problem in implementing quasitime optimal control law in embedded system is that the control law is quite complex and cumbersome because it contains 4 th order derivative of the quasi -time optimal function. This results to long time for computation, making it difficult for a system to meet the real-time requirement. To simplify the calculation process, the intermediate functions, which are the high order derivative of sub-optimal function, were used in the embedded program. Equations (6) and (7) are the quasitime optimal function (5) and its 1 st order derivative. The high order derivatives are not shown here due to the fact that they are very cumbersome.
f1*f1)*((z-zs)*(z-zs)+f1*f1))); } The angular displacement for balancing the robot is shown in Fig. 7. In general, the system has stabilized well but is still oscillating due to the following reasons. First, the actual model was built manually with relatively high measurement error. The actual model slips as the system is stable at zero angles. Second, the epsilons in the law are approximate parameters, which are not optimized since it is very hard to estimate them accurately in the simulation. Third, the measurement of feed-back values is with relatively high error. Fourth, time parameter is discretized in the embedded system. Improving the quality of the control part is the goal of our future work.

Conclusions
In this paper, the problem designing and building twowheeled self-balancing robot has been addressed comprehensively. First, the problem of synthesizing control law was addressed theoretically. By using the quasi -time optimal approach, the problem of synthesizing control low was solved. Then the robot and embedded board were designed to implement the synthesized control law.