Position and Attitude Control Based on Single Neuron PID With Gravity Compensation for Quad Rotor UAV

ABSTRACT Aimed at the deficiency of existing PID controller for quad rotor UAV, a single neuron PID controller with gravity compensation is presented. After using feed forward control to compensate gravity, the position loop adopts PID control to ensure control accuracy, while the attitude loop adopts single neuron control to increase adaptive ability. Then, by using Matlab/simulink simulation software, the position control of quad rotor UAV is carried out, and the simulation result shows, compared with the traditional double closed loop PID controller, the control algorithm based on the Single Neuron adaptive PID with gravity compensation can effectively improve the robustness and adaptability of the quad rotor UAV system.


INTRODUCTION
Compared with the traditional helicopter, the quad rotor UAV has many advantages.It has the characteristics of simpler structure, smaller volume and more stable flight, which makes it more practical in various environments (Shi et al. 2020).
In recent years, the quad rotor UAV has been widely used in military, remote sensing, surveying, mapping, and many other fields (Guan et al. 2021;Gu et al. 2021).Because the quad rotor UAV has the characteristics of strong coupling, nonlinearity and under actuation, the control method has been one of main research directions.At present, many control methods, such as PID control (Miranda-Colorado and Aguilar 2020; Rosales et al. 2018), sliding mode control (Mofid and Mobayen 2018;Oba et al. 2018;Zhang et al. 2021), intelligent control (Guan et al. 2021), backstepping control (Zhou et al. 2018), L1 Adaptive control (Souanef 2023), fault tolerant control (Di et al. 2023), and robust control (Weng et al. 2022;Yang 2021) have been applied to the control of quad rotor UAV.Though the traditional PID controller is easily used to implement the control of the quad rotor UAV, the fixed PID parameters cannot adapt to the changes of external conditions and control object parameters, which makes it difficult to achieve the desired control effect.However, single neuron PID method has been applied to some control systems and has achieved good control results (Feng 2022;Yanjun et al. 2018;Zhong et al. 2020).Single neuron has a strong self-learning ability, and its nonlinear mapping function can solve the nonlinear problems.Compared with the traditional PID control algorithm, the single neuron PID method needs to calculate the PID parameters in real time, but can obtain better performance.
Therefore, in order to achieve a better control effect, we study the design of variable parameter controller based on a single neuron, so that the three parameters of PID controller based on this algorithm can be adjusted online, and the adaptive control of quad rotor UAV is realized.In addition, in height control, gravity becomes a constant disturbance, which is prone to overshoot and even instability.Therefore, we use feed forward control to counteract the influence of gravity in height control.The simulation results show that the PID controller based on S-function RBF neural network has good stability and adaptability.

MODELING OF QUAD ROTOR UAV Flight principle of quad rotor UAV
The quad rotor UAV is a rigid body with six spatial degrees of freedom, including three translational motions of longitudinal, transverse and altitude, and three rotational motions of roll, pitch and yaw.The quad rotor UAV has only four inputs, which makes it an underactuated system.
The airframe structure of quad rotor UAV is usually cross-shaped or X-shaped.The difference between the two forms lies in the choice of nose direction.The X-shaped body structure is easy to operate, while the cross-shaped is easy to use and control.
In the paper we study the cross-shaped quad rotor UAV which is shown in Fig. 1 (Mian and Dao-bo Wang 2008).In Fig. 1, the four motors can be divided into two pairs.Motor 1 and Motor 3 are one pair, and Motor 2 and Motor 4 are the other pair.The motor pair (1, 3) is a clockwise positive propeller and the motor pair (2, 4) is a counterclockwise negative propeller.
The quad rotor UAV mainly includes the following motion forms: hover, vertical take-off and landing, roll, pitch, and yaw.When the speed of the four rotors changes by the same amount, the lift force will change.If the lift is equal to gravity, the UAV is in hovering state; if the lift is greater than gravity, the UAV will move upward; otherwise, the UAV will move downward.
When the speed of the motor pair (2, 4) remains unchanged, the pitch motion can be obtained by increasing (or decreasing) the speed of Motor 1 and decreasing (or increasing) the speed of Motor 3. When the speed of the motor pair (1, 3) remains unchanged, the roll motion can be obtained by increasing (or decreasing) the speed of Motor 2 and decreasing (or increasing) the speed of Motor 4. The yaw motion can be obtained by increasing (or decreasing) the speed of the motor pair (1, 3) and decreasing (or increasing) the speed of the motor pair (2, 4) (Gong et al. 2012).
Whether the motor speed increases or decreases depends on the direction of pitch, roll or yaw motion.The UAV can adjust the motor speed to control the required attitude for flight.

Dynamic model of the quad rotor UAV
In Fig. 1, l represents the distance of the motor from the pivot center.The center of gravity of the UAV is also the origin of the body fixed frame.The origin of the earth fixed frame is the take-off point of the UAV.The earth fixed frame and the body fixed frame are represented by E = {X, Y, Z} and B = {x, y, z}, respectively.
Three attitude angles of the quad rotor UAV are roll angleφ, pitch angle θ and yaw angle ψ, respectively.φ, θ and ψ represent Euler angles about x, y, z body axes, respectively.T n (n=1, 2, 3, 4) represents the thrust force produced by each propeller.W n (n=1, 2, 3, 4) represents the speed of the four rotors.
In practice, the flight situation of the quad rotor UAV is very complicated.In order to simplify the mathematical model of the quad rotor UAV, the following conditions are assumed.
• UAV is a rigid body.
• The mass of UAV remains unchanged under all flight status.
• The center of the UAV coincides with the origin of the body fixed frame.
The transformation relationship between the two frames can be obtained by first rotating the roll angle of the body fixed frame with respect to the OX axis, then rotating the pitch angle of the body fixed frame with respect to the OY axis, and finally rotating the yaw angle of the body fixed frame with respect to the OZ axis.The transformation matrix between two frames is (Eq.1): (1) where sφ, sθ, sψ, cφ, cθ and cψ are the simplified expression for sinφ, sinθ, sinψ, cosφ, cosθ and cosψ.
The control inputs to quad rotor includes vertical force u 1 , roll moment u 2 , pitch moment u 3 and yaw moment u 4 , which are defined as Eq.2: (2) By arranging Eq. 2, we can get Eq.3: (3) where K T and K D are constants dependent on air density and UAV parameters.
From Eq. 2, we can get Eq. 4 (4) In the body fixed frame, the lift force F B received by the four rotors can be expressed as Using the frame transformation matrix R E B , the lift force F E in the earth fixed frame can be obtained as (Eq.5): 1 1 1 (cos sin cos sin sin ) (cos sin sin sin cos ) Let J x , J y and J z be the moment of inertia for the x, y, and z axes of quad rotor UAV.Assuming that quad rotor UAV is completely symmetrical in structure, ignoring the air resistance and gyro effect, we can get the following conclusions when the quad rotor moves at a small angle (Eq.6).
Finally, the schematic diagram of the quad rotor UAV model is shown as Fig. 2. x u m y u m z mg u m Source: Elaborated by the authors.

The design of control algorithm
The control of the quad rotor UAV is achieved by adjusting the speed of the four rotors.Generally, the four rotors are controlled by double loops.One is the inner ring, which is used to control the attitude of the four rotors; one is the outer ring, which is used to control the position of the four rotors.Specific control methods will be introduced below.
Height Control based on Gravity compensation let [x c y c z c ] T the given position, and [x, y, z] T be the feedback position, then the deviation vector [e x e y e z ] is obtained as follows (Eq.7): (7) Height control adopts PD control (Eq.8): (8 where k pz and k dz are proportional and differential coefficients respectively.
The control quantity U z is used to determine the acceleration of the quad rotor UAV.When the quad rotor UAV hovers in the air, the gravity will be equal to the lift force.Therefore, we can use feed forward control to counteract the effect of gravity.
u z0 is used to counteract the gravitational acceleration of the quad rotor UAV.So we get Eq.9: (9) After the feed forward control is used to counteract the gravity, the gain k pz in the height control algorithm will be reduced, which is conducive to the system stability.

Position control in horizontal plane
We construct the following controller in the horizontal plane (Eq.10): (10) where k px , k iy and k dx are proportional, integral and differential coefficients of x-direction controller U x respectively, k py , k iy and k dy are proportional, integral and differential coefficients of y-direction controller U y respectively.
The control quantity U x and U y determines the accelerations in the x and y direction.
The Eq. 11 can be obtained utilizing Eqs. 5, 8 and 9. (11) In Eq. 11, φ c and θ c can be taken as the given values of roll angle and pitch angle in the attitude loop.The schematic diagram of position control loop is shown as Fig. 3.
Next, we will design the attitude loop controller.
Source: Elaborated by the authors.

Single Neuron adaptive PID attitude controller
As the basic unit of neural networks, the neuron has the self-learning ability and adaptability.Single neuron adaptive PID algorithm is easy to realize, and has better robustness.Besides, the algorithm does not need an accurate mathematical model of the controlled object (Wang et al. 2021).Therefore, the design of single neuron adaptive PID controller does not need system modeling.Considering these characteristics of single neuron control algorithm, we introduce the single neuron adaptive PID control algorithm into the control of three attitude angles in the attitude loop.
The roll, pitch and yaw angle control methods using single neuron adaptive PID controller are the same.Figure 4 is the model structure of single neuron adaptive PID controller for roll angle.
State Transformer Quad Rotor UAV Source: Elaborated by the authors.x φ3 are the inputs of the single neuron, which meet the Eq.12: (12) w φ1 , w φ2 and w φ3 are respectively the weight value of the input x φ1 , x φ2 and x φ3 .
K φ is the proportional coefficient of the neuron, and K φ > 0, then the output of the single neuron controller can be expressed at Eq. 13: (13) In the single neuron controller, the coefficient K φ reflects the adjusting amplitude.Generally, if the deviation is bigger, the adjusting amplitude is also bigger to meet the requirement of system rapidity; if the deviation is smaller, the adjusting amplitude is also smaller to meet the requirement of system stability of the system.The coefficient K φ is usually a function of the deviation e φ , and their relationship is as follows (Eq.14): (14 where α φ < 1, and μ φ is constant.Usually, if μ φ is bigger, the system rapidity is better, but the system overshoot becomes larger. If α φ is smaller, the system stability is better (Wang et al. 2021).
The single neuron PID control method implements the adapting control of system by adjusting the weight coefficient.We use Supervised Hebb learning rules as the learning method of weight value.In order to ensure the convergence and robustness of learning method, we normalize the Eq. 13, and get the following the expression (Eq.15-17): (15) where η φP , η φl and η φD proportional, integral and differential coefficients respectively for the roll angle.
Similar to the control of roll angle, we can use the single neuron control algorithm to obtain the control quantity u θ of pitch angle and the control quantity u ψ of yaw angle.So we get roll moment u 2 = u φ , pitch moment u 3 = u θ and yaw moment input u 4 = u ψ .
The schematic diagram of attitude control loop is shown as Fig. 5.
Source: Elaborated by the authors.ability and easily ensures real-time performance (Hu et al. 2015).Therefore, the quad rotor UAV can get better control effect under the single neuron adaptive PID controller with gravity compensation.

SIMULATION RESULTS
In order to prove the effectiveness of the proposed method, a quad rotor UAV is taken as the controlled object for simulation in Matlab/simulink environment.
In the simulation, it is assumed that the flight environment is calm, and there is no significant disturbance of atmospheric flow, ignoring the influence of air resistance.
The system parameters of a quad rotor UAV is summarized as follows: • Distance of the motor from the pivot center (l) is 0.3 m.
• Mass moments of the airframe inertia J x , J y and J z along the x, y and z axe is 0.0154 kg•m 2 , 0.0150 kg•m 2 and 0.0309 kg•m 2 respectively.
• Total mass of the airframe (m) is 0.6 kg.
Let us simulate the closed loop system with nonlinear control algorithm.The initial conditions used are φ = θ = ψ = 0, x = y = 0 and z=-1 m.The reference inputs to the controller are x c = 2m, y c = 2m, z c = 2m and ψ c = 2rad.
Using PID method, and single neuron adaptive PID with gravity compensation, the step responses are observed.Figures 6-9 show the response curve of the proposed control algorithm.
The single neuron adaptive PID with gravity compensation possesses high control accuracy, small overshoot and short adjusting time compared with the traditional PID methods.It can be seen that the single neuron adaptive PID realizes the automatic adjustment of control parameters, and the feed forward control realizes the gravity compensation, so the performance of the whole control system is improved.Therefore, the control method based on single neuron adaptive PID with gravity compensation is able to effectively meet the control requirements of the quad rotor UAV.Step response of yaw angle.

CONCLUSION
The paper is set out to study the position and attitude control of quad rotor UAV.The control algorithm of single neuron adaptive PID with gravity compensation is proposed.The research has also shown that the proposed method possesses more stable output, short adjustment time and strong robustness, and can meet the requirements of the quad rotor UAV.The major limitation of this study is that it does not consider the influence of some factors, such as air resistance, wind resistance, and gyroscopic effect, and the future research should carefully consider the effects.

Figure 2 .
Figure 2. Schematic diagram of the quad rotor UAV model.
k px e x + k ix ∫ e x dt + k dx e x + x c U y = k py e y + k iy ∫ e y dt + k dy e x + y c U zl = U z + u z0 = k pz e z + k dz e z + u z0

Figure 3 .
Figure 3. Schematic diagram of position control loop.

Figure 4 .
Figure 4. Structure of single neuron adaptive PID.In Fig. 4, φ c and φ are respectively the given and output of roll angle, and the deviation meets e φ (k) = φ c (k) -φ(k).The control quantity u φ (k) is generated through the single neuron associated with the search and self-learning (Hu et al. 2015).x φ1 ,x φ2 and

Figure 5 .
Figure 5. Schematic diagram of attitude control loop.
by the authors.

Figure 6 .
Figure 6.Step response of position in x direction.

Figure 7 .
Figure 7. Step response of position in y direction.reference position PID single neuron PID control with gravity compensation Time (s) Position in z direction (m)

Figure 8 .
Figure 8.Step response of position in z direction.