EKF-AF PID-Based Attitude Control Algorithm for UAVs

Aiming at the problems of manual setting of control rules and low control accuracy of the fuzzy PID control method, an attitude control method of the unmanned aerial vehicle (UAV) based on the extended Kalman lter (EKF) and adaptive fuzzy PID (AF PID) is proposed. e dynamics equations and measurement equations of UAV are established, and the EKF is used to estimate and predict attitude changes; an adaptive fuzzy PID control algorithm is designed, and the adaptive adjustment method is adopted to revise fuzzy control rules and parameters online; a simulation platform of the attitude control system (ACS) of UAV is built to simulate and verify the control eect of the method. e simulation results show that the proposed algorithm can estimate the change of attitude angles accurately and improve the control accuracy; meanwhile, it also ensures the stability and rapidity of the attitude changes. e research results can resolve the contradiction between high precision and rapid stability of complex systems to a certain extent.


Introduction
Autonomous aerial refueling (AAR) is an activity of one UAV delivering fuel to another or multiple UAVs during ight, which can signi cantly improve the airborne time and endurance of UAVs and increase the payload of UAVs [1,2]. During the aerial refueling phase, the speed and attitude of the UAVs must be consistent. Otherwise, it may cause refueling failure or crash, which causes signi cant economic losses [3]. e UAV is a typical under-driven and complex nonlinear system with such characteristics as strong coupling and susceptibility to disturbance from external factors, which increases the complexity and di culty of the control method [4,5]. erefore, for ensuring the success of the air refueling phase, it is necessary to study a control algorithm with high control accuracy and strong anti-interference ability.
At present, many researchers have done various works on UAV control and designed many control algorithms and strategies [6], mainly including PID control [7,8], neural network control [9][10][11], predictive control [12,13], active disturbance rejection control [1,14], sliding mode control [15], backstepping control [16][17][18], and so on. Due to the characteristics of mature control technology, simple principle, and easy implementation, the PID control method is widely applied in many elds [6]. However, the problems of real-time parameter adjustment and high-precision control in PID control are still the research hotspots and di culties of UAVs [19][20][21][22]. Yu and Yang [23] proposed an attitude control method of UAVs based on improved dual closedloop PID to optimize the ight result and improve its antijamming. Bolandi [7] used the frequency-domain analysis method to study the selection of control parameters of the UAV attitude controller, so as to optimize the PID control e ect. Alexis [24] applied fuzzy PID to the attitude control system of the UAV by formulating fuzzy rules, and the control performance is improved. Zhang et al. [25] designed a cascade fuzzy PID attitude controller to enhance the antijamming ability and accelerate the responsiveness and improve control accuracy. Dong [26] designed a fuzzy adaptive PID controller with control parameters as variables to enhance the system stability and accelerate the response time. Zhang and Zhang [27] used the fuzzy neural network to design an adaptive PID control algorithm for UAV, which can improve the control accuracy and robustness. Liu et al. [28] proposed a robust PID attitude control algorithm to enhance the robustness of systems. Rosales et al. [29] combined the traditional PID and neural network to propose an improved attitude control algorithm, which can reduce the control errors. Islam et al. [30] used the neural network to design a PID attitude controller, which can decompose multiple variables of the system to obtain a good flight effect. Although the aforementioned control algorithms have made certain progress in the attitude control of the UAV, there are still problems such as manual setting of fuzzy control rules and low control accuracy; in response to these problems, an EKF-AF PID attitude control algorithm with adaptive adjustment of fuzzy rules is proposed to promote the control effect and accelerate the system response.
In Section 2, the motion model and measurement model of the UAV attitude are established, and the EKF is used to estimate and predict the attitude changes. e adaptive fuzzy PID control algorithm is presented, and the adaptive adjustment method is used to adjust control rules and parameters online. In Section 3, a simulation platform of the attitude control system (ACS) for UAV based on Simulink is built to simulate and verify the control effect. In Section 4, concluding remarks are made.

Attitude Motion Model of UAV.
Generally, the UAV attitude is often represented by Euler angles (φ, θ and ψ). e angular velocity vector of the UAV is ω Assuming that the inertia matrix of the UAV is J � (J x , J y , J z ) T , the resultant matrix is M � (M x , M y , M z ) T , and the moment of momentum is H � (H x , H y , H z ) T ; according to the moment of momentum theorem [31], we can get Choosing O-xyz as the body coordinate system of the UAV, equation (1) can be rewritten as e relative angular velocity vector ( _ ϕ, _ θ, _ ψ) obeys the following equation [2]: e state-space model based on the first-order differential equation is adopted to express the attitude motion of the UAV. Specifically, a multi-dimensional state variable X�(φ, θ, ψ, ω x , ω y , ω z ) T is constructed. e multi-dimensional state variable contains not only the rotation angle information of the UAV relative to a certain reference coordinate system but also the rotation speed information. According to equations (2) and (3), the motion state model is obtained as where Considering the high complexity of body structure and flight environment of the UAV, as well as some external uncertain factors, equation (4) can be modified as where ε → (t) is the random disturbance term, which represents the comprehensive influence of the model fitting error, nonmodel component, and random disturbance on the attitude of the UAV.

Attitude Measurement Model of UAV.
e attitude measurement system is used to determine the attitude of the UAV at any time, and it is a prerequisite for the control, management, and use of the UAV. At present, the equipment that measured the attitude of the UAV usually includes inertial navigation system (INS), vision navigation system (VisNav), Global Positioning System (GPS), infrared sensors, global navigation satellite system (GNSS), and BeiDou Navigation Satellite System (BDS) [32][33][34][35]. According to the number of measurement equipment, the attitude measurement system can be divided into the single-equipment measurement system and the multiequipment measurement system [36,37]. e singleequipment measurement system is easily affected by external interference, resulting in inaccurate attitude measurement. e multi-equipment measurement system can restrain the effect of external interference and improve the accuracy of the attitude measurement. erefore, a multiequipment measurement system is adopted to measure the attitude in this paper, which includes a integrating gyroscope, an accelerometer, a magnetometer, and two GPS receivers. e output of the integrating gyroscope is ω → g � (ω gx , ω gy , ω gz ) T of the rotational angular velocity of the UAV. e measurement model is where η → 1 represent the measurement errors. e output of the accelerometer is a → � (a x , a y , a z ) T of the gravity acceleration at the location of the drone. e measurement model is where g → e � (g ex , g ey , g ez ) T represent the gravity acceleration vectors and η → 2 represent the measurement errors. e output of the three-axis magnetometer is h → � (h x , h y , h z ) T of the geomagnetic field intensity at the location of the drone. e measurement model is where H → e � (H ex , H ey , H ez ) T is the local geomagnetic vector and η → 3 represent the measurement errors. e two GPS receivers are mounted on the longitudinal axis of the body coordinate system. e measurement values of the two GPS receivers are (x 1 , y 1 , z 1 ) and (x 2 , y 2 , z 2 ), and the components of the baseline vector of two GPS receivers along the body coordinate system are According to the relationship between attitude angle and position, the measurement model of the GPS receiver is established. Δx where η → 4 represent the measurement errors. Choosing the measurement variance Z�(a x , a y , a z , h x , h y , h z , Δx, Δy, Δz, ω gx , ω gy , ω gz ) T , according to equations (7)-(11), the measurement system model can be given.

Attitude Estimation Based on EKF. Equation
where T is the sampling time.
If the T �1, equation (13) is expressed as , the discretization model of motion state equation is obtained as where f[X(k)] is a nonlinear function and W(k) is the noise vector.
Similarly, the discretization model of the measurement equation is where G[X(k)] is a nonlinear function and V(k) is the noise vector.
According to the EKF method [35], we can get where X�X(k) , P(k) is the covariance matrix, Q(k) is the variance matrix of the process noise, K(k) is the gain matrix, and R(k) is the variance matrix of the measurement noise.

Mobile Information Systems
When the initial values of X(0) and P(0) are given and the measured values Z(k) at the corresponding time are known, the current estimation values X(k) are obtained by recursive solution.

Adaptive Fuzzy PID Attitude Control Algorithm.
As we can see from equation (1), the attitude control of the UAV is mainly to control the attitude angle φ, θ and ψ and make them maintain stability and essentially adjusting the total moment M of the UAV to make the UAV maintain attitude stable. According to the nonlinear characteristics of UAVs and the requirements of the actual application environment, an adaptive fuzzy PID control method is adopted to improve the capability of the dynamic response and adaptive antijamming of the UAV. e adjustment parameters and control rules of traditional fuzzy control methods are fixed. Due to the roughness and imperfection of fuzzy rules, the traditional fuzzy control method cannot effectively control the dynamic changes of the UAV. For this, Figure 1 shows an adaptive fuzzy PID control method. Based on the traditional fuzzy PID control method, a rule-adaptive learning controller and adjustment factors are added to achieve the revisions of control rules and parameters online.
Taking the error e and error change rate ec of attitude angles as input, the self-adjustment factor and control rule adaptive learning are used to make the fuzzy controller output the control parameter revisions ∆K P , ∆K I , and ∆K D and then make the revisions input into the PID controller, and finally the control variance u can be obtained.

Fuzzy PID Controller. e and ec of attitude angles can be given as
where X d is the expected value. When designing a fuzzy controller, a fuzzy subset of the input and output must be obtained first. In this paper where E represent the fuzzy variances of e; EC represent the fuzzy variances of ec; S represent the fuzzy variances of s; K e � 2/e max − e min ; K ec � 2/ec max − ec min ; and L s � s max − s min /2. According to equation (23), the quantization factors K e , K ec and the scale factor L s are adaptively adjusted. According to the quantized value, a certain fuzzy subset can be obtained through the degree of membership function. e degree of membership is a value between 0 and 1, which is adopted to express the degree of an input fuzzy itself. In this paper, a triangular membership function with a symmetric, uniformly distributed, and fully overlapping function is chosen to calculate the degree of membership of the quantized input [38], and the corresponding fuzzy subsets can be obtained.  e fuzzy inference is the basis for designing the fuzzy controller. After the input is fuzzified, a fuzzy rule library needs to be established to output the inference result. When the values of K p and K I are increased, the error e is reduced; when the value of K D is decreased, the error change rate ec is reduced. According to the change of e and ec, the three fuzzy rules are shown in Tables 1-3 [39].
According to the fuzzification results of E and EC, combined with three fuzzy rule tables and Mamdani's minmax reasoning rule [40], the degree of membership of fuzzy    Mobile Information Systems subsets S 1 , S 2 , and S 3 of the parameter revisions ∆K P , ∆K I and ∆K D can be obtained.
where R is the fuzzy rule set; n is the number of rules; R i is the i th rule; μ is the degree of membership; C i , and D i are the inputs under the i th rule; and O i is the output under the i th rule. e precise value of each output is calculated by the typical center of gravity defuzzification method.
According to equations (23) and (25), the actual revisions of the fuzzy controller parameters can be obtained.
ΔK P � L sP S P + s P max − s P min 2 , According to the results of equation (26), the parameters of PID controller can be given.
According to the above results and the structure characteristics of UAVs, the control output u is obtained.

Self-Adjustment of Fuzzy Rules.
For completing the modulation of control rules online, a performance function is given.
where ρ is the weighting coefficient. e partial differential of J is According to equations (30) and (31), the negative gradient function can be given.       Mobile Information Systems Referring to the idea of neural network optimization [41], the control variance is obtained.
According to the results of equations (32) and (33), the control rules can be modified as where μ O i (S i ) is the degree of membership and ΔO i is the revision of the output. Figure 2 shows a simulation platform of the ACS. e simulation platform mainly includes 10 unit modules.

Simulink-Based Design of Simulation Platform for ACS.
e specific design and implementation are as follows.

Attitude Dynamics Module.
According to the result of equation (1), the simulation module of the attitude dynamics model is built as shown in Figure 3.

Attitude Kinematics Module.
According to the result of equation (3), the simulation module of the attitude kinematics model is built as shown in Figure 4.

Measurement System
Module.
e measurement system includes a gyroscope, an accelerometer, a magnetometer, and two GPS receivers. erefore, the measurement system module includes four simulation modules. e specific design is as follows.
According to the result of equation (7), the simulation module of the three-axis gyroscope is built as shown in Figure 5.
According to equation (8), we can see that when the measured value of the accelerometer is known, the attitude angle can be calculated. In order to facilitate the construction of the simulation module, the calculated attitude angle is used as the measured value of the accelerometer. erefore, the simulation module of the three-axis accelerometer is built as shown in Figure 6.
Similarly, the simulation modules of the magnetometer are built as shown in Figure 7. e simulation modules of the GPS are built as shown in Figure 8.   3.1.5. Feedback Module. According to the result of equation (22), the simulation module of the state feedback is built as shown in Figure 10.
3.1.6. PID Controller Module. Figure 11 shows the simulation module of the PID controller.

Actuator
Module. e motor is selected as the actuator, and we can get [42] where V is the voltage; M is the torque; L is the inductance; K m is the torque moment coefficient (N * m/A); and R is the resistance.
According to the result of equation (35), the simulation module of the actuator is built as shown in Figure 12.

Mobile Information Systems
According to the above results, the simulation platform of the ACS can be shown in Figure 13.

Simulation Result and Analysis.
During the process of the autonomous refueling, the two UAVs need to remain relatively stationary. Assuming that the tanker is flying parallel to the ground, the attitude of the receiver is consistent with the tanker, that is, to stabilize at the desired attitude angle [0 0 0]. A certain type of fixed-wing UAV is taken as an example, and the initial simulation parameters are set to simulate and verify the control effect. e estimation results of the attitude angles are shown in Figure 14. For the model of the UAV with nonlinearity and uncertainty, the proposed method can estimate the change of attitude angles accurately, and the estimation accuracy is high. Figure 15 shows the tracking result comparison of the attitude angle in different control algorithms. From Figure 15, compared with the traditional PID, the control accuracy of the proposed method is better, the attitude change is relatively stable, the steady state can be reached quickly, and the error of steady state is small.

Conclusions
We proposed an EKF-AF PID-based attitude control algorithm for UAVs in this paper, and the algorithm can improve the control accuracy of the ACS. An attitude estimation method based on EKF is established and an adaptive fuzzy PID algorithm is designed, and finally a simulation platform of the ACS is established to simulate and verify the control effect.
EKF-AF PID-based attitude control algorithm for UAVs can estimate the attitude change accurately, and the control accuracy is high; meanwhile, it has fast control time and small control error. e research results can resolve the contradiction between high precision and rapid stability of complex systems to a certain extent.

Data Availability
e data used to support the findings of this study are included within the article.

Conflicts of Interest
e authors declare that they have no conflicts of interest.