Fuzzy intelligent control method for improving flight attitude stability of plant protection quadrotor UAV

At present, the attitude control method of plant protection UAV is the classical PID control, but there are some imperfections in the PID control, such as the contradiction between speediness and overshoot, the weak anti-jamming ability and adaptability. The physical parameters of plant protection UAV are time-varying, and the airflow also interferes with it. The control ability of classical PID is limited, and its control parameters are fixed, and its anti-jamming ability and adaptability are not strong. Therefore, a fuzzy adaptive PID controller is proposed in this paper. Fuzzy logic control is used to optimize the control parameters of PID in order to improve the dynamic and static performance and adaptability of attitude control of plant protection UAV. In the process of research, the mathematical model of UAV is established firstly, then the fuzzy adaptive PID is designed, and then the simulation is carried out in Simulink. The simulation results show that the fuzzy adaptive PID controller has better dynamic and static control performance and adaptability than the traditional PID controller. Therefore, the proposed control method has excellent application value in the attitude of plant protection UAV.


Introduction 
Agricultural plant protection UAV has increasing broad application prospects in modern agricultural production [1] .On the one hand, the complex working environment increases the test of the stability of the drone.On the other hand, agricultural plant protection drones operate in low-altitude, low-speed environments, and the flight is greatly affected by the environment, which makes it difficult to control the operation of agricultural drones.In addition, the sensors on the agricultural plant protection drone are limited by cost, volume and weight, and the accuracy will be affected, which will affect the flight control of the plant protection drone.In this case, it is especially important to develop an excellent attitude control method.
At present, domestic plant protection drones generally use traditional PID control algorithms.Aiming at the small-area planting area and precision agriculture development demand in southern China, Huang [2] designed a small quadrotor plant protection drone using the classical PID control method.In response to the operational characteristics and application fields of agricultural drones, Liu et al. [3] designed the longitudinal attitude control system for agricultural drones using classical PID control methods.In view of the limited performance of PID control, Liu hopes to apply more efficient control methods to flight control of agricultural drones.In order to solve the problem that plant protection drones cannot achieve obstacle avoidance, Qiu [4] developed a flight control system suitable for agricultural plant protection drones based on classical PID control.
However, there are some imperfections in the structure of the classic PID controller [5,6] .For example, there are contradictions in the rapidity of control and overshoot.The effect of suppressing time-varying disturbances is not significant, and the adaptability of classical PID control is not strong.In this case, the use of the classic PID control method will limit the attitude control performance of the plant protection drone.The reason is that the three control parameters (proportional gain, integral gain and differential gain) of the PID control cannot be adjusted at any time with the change of the environment.Therefore, in order to improve the attitude control performance of plant protection drones, this paper proposes a fuzzy adaptive PID control method.The fuzzy control combines the traditional expert system based on the rules, fuzzy set theory and the achievements of cybernetics [7] .Combining fuzzy control with classic PID control will achieve better results than classic PID control [8,9] .
The purpose of this study is to introduce fuzzy logic control based on classical PID control, optimize the parameters of PID, improve the attitude control performance of plant protection UAV, and improve the adaptability of plant protection UAV.In the process of research, we first use the Newton-Euler method to establish the mathematical model of the UAV, then design a fuzzy adaptive PID control algorithm, and carry out simulation experiments in Simulink.The experimental results show that the proposed method is feasible.

Dynamic modeling of quadrotor UAV
In order to establish the mathematical model of quadrotor UAV conveniently, firstly, the flight conditions of quadrotor UAV are rationally simplified, then establishes the system reference frame, carries out force analysis and moment analysis of the quadrotor UAV on the basis of the assumptions, and finally establishes the dynamic mathematical model of the quadrotor UAV.In this paper, a quadrotor UAV with a cross structure is shown in Figure 1.
Figure 1 Cross type structure quadrotor UAV It is difficult to mathematically model the quadrotor flight system in the actual flight process, such as the external airflow conditions and the inherent influence of the internal airframe structure.In order to facilitate modeling, the following reasonable assumptions are made for these uncertainties [10] .
1) The quadrotor is a symmetrical rigid body; 2) The origin of the inertial coordinate system is in the same position as the geometric center and centroid of the quadrotor; 3) Resistance and gravity of the quadrotor do not be affected by flight altitude and other factors; 4) Tensions in all directions are proportional to the square of the propeller speed.
An adequate dynamic system model was vital to the simulation of the control strategy.In order to get the mathematical modeling for the quadrotor, two coordinate systems were established, which were inertial coordinate system E(Oxyz) and body coordinate system B(O b x b y b z b ), shown in Figure 1.These two coordinates can be converted to each other through transition matrix R. The transformation matrix R can be expressed by Euler angle [11] .Euler angles can be used to describe the quadrotor's attitude, roll (φ), pitch (θ), and yaw (ψ).In Figure 2, the Euler angles are defined as follows: Yaw angle ψ is the angle between the X-axis and the projection of Ox in the OXY plane; Pitch angle θ is the angle between the Z-axis and the projection of Oz in the OXZ plane; Roll angle φ is the angle between the Y-axis and the projection of Oy in the OYZ plane.
where, s and c denote sine and cosine functions respectively, i.e., cψcθ=cosψcosθ, sψcφ=sinψcosφ.Newton's second law and aircraft dynamics equation [12,13] can be expressed as vectors, respectively, as follows: where, F is the external force acting on the quadrotor aircraft; m is the mass of the quadrotor aircraft; V is the speed of the aircraft; M is the sum of the momentum acting on the quadrotor aircraft; H is the absolute momentum of the quadrotor aircraft relative to the inertial coordinate system.Gravity G, lift T i and reverse torque D i of the single rotor are expressed as follows.
where, k t and k d are force and moment constants and ω i is the propeller's rotation speed.
According to the force analysis, Newton's second law and aircraft dynamics equation can be obtained linear motion equation, which is expressed as follows: (cos cos ) / where, F x , F y , F z are defined as the components of F on the three coordinate axes of the body coordinate system; K 1 , K 2 , K 3 are the resistance coefficients in linear motion.
According to the relationship between Euler angles and angular velocities of quadrotor aircraft, the following set of formulas can be obtained.sin cos sin cos sin cos cos ( cos sin sin cos sin ) / cos cos sin ( sin cos ) / cos where, p, q, rare components of angular velocity ω on the three coordinate axes of the body coordinate system.
As previously assumed, the mass and structure of a quadrotor aircraft are uniformly symmetrical, so its inertia matrix can be defined as diagonal matrix I.
, we can get By calculating the angular momentum, the angular motion equations of the three-axis components of M in the body coordinate system, M x , M y and M z , are obtained.
According to diagonal matrix I, the above set of formulas can be simplified as the following one Combining the above linear motion equation with the angular motion equation, the quadrotor nonlinear motion equation is obtained.
The quadrotor is subjected to one force and three moments [14] .These force and moments represent the inputs of the four independent control inputs to quadrotor and they can be defined as vertical force input U 1 , pitch moment input U 2 , roll moment input ) where, T i , D i , k t , k d have been defined earlier and l is the distance from the center of the rotor to the origin of the body coordinate system.
In the case of no wind and low-speed flight, the drag coefficients K 1 , K 2 , K 3 are negligible.In addition to the torque generated by actuators, the quadrotor UAV is also affected by the gyroscopic effect caused by the airframe or rotor.However, the effect of the gyroscopic effect, especially in hovering or low-speed flight, is negligible compared with that produced by actuators, which can be simplified as a small disturbance of the system, so we can get a simplified model.

Attitude control algorithms design
In this section, two controllers for the attitude control of the quadrotor are presented, which are the traditional PID controller and the fuzzy adaptive PID controller, respectively.
As mentioned before the inputs chose like equations (11), where U 1 controls the motion along the z-axis, U 2 controls rotation along the x-axis (roll angle), U 3 controls the rotation along the y-axis (pitch angle), and U 4 controls rotation along the z-axis (yaw angle).The designed controllers should set values to parameters which determine the four rotor speed parameters by equations (12).

Traditional PID controller
The quadrotor UAV system has only four input control variables, but there are six degrees of freedom, and the six constraints relation are existed among the six outputs, so it is difficult to control the position and attitude accurately at the same time [15] .The nested loops control architecture was employed to control the flight position and attitude respectively, as shown in Figure 3.The PID control was used in each loop.Note that this paper only studies four channels: altitude, roll, pitch and yaw, so the x, y channels in Figure 3   The equation of a PID controller has the following form: ( ) ( ) ( ) ( ) where, K p , K i and K d are called the proportional, integral and differential gains, respectively; e(t) is the error between the expected value and the actual value.

Fuzzy system for tuning the PID gains
The success of the PID controller depends on the appropriate PID gains.Tuning the PID gains is very important to optimize performance.In practice, the PID gains are usually tuned by experienced human experts based on some "rule of thumb".In this work, we first determined a set of tuning rules (fuzzy IF-THEN rules) for the PID gains, and then combine these rules into a fuzzy system that is used to adjust the PID gains on-line [16] .
A fuzzy PID controller takes the classical PID controller as the foundation which uses the fuzzy reasoning and variable universe of discourse to regulate the PID gains [17] .The characteristics of a fuzzy system such as robustness and adaptability can be successfully incorporated into the controlling method for better tuning of PID gains.
The term self-tuning refers to the characteristics of the controller to tune its controlling parameters on-line automatically so as to have the most suitable values of those gains result in optimization of the process output.Fuzzy adaptive PID controller works on the control rules design on the basis of theoretical and experience analysis.Therefore, it can tune the gains K p , K i and K d , and by adjusting the other controlling parameters and factors on-line.This makes the precision of overall control higher and hence gives a better performance than the classical PID controller.
The self-tuning fuzzy PID controller, which takes error "e" and rate of change-in-error "ec" as the input to the controller makes use of the fuzzy controller rules to modify PID gains on-line.The self-tuning the PID controller refers to finding the fuzzy relationship between the three gains of PID, K p , K i and K d , and "e" and "ec".According to the principle of fuzzy control, modifying the three gains is important to meet different requirements for control gains when "e" and "ec" are different and making the control object produce a good dynamic and static performance.For selecting the inputs language variables of "e" and "ec", and the outputs language variables of ΔK p , ΔK i andΔK d , choose seven fuzzy values (NB, NM, NS, ZO, PS, PM, PB) which NB denotes Negative Big, NM denotes Negative Medium, Negative Small (NS), Zero (ZO), Positive Small (PS), Positive Medium (PM) and PB denotes Positive Big.
Figure 4 shows the block diagram of a fuzzy adaptive PID controller.As can be seen from the block diagram, the fuzzy system takes two inputs (e and ec) and gives three outputs (ΔK p , ΔK i and ΔK d ).This block diagram just shows the control of one degree of freedom of a quadrotor and we are used three other controllers like this controller for attitude and altitude control of quadrotor.
All input and output membership functions are of the same type, that is, Gauss function.Figure 5 shows these membership functions.The width of the fuzzy sets used for controllers is not the same and they have been determined by trial and error experience.The width of the fuzzy sets for output ΔK p have been chosen [-60 60], ΔK i have been chosen [-0.2 0.2] and for ΔK d , [- 10 10].And for inputs, the range for the error 'e' and error rate 'ec' have been chosen [- 10 10].
The set of linguistic rules is the essential part of a fuzzy controller.As a rule of thumb, the parameters K p , K i and K d are self-adjusted under different e and ec according to the following adjustment principles [18][19] : (1) When the error value e is large and the error rate ec is small, in order to improve the reaction speed of the system, K p should be larger; in order to prevent overshoot from being too large, K i should be smaller; and K d should be smaller.
(2) When the error value e and the error change rate ec are medium, K p and K i should be moderate and K d should be large.
(3) When the error value e is small, K p should be larger.In order to reduce static error, the value of K i should be increased, while K d will change with the change rate of error.
The fuzzy rules for tuning the PID gains can be obtained from the above PID regulation rules and expert experience, as shown in Table 2.
The rules which were presented at the table can be read as follows: If the error is NB and the error rate is PS THEN ΔK p is NS and ΔK i is ZO and ΔK d is NB.
The output of the fuzzy system logic is fuzzy.We cannot provide these fuzzy outputs to a dynamical system as control inputs directly.The defuzzification process is needed to convert these fuzzy outputs to numbers that can represent the fuzzy output.The defuzzification should be logical, should have a high membership degree and it should correspond to the approximately middle of the graph.For the reason discussed above, we have selected a centroid defuzzifier for the controllers.

Simulation and results
In this study, we used the control variable method to study them.For example, when the flight altitude control is studied, the initial and expected values of three attitude angles are set to zero, and then the parameters of the flight altitude PID controller are manually adjusted to achieve the purpose of controlling the flight altitude.When the control of pitch angle is studied, the initial and expected values of the other two attitude angles and heights are set to zero, and then the parameters of the PID controller in pitch channel are manually adjusted to control the pitch angle of aircraft.Similar processing is also used when studying the other two attitude channels.Both of the controllers were run on these two scenarios and the results are compared.
For adjusting classical PID controller gains, the trial-and-error method was used.After repeated experiments, we have set up a set of initial PID gains with good effect, among which K p0 =6, K i0 =0.1, K d0 =1.6.By using a fuzzy system to adjust the PID gain, the PID gain will automatically change according to the fuzzy rules.You can see the of this change in Figures 6, 7 and 8.Because the simulation process of the three attitude channels is similar, only the simulation results of the pitch channel are shown below.The results of the two methods for the pitch channel were shown in Figure 9.In this figure, it showed the different responses of the pitch angle between two methods, classical PID controller and fuzzy PID controller.It is evident from this chart that the performances improved by using the fuzzy system for tuning the PID gains.Although the rise time and the steady precision of the two control methods are almost the same, the overshoot of the fuzzy adaptive PID controller is nearly 40% less than that of the classical PID controller and the setting time of the fuzzy PID controller is only half of that of the classical PID controller.In addition, in order to verify the resistance against external interference and disturbances ability of the two control algorithms, when the simulation time is 7 seconds, a pulse signal with a pulse span of 3%, a period of 10 seconds and an amplitude of 10 is added.From Figure 10, we can see clearly that the resistance against external interference and disturbances ability of the fuzzy adaptive PID controller is better than that of the classical PID controller.The simulation effect of the altitude loop using the fuzzy adaptive PID control method is also very good, which can be seen from Figure 11.The settling time of fuzzy adaptive PID is less than 25% of classical PID.Fuzzy adaptive PID almost has no overshoot.At the same time, the anti-interference ability of fuzzy adaptive PID is also very good.

Conclusions
In order to restrain the influence of structural parameters change and internal and external disturbances on attitude control performance and improve the adaptability of plant protection UAV, a fuzzy adaptive PID controller is designed in this study.On the basis of classical PID control, the fuzzy logic control introduced to optimize the PID parameters.The experimental results show that the proposed method can effectively realize the attitude control of plant protection UAV, and has good static and dynamic control performance and good adaptability.The fuzzy adaptive PID control method proposed in this study can solve some problems existing in classical PID control.It has good application prospects in attitude control of plant protection UAV.

Figure 2
Figure 2 Diagram of Euler angle Get the transition matrix R from the body coordinate system B(O b x b y b z b ) to the inertial coordinate system E (Oxyz).R=Rx•Ry•Rz c c s c c s s s s c s s s c c c s s s c s s s s s c s c c are dotted.

Figure 3 PID
Figure 3 PID Control diagram of the quadrotor UAV system

Figure 4 Figure 5
Figure 4 Block diagram of the fuzzy adaptive PID controller

Figure 6 FuzzyFigure 8
Figure 6 Fuzzy PID parameter K p adaptive adjustment curve

Figure 9
Figure 9 Comparison of simulation results between classical PID and fuzzy adaptive PID controller in pitch loopIn addition, the output of the fuzzy adaptive PID controller is only 25% of the classical PID controller, as shown in Figure10.

Figure 10
Figure 10 Simulation comparison of output of fuzzy adaptive PID and classical PID controller

Figure 11
Figure 11 Comparison of simulation results between classical PID and fuzzy adaptive PID controller in altitude loop

Table 2
Fuzzy rules for ΔK p , ΔK i , ΔK d