The LQR Controller Design of Two-Wheeled Self-Balancing Robot Based on the Particle Swarm Optimization Algorithm

The dynamics model is established in view of the self-designed, two-wheeled, and self-balancing robot.This paper uses the particle swarm algorithm to optimize the parameter matrix of LQR controller based on the LQR control method to make the two-wheeled and self-balancing robot realize the stable control and reduce the overshoot amount and the oscillation frequency of the system at the same time. The simulation experiments prove that the LQR controller improves the system stability, obtains the good control effect, and has higher application value through using the particle swarm optimization algorithm.


Introduction
The two-wheeled and self-balancing robot belongs to a multivariable, nonlinear, high order, strong coupling, and unstable essential motion control system, and it is a typical device of testing various control theories and control methods; therefore, the research has great theoretical and practical significance.Because it has the advantages of simple structure, stable running, high energy utilization rate, and strong environmental adaption, it has the broad application prospects whether in the military field or in the civilian field.
Since 1980s, the scholars of various countries have conducted the system research on the two-wheeled selfbalancing robot.The two-wheeled and self-balancing robot control system based on the fuzzy control can overcome the instability and nonlinear nature of the system, but it relies on the expert's experience too much [1,2].The optimal LQR controller is designed on the basis of establishing the system structure model; the correctness and effectiveness of the LQR controller are verified, but it is difficult to determine the weighted matrix  and  [3][4][5].The genetic algorithm is successfully applied to the parameter optimization of the LQR controller of the inverted pendulum system, and it achieves the good control effect.However, the parameters are difficult to adjust, and it is easy to fall into the local optimization [6].
This paper concerns the self-designed and two-round self-balancing robot as the research object, which uses the Newtonian mechanics equation method and the linear method near the balance point to establish the linearized mathematical model of the system.In view of the mathematical model of the system, LQR controller is designed based on the particle swarm optimization and makes full use of the searching capability of the particle swarm algorithm to optimize the matrix  and matrix  of the LQR controller.It gains the global optimal solution of matrix  and  of the LQR controller so as to design the optimal state feedback control matrix  and overcome the disadvantages of relying on the experience and the trial and error in the selection of matrix  and  of the general LQR control design, making up for the inadequacy of big workload.This method has better control effect by simulation tests and comparison.

The Dynamics Model of the Two-Wheeled Self-Balancing Robot
The two-wheeled and self-balancing robot structure is mainly composed of the body and the two wheels, and the robot is the coaxial two wheels, driven by the independent motor; the parameters of quality, moment of inertia, and radius of the two wheels are regarded as the same, so the body center of gravity is inverted above the axletree and it keeps balance through sports.The two-wheeled and self-balancing robot can be regarded as the vehicle-mounted inverted pendulum, so the dynamic system analysis process is more complex.This paper separates the wheel from the pendulum analysis first in the process of modeling, and then it deduces the dynamics state equation of the two-wheeled self-balancing robot through the simultaneous two parts [7,8].
The two wheels are regarded as the research object, Figure 1 is a diagram revolver force analysis.According to the revolver force equation can be obtained in the following according to the Newton's law [9] and the rotational torque formula [10]: The right wheel force equation is as follows: After finishing, it can obtain Among them,   is the weight of the wheel;   is the moment of inertia of the wheel;  is the radius of the wheel; Ẍ is the wheel acceleration of  axis;   and   are the right and left wheel torque;   and   are the  axis forces of the left and right wheels with the car body;   and   are the interatomic forces of the right and left wheels with the ground; and   is the angle of wheel around the  axis direction.The car body of the two-wheeled and self-balancing robot is modelled as an inverted pendulum; the car body force analysis is shown in Figure 2. Using Newton's second law, the horizontal force is as follows: Among them,   is the displacement of the car body centre of gravity relative to the ground, Using Newton's second law, the force of the vertical direction of the car body is as follows: The sum of the torques of the car body mass center is as follows: On the small angle scope,  2  ≈ 0, sin   ≈   , cos   ≈ 1, the linearized equations are gotten after the linearization process: Among them,   is the angle of the car body deviating from the  axis direction;   is the moment of inertia of the car body;   is the weight of the car body; and  is the height of which the car body is apart from the shaft.The output torque of the wheel is   =   =   (/) = (  /)  − (−    /) θ  ; the state equation of the two-wheeled selfbalancing robot is obtained: The output equation is as follows: ] . (10)

The Design of the Self-Balancing Robot LQR Controller.
The LQR method is the mature controller design method in the development of modern control theory [11]; optimal control is to seek the control amount  * () to make the system reach the steady state and guarantee the performance index  to take the minimum value: Among them,  * = − −1    = −, and  is the solution of the algebraic equation +  +− −1    = 0 of the matrix Riccati [12].In (13), the matrix  and matrix  are mutually restricted, and the size of the  value is proportional to the anti-interference ability of the system; increasing the  value, the anti-interference ability of the system is enhanced, and the adjustment time of the system is shortened.However, at the same time, the oscillation of the system is strengthened, and the consumption of energy increases.The increase of  value makes the energy consumed by the system less, but the adjustment time increases.Therefore, the design key is to find the right weight matrix  and matrix .As long as we make sure of the matrix  and matrix , the state feedback matrix  is the only confirmation.However, the selection of the  matrix and  matrix entirely depends on the experience and trial and error method in the process of LQR controller design, so the subjectivity is larger, resulting in the imperfection of the controller design and affecting the control effect.

The Parameter Optimization Principle of the LQR Controller Based on the Particle Swarm Optimization Algorithm.
As a new optimization algorithm has been developed in recent years, the particle swarm optimization algorithm is abbreviated as the PSO.The particle swarm optimization algorithm is a kind of evolutionary algorithms, and it starts from the random solutions and searches for the optimal solution through the iterative algorithm [13].
Assuming  particles are composed of a group in  dimensional space, among them, the position and velocity of  particle in the space are   = ( 1 ,  2 , . . .,   ), V  = (V 1 , V 2 , V 3 , . . ., V  ),  = 1, 2, . . ., , the best position that the  particle experiences is denoted by  bset (), and the best position that all the particles in the group experience is denoted by  bset ().The whole particle swarm updates the velocity and position through tracking the individual extreme value and the optimal value [14].The particle optimization process is expressed in Among them,  is the inertia weight;  1 is the weight coefficient of the optimal value that the particle tracks its history;  2 is weight coefficients that particle track the optimal value; and  and  are the random numbers changing in [0, 1].   is the individual optimal solution of the particle after the  iterations;    is the global optimal solution of the group in the  iterations.To make the algorithm a more accurate search scope, the movement speed of the particle is limited in [−V max , V max ]; if V max is too large, the particle will fly over the optimal solution; if it is too small, it is easy to fall into the local optimum.Assuming that the particle position is defined as the interval [−V max , V max ], the two-wheeled selfbalancing robot state variables [, ẋ ,   , θ  ]  are regarded as the particles, and the particle's position and the initial value of the speed are produced at random in a certain range.The fitness function is an important link in using the particle swarm optimization algorithm, and it is the standard of the whole particle swarm algorithm iterative evolution.Because what we have designed is the quadratic optimal control regulator, we adopt the linear quadratic performance index formula (10) as the fitness function.The  is a symmetric positive semidefinite matrix of 6 * 6;  is a constant positive definite matrix.In order to simplify the problem and make the weighted matrix a clear physical meaning, we choose the weighted matrix  as the diagonal matrix, so that the performance index can be represented as Among them,  1 ,  2 ,  3 , and  4 are the weights of the position, speed, angle, and angular velocity of the twowheeled self-balancing robot, respectively. is the square weight of the control amount  in the objective function.

The Parameter Optimization Steps of the LQR Controller
Based on the Practical Swarm Optimization Algorithm Step 1. Initialize the particle swarm.Set the speed coefficients  1 ,  2 , the maximum evolution algebra gen, the size of the group pop, and the location of the initial search point and its speed, and each particle has the value of the current position.
Step 2. Calculate the fitness value   [] of each particle.
Step Step 5. Update the particle's speed V  and position   according to formula (12).
Step 6.If it meets the end condition (the error is good enough or it reaches the maximum cycle times), it will exit, or it returns to Step 2.

The Simulation Experiment of the LQR Controller Based on the Particle Swarm Algorithm
The parameter symbols, description, and the actual value of the two-wheeled self-balancing robot are shown in Table 1.
The actual parameters of this system are substituted into the state equation; the actual state equation is obtained as follows: The initial state of self-balancing robot system is as follows: to make experiment, at the same time, selecting the inertia weight formula [15]: Among them,  max = 1,  min = 0.3, and gen = 30; it indicates the iterative number of the algorithm evolution, and  is the current evolution algebra.
For an initial population of 40 * 8 matrix, the four dimensions in the front represent particle updated location and the four dimensions in the latter represent particle updated speed.The particle swarm updated position curve is shown in Figure 3.The particle motion curve shown in Figure 3 is not lost regularity, so there is only one particle position in critical condition.The PSO updated rate curve is shown in Figure 4. Figure 4 shows the particle movement speed can be controlled, not beyond the intended scope.Selecting the inertia weight formula is appropriate.
PSO algorithm in this case has a total of 50 times iterative and adaptive values.The number of iterations with the curve is shown in Figure 5.
Seen from Figure 5,  and  parameters after 21 iterations to achieve the optimization.
The global optimal solution can be gotten through the particle swarm algorithm programming: The dynamic response curves of the two kinds of algorithms of the LQR controller and the LQR controller based on the particle swarm algorithm are shown, respectively, in Figure 6.
The simulation curves of Figure 6 show that when the initial conditions of self-balancing robot are zero, the LQR

The initial position
The initial position The initial position The initial position   control and LQR control after the particle swarm optimization algorithm can make the system stable.However, the latter algorithm has the advantages of stable short time, less overshoot with fewer shocks.In order to verify the LQR algorithm based on PSO optimization is better than that LQR algorithm in the literature [4] and literature [7].LQR algorithm comparison and each algorithm control indicators are shown in Table 2.According to the above results, three kinds of algorithms can all achieve the stability of the system.The proposed algorithm on the overshoot and oscillation frequency is out of the more obvious advantages.That is because the algorithm can find the optimal solution of the LQR matrix  and matrix .

Conclusion
Using the particle swarm algorithm to optimize the selection of weighted matrix  and matrix  can overcome the blindness of selecting matrix  and matrix  in the traditional LQR optimal control.This paper uses the characteristics that the particle swarm optimization algorithm can achieve an intelligent search, gradual optimization, and rapid convergence.Therefore, it is not easy to fall into local optimum, but easy to be implemented on the basis of the linear model of the two-wheeled and self-balancing robot to obtain the global optimal solution of the , , achieving the optimal LQR controller design through the MATLAB simulation experiments.It can be found that the design response speed of the LQR optimal controller is faster with less overshoot amount, and it can keep the steady-state error zero, so the control effect is better.

Figure 2 :
Figure 2: The analysis of car body force.

Figure 5 :
Figure 5:  and  iterative optimization Figure based on PSO algorithm.

Figure 6 :
Figure 6: Based on self-balancing robot angle PSO optimized response.

Table 1 :
The parameter of the robot.
4tep4.Compare the fitness value   [] with the global extremum  best of each particle; if   [] >  best (), use   [] to replace  best .
3. Compare the fitness value   [] with the individual extremum  best () of each particle; if   [] >  best (), use   [] to replace  best ().

Table 2 :
The effective comparison table between other methods and proposed methods.