Modeling and PID control of quadrotor UAV based on machine learning

: The aim of this article was to discuss the modeling and control method of quadrotor unmanned aerial vehicle ( UAV ) . In the process of modeling, mechanism modeling and experimental testing are combined, especially the motor and propeller are modeled in detail. Through the understanding of the body structure and ﬂ ight principle of the quadrotor UAV, the Newton – Euler method is used to analyze the dynamics of the quadrotor UAV, and the mathematical model of the UAV is established under the small angle rotation. Process identi ﬁ er ( PID ) is used to control it. First, the attitude angle of the model is con - trolled by PID, and based on this, the speed in each direction is controlled by PID. Then, the PID control of the four rotor aircraft with the center of gravity o ﬀ set is simulated by MATLAB. The results show that the pitch angle and roll angle can be controlled by 5 degrees together without center of gravity deviation, and the PID can e ﬀ ectively control the control quantity and achieve the desired e ﬀ ect in a short time. Classical BP algorithm, classical GA - BP algorithm, and improved GA - BP algorithm were trained, respectively, with a total of 150 sets of training data, training function uses Levenberg - Marquardt ( trainlm ) , and performance function uses mean squared error ( MSE ) . In the background of the same noise, the improved GA - BP algorithm has the highest detection rate, classical GA - BP algorithm is the second, and classical BP algo - rithm is the worst. The simulation results show that the PID control law can e ﬀ ectively control the attitude angle and speed of the rotor UAV in the case of center of gravity deviation.


Introduction
In recent years, with the continuous development of science and technology and the continuous innovation of industrial technology in a country, more and more research institutions have invested in the research of quadrotor unmanned aerial vehicle (UAV).Compared with the traditional UAV, the four wing UAV is simpler and more flexible in structure because it does not need tail rotor.The utility model has the advantages of low cost, easy production, convenient disassembly, maintenance and transportation.It also has strong controllability, and can perform vertical take-off and landing, fixed-point hover, low-speed flight, rotation, roll and handstand operations in a narrow space.Quadrotor UAV (QUAV) is an aircraft with four rotors, which are distributed in x shape.In this study, the x-type distribution of the quadrotor is used, in which the QUAV can only change the rotor speed to achieve various movements.QUAV is a multi-rotor UAV which provides lift by rotating four rotors.Because of its vertical takeoff and landing, simple mechanical structure, flexible control, and other characteristics, it is widely used in different fields.QUAV is a highly complex system.The key to realize the control of QUAV is to design a controller with superior performance.
Research on quadrotor unmanned helicopter is very active.For example, Lakehead University in Canada has demonstrated that stable flight can be achieved using a quadrotor design.Accurate modeling was carried out at the University of Wollongong in Australia.At present, research on quadrotor unmanned helicopter mainly focuses on the following three aspects: autonomous flight based on inertial navigation, autonomous flight based on vision, and autonomous aircraft system [1].China's research on quadrotor is mainly carried out by Northwestern polytechnical university, National university of defense technology, Southern university of aeronautics and astronautics, Air missile research institute, Jilin university, University of Science and technology Beijing, etc. Ma et al. proposed that most research methods are theoretical analysis and computer simulation, and have proposed many control algorithms [2].In view of the uncertainty and nonlinearity of the UAV model, the National Defense University of science and Technology (ADRC) proposed a DI/QFT (Quantitative Feedback Theory) dynamic inverse controller, which can realize the attitude stability control of a small four rotor helicopter, but cannot control it well when the speed is high [3].
Islam et al. proposed that the quadrotor can be controlled stably to achieve the desired effect, especially for the larger flight speed of the aircraft [4].

Literature review
Aiming at the problem that agricultural four rotor UAV can be easily disturbed during ultra-low-altitude phenotypic remote sensing and precise hovering spraying, SW et al. proposed an adaptive composite antiinterference attitude controller to suppress the interference of ground effect and propeller failure.The stability of the composite anti-interference controller is analyzed.The wind disturbance experiment under side downflow and horizontal flow, the failure experiment under single propeller failure and double propeller failure, and the composite disturbance experiment under the simultaneous action of wind disturbance, propeller failure, and payload disturbance were carried out.The experimental results show that the anti-interference performance of adaptive composite dynamic range compression (ACDRC) is improved by 82.5% under wind interference; under the disturbance of propeller failure, the anti-interference performance of ACDRC is improved by 60%; and under the combined interference, the anti-interference performance of ACDRC is improved by 50% [5].
Random external interference/parameter uncertainty and other factors can worsen the tracking control performance of the QUAV.To achieve fast and high-precision performance of QUAV, an adaptive fractionalorder non-singular fast terminal sliding mode controllers (AFONFTSMC) is proposed by Labbadi and Cherkaoui.NFTSM surfaces with fractional derivatives and integrals are designed for pose and position measurements.The proposed nonlinear sliding surface ultimately and continuously allows the pose and position tracking errors to converge to zero in finite time.Furthermore, by designing adaptive laws based only on velocity and position variables for AFONFTSMCs, an upper bound on the uncertainty/interference affecting QUAV dynamics can be rejected.To demonstrate the finite-time convergence of the AFONFTSMC scheme and the zero pose/position tracking error, a stability analysis was performed.Simulation results in different cases show that AFONFTSMC is effective in anti-interference and path tracking performance compared to the recently proposed FO controller, adaptive non-singular fast terminal sliding mode control (SMC), and other nonlinear controllers [6].
For trajectory tracking control under white noise interference, Zhao et al. proposed a new self-disturbance control (ADRC) algorithm-based self-disturbance switching control (ADRSC) algorithm.The dynamics of the quadrotor vehicle is built with three sub-equations and the control algorithm is designed.The exact robust differentiator replaces the tracking differentiator in the traditional self-disturbance control algorithm and improves the accuracy and robustness of the differential signal.The ADRSC algorithm is used to control the quadrotor aircraft to improve its anti-white noise interference ability and control accuracy.Simulation results show that the proposed algorithm resists white noise interference without exceeding 0.1 dB intensity [7].
The stability and trajectory tracking control of the autonomous quadrotor helicopter system under wind interference were investigated by Bellahcene et al.The adaptive tracking controller uses a radial basis function neural network (RBF NN) to approximate an unknown nonlinear function in the system.To handle the modeling error and external interference, two controllers are proposed: H adaptive neural controller (H-ANC) and H-based adaptive neural sliding mode controller (H-ANSMC).This design method combines the robustness of SMC with the uncertainty of H treatment parameters and the ability of bounded perturbations.Simulation results show that H-ANSMC can eliminate shake phenomenon and suppress perturbation mismatch with better performance than H-ANC.Comparative simulation studies of the proposed controller are performed, and the results are discussed [8].
For the complex kinetic modeling and parameter identification of four-rotor formation cooperative trajectory tracking control, a data-driven model-free adaptive control method based on robust integral of signum of error (RISE) and improved sliding mode control (ISMC) was proposed by Hao et al.The leader-follower strategy was used for trajectory tracking control as implemented by the leader.A novel data-driven controller for asymptotic tracking is designed using RISE method.It is divided into two parts: the inner ring for posture control and the outer ring for position control.Both use the RISE method to eliminate interference in the circuit, and this method only uses the input and output data of the UAV system, and does not rely on any kinetic and kinematic models of the UAV.By improving the SMC by introducing the adaptive update law and the saturation function, the shake vibration problem of the general sliding mode control algorithm controller design depending on the UAV mathematical model is eliminated.Then, the stability of the system is demonstrated by the Lyapunov's method, and the algorithm effectiveness and scheme feasibility are verified by numerical simulations.The experimental results show that the designed data-driven model-free adaptive four-rotor formation control method is effective for realizing the coordinated tracking control of the four-rotor formation.Meanwhile, the design of the controller, with high control accuracy, stability, and robustness, does not depend on the UAV kinematics and kinetic model [9].
Shao et al. used a discrete time disturbance observer (DTDO) to study a four-rotor UAV with external perturbator and input saturation.First, the embedded trace buffer mechanism of the neural network and the S-shaped function for solving the input saturation are given; then the DTDO is designed to ensure the boundedness of virtual control signal.The combination of discrete-time tracking differentiators analyzes the stability of the closed-loop system.Experimental results of the four-rotor UAV system are finally presented to verify the feasibility of the proposed control scheme [10].
In this study, through the understanding of the structure and flight principle of the QUAV, the Newton-Euler law is used for its dynamic force analysis, the establishment of its small angle of flight under the mathematical model, and the process identifier (PID) algorithm is used for designing PID control.In this study, a different control method is designed for the QUAV, namely, the quaternion control law design of the quadrotor.The simulation results show that this control method is an effective method.
3 Research technique

Movement method of QUAV
(1) Vertical movement: Hovering and vertical movement are the most basic movement modes of QUAV.
When the QUAV blades rotate, they provide lift to the body, but at the same time, they are subjected to the opposite torque of the air, causing the UAV to spin.But the QUAV is a symmetrical structure, and the two motors on opposite sides turn in the same direction, and the other two motors on opposite sides turn in opposite directions [11,12].When the QUAV increases the speed of the four motors at the same time at the same rate, the lift force of four rotors increase with the same amount, if the total lift force is greater than the gravity of the body, and the UAV will rise vertically.On the contrary, when it reduces the speed of four motors at the same time at the same rate, the total lift force generated is less than the gravity of the body, and it will drop vertically.If the total lift force generated by the UAV is equal to the gravity received when there is no external interference, then the QUAV is hovering horizontally [13,14].(2) Yaw motion: The QUAV uses two forward oars and two counter oars to offset the torque generated by the rotor in the rotation process, so that the UAV can maintain a smooth flight.The direction of rotation of the diagonal motors is different depending on the adjacent rotor propeller.The torque generated by the rotor is related to the speed of the rotor itself.When the speeds of the four motors are the same, the torques of the four rotors are the same.The moments cancel each other and the QUAV does not rotate.
When the speed of the four motors is not exactly the same, the unbalanced torque will cause the rotation of the QUAV.When the speed of the motor 2 and 4, the speed of the motor 1 and 3 falls, rotor and rotor 2 and 4 of the fuselage rotor torque is greater than 1 and 3 reactive torque of the fuselage, rotor fuselage is in surplus torque under the action of around the z axis rotation, to achieve the yaw movement of the aircraft, steering and steering motor 2 4 instead [15,16].3.2 Power system modeling of QUAV

Motor dynamics model
Substituting Q and I from the above equations, we get where J TM is the rotational inertia of the motor, Q L is the load torque, Q is the motor torque, and V is the voltage at both ends of the motor.I is the current through the motor; ω is the angular speed of the motor; K q , R a , and K e are specific constants of the motor, where K q is associated with current and torque, R a is the total impedance of the motor rotor, and K e is associated with the speed and potential of the motor.

Propeller model
In this study, only the lift force (T) and torque (Q) of the propeller along the rotating axis are considered, and the drag force and lateral torque are ignored.These forces or torques are proportional to the square (Ω 2 ) of the rotor speed.
where C T and C Q are the resistance coefficient and torque coefficient of the rotor, p is air density, R is blade radius, and oar disc area = A πR 2 .
3.3 Design of PID control law for QUAV

PID controller design
Through the modeling of QUAV, the PID controller of the design is set in the flight process, the expected yaw attitude ϕ d angle is known, the expected position information x d y d z d is obtained through the receiver, and the UAV body position information X, Y, and Z are calculated through sensor feedback and flyback control.After comparing with the expected position coordinate information, the position controller calculates the control amount (flight lift of QUAV and expected pitch attitude angle θ d with the horizontal roll pose angle ϕ d .The actual attitude angle of QUAV is calculated through the data fed back by IMU and other sensors, and compared with the expected attitude angle, and then the control quantity is obtained through the attitude controller u 2 u 3 u 4 , and the calculated control quantity is finally transmitted to four motors through pulse width modulation to change the attitude and position of UAV.PID is the general name of various combinations of algorithms in P algorithm, I algorithm, and D algorithm.You can choose PD, PI, a separate P algorithm, etc. P (proportional control) reduces system error on the premise of reducing system stability.I (integral) and D (differential) must be used in conjunction with P (proportional) control, where I (integral) reflects the cumulative deviation of the system, allowing the system to eliminate steady-state errors.D (differential) reflects the rate of change of system deviation signal, which is predictive, so as to carry out advance control [18,19].Negative feedback PID controller is generally used to control QUAV.Stability (P and I reduce system stability and D improves system stability): In equilibrium state, after a certain disturbance, the controlled quantity of the system can reach a certain stable state after a period of time; Accuracy (P and I improve steady-state accuracy.D has no effect): The steady-state error when the system is in steady state; Rapidity (P and D increase response speed, while I decreases response speed): Dynamic response requirements of the system, generally measured by the length of transition time.

PID control structure of QUAV
The main purpose of PID control structure is PID-based quadrotor control problem research, and its ultimate goal is to verify that PID can effectively control the attitude angle and speed of quadrotor in the case of no center of gravity offset and center of gravity offset.Therefore, first of all, the quadrotor aircraft is modeled, and then the controller is designed, and finally the simulation is verified, Figure 1.

PID control parameters of QUAV
PID controller parameters: The P coefficient of the attitude loop is 15.The I coefficient is 0.2, and the D coefficient is 9.The P coefficient of the position loop is 12, the I coefficient is 0.1, and the D coefficient is 5.In order to obtain the parameters of the controller, the dynamic parameters of the UAV need to be obtained.It mainly includes the height of the body, the weight of the body, the length of the rotating arm, the moment of inertia around the three axes, and the lift coefficient and torque coefficient of the propeller.The body weight and the arm span can be measured directly by the device, and the lift coefficient and torque coefficient of the propeller can be obtained by the formula.The empirical formula for calculating the lift coefficient and torque coefficient of UAV is K t = c t pAr 2 ; Kd = c d pAr 2 .In the two formulations, c t , c d , p is the air density.A is the area swept by one rotation of the propeller, and r is the length of the propeller.Assuming that the QUAV is completely symmetric and the mass distribution of the QUAV is uniform, then the moment of inertia of the QUAV is: Rotation around the X (or Y) axis.It is assumed that the motor of the QUAV is a standard cylinder, the combination of each hardware of the UAV body's center of gravity including the load is regarded as a standard cylinder, and the four cantilevers of the body are all regarded as cuboids of equal quality.According to the definition of moment of inertia in classical mechanics, if you have a standard cylinder going around it and if the mandrel rotates, its mass is m, its radius is R, and its height is h, then its moment of inertia is zero, J X = J Y = m(3r 2 + h 2 )/12.The moment of inertia about an axis on its cross section is: J Z = mr 2 /2.If a thin rod of uniform mass (mass m and length l) rotates about its center, then the moment of inertia of the thin rod is: = / J ml 12 2 .According to the parallel axis law of moment of inertia, the moment of inertia of a rigid body is equal to the rotation of two axes passing through the center of mass and parallel to the axis at a distance of D plus the square of the mass of the rigid body and the distance between the two axes, i.e., J = J C + md 2 .The UAV dynamic parameters used in the experiment are shown in Table 1.

Result analysis 4.1 Machine learning model
Considering the fault of accelerometer sensor, three machine learning detection models are designed using Matlab: the first is classical BP neural network detection model, the second is classical GA-BP neural  network detection model, and the third is improved GA-BP neural network detection model.To compare the advantages of the three models, in this study, classical BP, classical GA-BP, and improved GA-BP algorithms were trained, respectively.There are 150 sets of training data in total.The simulation results are listed in Table 2, and the convergence curves of the three algorithms are shown in Figures 2-4.
The performance of the three machine learning algorithms is evaluated, and the detection rates of the three methods are shown in Figures 5-7.In the same GA-noise context, the modified GA-BP algorithm has the highest detection rate, followed by the classical GA-BP algorithm, and the classical BP algorithm is the worst.Therefore, machine learning models using an improved GA-BP algorithm can quickly and accurately detect various errors of the sensors.

Analysis of PID parameter adjustment law
The analysis of the QUAV model shows that the position and attitude controls of the UAV have compatibility, but the attitude and altitude controls of the UAV are completely independent.Therefore, three attitude angle channel controllers of QUAV can be designed, respectively, to realize the control of UAV.The pitch angle and roll angle channels have the same transfer function, so their controller structure is also the same.In order to ensure the expected trajectory tracking performance of QUAV in the presence of external disturbances and model uncertainties, Xu et al. adopted the cascaded Active Disturbance Rejection control (ADRC) method to control the attitude subsystem.A new position subsystem backstepping sliding mode control scheme is proposed.The analysis shows that the tracking error can converge to any small residual set.The feasibility of this method in practical application is verified [20].The single-stage PID control system of pitch angle, roll angle, and yaw angle channels of the UAV can be constructed based on the transfer function of the QUAV.The steady-state error of the system can be expressed by the gain speed of the P control unit.The faster it is, the more likely it is to cause system oscillation and reduce its stability [21,22].The slower it is, the less likely it is to oscillate, but it will reduce the adjustment speed.
When the system deviation is large, in order to reduce the deviation as soon as possible, choose the larger value, at the same time in order to avoid the system overshoot, when the system deviation is reduced, appropriately reduce the value, at the same time in order to eliminate the system shock caused by the excessive value, appropriately increase the deviation rate [23,24].When the deviation is the same as the rate of change of the deviation, the positive value is taken to reduce the deviation as soon as possible.When the deviation is reduced, the value is negative in order to avoid super oscillation.On the contrary, the larger the rate of change of deviation is, the smaller the value of deviation is, and the larger the value of deviation rate is, and so on.When the deviation is relatively large, p control is carried out; when the deviation is small, increase the deviation and value, and add p control unit.

PID parameter setting
PID method is widely used in the field of control.At present, there are many parameter setting methods proposed, which are mainly divided into theoretical calculation setting and engineering setting.For QUAV with input saturation, unmodeled nonlinear dynamics, and external interference, Xu et al. proposed a new adaptive robust control strategy.A new anti-saturation control method based on neural network finite time inversion is proposed by introducing neural network finite time inversion and designing a new virtual control signal and a modified error compensation mechanism.The effectiveness and robustness of the controller are verified by numerical simulation [25].Theoretical calculation setting is mainly based on the mathematical model of the system to determine PID controller parameters through control theory derivation, such as time-frequency analysis method and root trajectory method [26][27][28].However, the parameters obtained by using these methods cannot be used directly, and it is necessary to use experience in practical engineering applications to get the appropriate parameter values [29,30].The engineering setting method is more convenient and practical for on-site setting in engineering application.

Control results without center of gravity deviation
When pitch angle and roll are controlled together without center of gravity deviation, the results show that PID can effectively control the control quantity and achieve the desired effect in a short time.On the basis of attitude angle control, the speed control is further added, and the speed control is just a simple proportional control.The experimental results are good [31,32], as shown in Figure 8.

Control results under gravity shift condition
In order to test the PID control effect, the center of gravity of the quadrotor is shifted in this study, and the control results show that the rapidity of the control quantity decreases, but the control is still smooth and effective [33,34], as shown in Figure 9.

Conclusion
PID controller can effectively control the attitude angle and speed of the QUAV, and when the center of gravity of the quadrotor is offset, although the rapidity of control decreases, the control effect still meets the requirements.Simulation results show that this control method is effective.Especially, for the larger flying

( 3 ) 4 )
Pitching motion: When the speed of the motor 1 decreases (increases), the speed of the motor 3 increases (decreases), and the speeds of the motors 2 and 4 remain unchanged.As the lift of rotor 3 increases (decreases) and the lift of rotor 1 decreases (increases), the resulting unbalanced torque tilts the fuselage, producing a forward (backward) component, and forward flight.(Roll motion: Roll motion and pitch motion have the same principle.When the speed of motor 2 decreases (increases), the speed of motor 4 increases (decreases), keeping the speed of motors 1 and 3 unchanged.As the lift of rotor 4 increases (decreases), that of rotor 2 decreases (increases), the resulting unbalanced torque tilts the fuselage, resulting in a lateral component of the force and lateral flight.Mk et al. proposed a new attitude control scheme for quadrotor aircraft in the case of uncertainty and interference.The finite time convergence and stability analysis of closed-loop system are derived by using Lyapunov function technique.Experimental results show that the proposed method has good performance in precision, robustness, finite time convergence and chattering elimination, and the control work is small [17].The four flight motion modes of the QUAV can fly superimposed on each other, thus completing the assigned flight mission and desired position through complex flight motions.

Table 1 :
PID and quaternion control parameters

Table 2 :
Comparison of the three algorithms