# EKF-AF PID-Based Attitude Control Algorithm for UAVs

Authors: He Song; Shaolin Hu; Wenqiang Jiang; Qiliang Guo
Journal: Mobile Information Systems
 (2022)

---

## Abstract

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 filter (EKF) and adaptive fuzzy PID (AF PID) is proposed. The 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 effect of the method. The 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. The research results can resolve the contradiction between high precision and rapid stability of complex systems to a certain extent.


---

## Body

## 1. Introduction

Autonomous aerial refueling (AAR) is an activity of one UAV delivering fuel to another or multiple UAVs during flight, which can significantly 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 significant economic losses [3]. The 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 difficulty of the control method [4, 5]. Therefore, 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–11], predictive control [12, 13], active disturbance rejection control [1, 14], sliding mode control [15], backstepping control [16–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 fields [6]. However, the problems of real-time parameter adjustment and high-precision control in PID control are still the research hotspots and difficulties of UAVs [19–22]. Yu and Yang [23] proposed an attitude control method of UAVs based on improved dual closed-loop PID to optimize the flight result and improve its anti-jamming. 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 effect. 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 anti-jamming 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 Section2, the motion model and measurement model of the UAV attitude are established, and the EKF is used to estimate and predict the attitude changes. The 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.


## 2. Attitude Estimation of UAV Based on EKF

### 2.1. Attitude Motion Model of UAV

Generally, the UAV attitude is often represented by Euler angles (φ, θ and ψ). The angular velocity vector of the UAV is ω⟶=ωx,ωy,ωzT. Assuming that the inertia matrix of the UAV is J = (Jx, Jy, Jz)T, the resultant matrix is M = (Mx, My, Mz)T, and the moment of momentum is H = (Hx, Hy, Hz)T; according to the moment of momentum theorem [31], we can get(1)M⟶=J⋅ω⟶˙+ω×J⋅ω⟶.ChoosingO-xyz as the body coordinate system of the UAV, equation (1) can be rewritten as(2)ω˙x=1JxMx+Jy−Jzωyωz,ω˙y=1JyMy+Jz−Jxωxωz,ω˙z=1JzMz+Jx−Jyωxωy.The relative angular velocity vectorϕ˙,θ˙,ψ˙ obeys the following equation [2]:(3)ϕ˙θ˙ψ˙=1cosθcosθsinϕsinθcosϕsinθ0cosϕcosθ−sinϕcosθ0sinϕcosϕωxωyωz.The 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 variableX=(φ, θ, ψ, ωx, ωy, ωz)T is constructed. The 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(4)X˙t=I300diagJx,Jy,Jz−1F1X,tF2X,t,where(5)F1X,t=1sinϕtanθcosϕtanθ0cosϕ−sinϕ0sinϕsecθcosϕsecθωxωyωz,F2X,t=Mx+Jy−JzωyωzMy+Jz−JxωxωzMz+Jx−Jyωxωy.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(6)X˙t=I300diagJx,Jy,Jz−1F1X,tF2X,t+ε⟶t,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.


### 2.2. Attitude Measurement Model of UAV

The 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–35]. According to the number of measurement equipment, the attitude measurement system can be divided into the single-equipment measurement system and the multi-equipment measurement system [36, 37]. The single-equipment measurement system is easily affected by external interference, resulting in inaccurate attitude measurement. The multi-equipment measurement system can restrain the effect of external interference and improve the accuracy of the attitude measurement. Therefore, a multi-equipment measurement system is adopted to measure the attitude in this paper, which includes a integrating gyroscope, an accelerometer, a magnetometer, and two GPS receivers.The output of the integrating gyroscope isω⟶g=ωgx,ωgy,ωgzT of the rotational angular velocity of the UAV. The measurement model is(7)ω⟶g=ω⟶+η⟶1,where η⟶1 represent the measurement errors.The output of the accelerometer isa⟶=ax,ay,azT of the gravity acceleration at the location of the drone. The measurement model is(8)a⟶=cosϕsinϕsinθ−sinϕcosθ0cosθsinθsinϕ−cosϕsinθcosϕcosθg⟶e+η⟶2,where g⟶e=gex,gey,gezT represent the gravity acceleration vectors and η⟶2 represent the measurement errors.The output of the three-axis magnetometer ish⟶=hx,hy,hzT of the geomagnetic field intensity at the location of the drone. The measurement model is(9)h⟶=cosϕcosψ−sinϕsinθsinψcosϕsinψ+sinϕsinθcosψ−sinϕcosθ−cosθsinψcosθcosψsinθsinϕcosψ+cosϕsinθsinψsinϕsinψ−cosϕsinθcosψcosϕcosθH⟶e+η⟶3,where H⟶e=Hex,Hey,HezT is the local geomagnetic vector and η⟶3 represent the measurement errors.The two GPS receivers are mounted on the longitudinal axis of the body coordinate system. The measurement values of the two GPS receivers are (x1, y1, z1) and (x2, y2, z2), and the components of the baseline vector of two GPS receivers along the body coordinate system are(10)Δx=x2−x1,Δy=y2−y1,Δz=z2−z1.According to the relationship between attitude angle and position, the measurement model of the GPS receiver is established.(11)ΔxΔyΔz=Δy⋅cotψΔx⋅tanψΔx2+Δy2⋅tanθ+η⟶4,where η⟶4 represent the measurement errors.Choosing the measurement varianceZ=(ax, ay, az, hx, hy, hz, Δx, Δy, Δz, ωgx, ωgy, ωgz)T, according to equations (7)–(11), the measurement system model can be given.(12)Zt=G1X,tG2X,tG3X,tG4X,t+η⟶t,where G2X,t=cosϕcosψ−sinϕsinθsinψcosϕsinψ+sinϕsinθcosψ−sinϕcosθ−cosθsinψcosθcosψsinθsinϕcosψ+cosϕsinθsinψsinϕsinψ−cosϕsinθcosψcosϕcosθH⟶, G1X,t=cosϕsinϕsinθ−sinϕcosθ0cosθsinθsinϕ−cosϕsinθcosϕcosθg⟶, G3X,t=cotψΔytanψΔxtanθΔx2+Δy2, G4X,t=ωxωyωz, and measurement errors η⟶t=η⟶2η⟶3η⟶4η⟶1T.


### 2.3. Attitude Estimation Based on EKF

Equation (6) can be discretized by the difference approximation method:(13)XkT=Xk−1T+TFXk−1T,k−1T+ε⟶k−1T,where T is the sampling time.If theT = 1, equation (13) is expressed as(14)Xk=Xk−1+FXk−1,k−1+ε⟶k−1.Remembering thatfXk−1=Xk−1+FXk−1,k−1 and Wk−1=ε⟶k−1, the discretization model of motion state equation is obtained as(15)Xk=fXk−1+Wk−1,where fXk is a nonlinear function and Wk is the noise vector.Similarly, the discretization model of the measurement equation is(16)Zk=GXk+Vk,where GXk is a nonlinear function and Vk is the noise vector.According to the EKF method [35], we can get(17)X^k=fXk−1,(18)P^k=Ak−1Pk−1Ak−1T+Qk,(19)Kk=P^kBkTBkP^kBkT+Rk−1,(20)Xk=fXk−1+KkZk−GX^k,(21)Pk=I−KkBkP^k−1,where Αk−1=∂fXk−1/∂X|X=X^k−1, Bk=∂GXk/∂X|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.When the initial values ofX^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.


### 2.4. 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 anti-jamming of the UAV.The 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, Figure1 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.Figure 1
Adaptive fuzzy PID control algorithm.Taking the errore 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 ∆KP, ∆KI, and ∆KD and then make the revisions input into the PID controller, and finally the control variance u can be obtained.


#### 2.4.1. Fuzzy PID Controller

e and ec of attitude angles can be given as(22)ek=Xd−X^k,eck=ek−ek−1,where Xd is the expected value.When designing a fuzzy controller, a fuzzy subset of the input and output must be obtained first. In this paper, 7 language variances {NB, NM, NS, ZE, PS, PM, PB} are selected to represent fuzzy subsets of the PID control. Therefore, the fuzzy subsets ofe, ec and the output s of the controller are defined as {NB, NM, NS, ZE, PS, PM, PB}. In order to correspond the specific values of the input and output quantities to the fuzzy subsets, a quantization function needs to be introduced. In the actual system of UAVs, considering the saturation characteristics of the actuator and the asymmetry of variables, the change ranges of e, ec, and s are [emin, emax], [ecmin, ecmax], and [smin, smax], respectively. Their fuzzy domain is [−1, 1] through normalization, and then the quantization function can be obtained.(23)E=Kee−emax−emin2,EC=Kecec−ecmax−ecmin2,S=Lss−smax−smin2,where E represent the fuzzy variances of e; EC represent the fuzzy variances of ec; S represent the fuzzy variances of s; Ke=2/emax−emin; Kec=2/ecmax−ecmin; and Ls=smax−smin/2.According to equation (23), the quantization factors Ke, Kec and the scale factor Ls are adaptively adjusted. According to the quantized value, a certain fuzzy subset can be obtained through the degree of membership function. The 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.The 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 ofKp and KI are increased, the error e is reduced; when the value of KD 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].Table 1
Fuzzy rules of ∆KP.
∆KPecPBPMPSZENSNMNBePBNBNBNMNMNMZEZEPMNBNMNMNMNSZEPSPSNMNMNSNSZEPSPSZENMNMNSZEPSPMPMNSNSNSZEPSPMPMPMNMNSZEPSPSPMPBPBNBZEZEPSPSPMPBPBTable 2
Fuzzy rules of ∆KI.
∆KIecPBPMPSZENSNMNBePBPBPBPMPMPSZEZEPMPBPBPMPSPSZEZEPSNMNMNSNSZENSNMZEPMPMPSZENSNMNMNSPSPSZENSNSNMNBNMZEZENSNSNMNBNBNBZEZENSNSNMNMNBTable 3
Fuzzy rules of ∆KD.
∆KDecPBPMPSZENSNMNBePBPBPSPSPMPMPMPBPMPBPSPSPSPSPSPBPSZEZEZEZEZEZEZEZEZENSNSNSNSNSZENSZENSNSNMNMNSZENMZENSNMNMNBNSPSNBPSNMNBNBNBNSPSAccording to the fuzzification results ofE and EC, combined with three fuzzy rule tables and Mamdani’s min-max reasoning rule [40], the degree of membership of fuzzy subsets S1, S2, and S3 of the parameter revisions ∆KP, ∆KI and ∆KD can be obtained.(24)R=∪i=1nRi=∪i=1nCi×Di×Oi,μRi=minμCiE,μDiEC,μOiSm,μOs=maxminμC×DE,EC,μRE,EC,Sm,where R is the fuzzy rule set; n is the number of rules; Ri is the ith rule; μ is the degree of membership; Ci, and Di are the inputs under the ith rule; and Oi is the output under the ith rule.The precise value of each output is calculated by the typical center of gravity defuzzification method.(25)S=Oi∑iμOiSiOi∑iμOiSi.According to equations (23) and (25), the actual revisions of the fuzzy controller parameters can be obtained.(26)ΔKP=LsPSP+sPmax−sPmin2,ΔKI=LsISI+sImax−sImin2,ΔKD=LsDSD+sDmax−sDmin2.According to the results of equation (26), the parameters of PID controller can be given.(27)KP=KP+ΔKP,KI=KI+ΔKI,KD=KD+ΔKD.According to the above results and the structure characteristics of UAVs, the control outputu is obtained.(28)uk=KP⋅ek+KI⋅∑i=1kei+KD⋅ek−ek−1.


#### 2.4.2. Self-Adjustment of Fuzzy Rules

For completing the modulation of control rules online, a performance function is given.(29)J=∑k=1ne2k+ρ⋅ec2k,where ρ is the weighting coefficient.The partial differential ofJ is(30)∂J∂ek=eke2k+ρ⋅ec2k,(31)∂J∂eck=ρ⋅ecke2k+ρ⋅ec2k.According to equations (30) and (31), the negative gradient function can be given.(32)−∇J=−∂J∂ek−ρ∂J∂eck.Referring to the idea of neural network optimization [41], the control variance is obtained.(33)ΔS=λ⋅−∇J⋅ekeck,where λ is the learning rate and 0 < λ < 1.According to the results of equations (32) and (33), the control rules can be modified as(34)ΔOi=ΔS⋅μOiSi∑iμOiSi,Oi=Oi+ΔOi,where μOiSi is the degree of membership and ΔOi is the revision of the output.


## 2.1. Attitude Motion Model of UAV

Generally, the UAV attitude is often represented by Euler angles (φ, θ and ψ). The angular velocity vector of the UAV is ω⟶=ωx,ωy,ωzT. Assuming that the inertia matrix of the UAV is J = (Jx, Jy, Jz)T, the resultant matrix is M = (Mx, My, Mz)T, and the moment of momentum is H = (Hx, Hy, Hz)T; according to the moment of momentum theorem [31], we can get(1)M⟶=J⋅ω⟶˙+ω×J⋅ω⟶.ChoosingO-xyz as the body coordinate system of the UAV, equation (1) can be rewritten as(2)ω˙x=1JxMx+Jy−Jzωyωz,ω˙y=1JyMy+Jz−Jxωxωz,ω˙z=1JzMz+Jx−Jyωxωy.The relative angular velocity vectorϕ˙,θ˙,ψ˙ obeys the following equation [2]:(3)ϕ˙θ˙ψ˙=1cosθcosθsinϕsinθcosϕsinθ0cosϕcosθ−sinϕcosθ0sinϕcosϕωxωyωz.The 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 variableX=(φ, θ, ψ, ωx, ωy, ωz)T is constructed. The 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(4)X˙t=I300diagJx,Jy,Jz−1F1X,tF2X,t,where(5)F1X,t=1sinϕtanθcosϕtanθ0cosϕ−sinϕ0sinϕsecθcosϕsecθωxωyωz,F2X,t=Mx+Jy−JzωyωzMy+Jz−JxωxωzMz+Jx−Jyωxωy.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(6)X˙t=I300diagJx,Jy,Jz−1F1X,tF2X,t+ε⟶t,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.


## 2.2. Attitude Measurement Model of UAV

The 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–35]. According to the number of measurement equipment, the attitude measurement system can be divided into the single-equipment measurement system and the multi-equipment measurement system [36, 37]. The single-equipment measurement system is easily affected by external interference, resulting in inaccurate attitude measurement. The multi-equipment measurement system can restrain the effect of external interference and improve the accuracy of the attitude measurement. Therefore, a multi-equipment measurement system is adopted to measure the attitude in this paper, which includes a integrating gyroscope, an accelerometer, a magnetometer, and two GPS receivers.The output of the integrating gyroscope isω⟶g=ωgx,ωgy,ωgzT of the rotational angular velocity of the UAV. The measurement model is(7)ω⟶g=ω⟶+η⟶1,where η⟶1 represent the measurement errors.The output of the accelerometer isa⟶=ax,ay,azT of the gravity acceleration at the location of the drone. The measurement model is(8)a⟶=cosϕsinϕsinθ−sinϕcosθ0cosθsinθsinϕ−cosϕsinθcosϕcosθg⟶e+η⟶2,where g⟶e=gex,gey,gezT represent the gravity acceleration vectors and η⟶2 represent the measurement errors.The output of the three-axis magnetometer ish⟶=hx,hy,hzT of the geomagnetic field intensity at the location of the drone. The measurement model is(9)h⟶=cosϕcosψ−sinϕsinθsinψcosϕsinψ+sinϕsinθcosψ−sinϕcosθ−cosθsinψcosθcosψsinθsinϕcosψ+cosϕsinθsinψsinϕsinψ−cosϕsinθcosψcosϕcosθH⟶e+η⟶3,where H⟶e=Hex,Hey,HezT is the local geomagnetic vector and η⟶3 represent the measurement errors.The two GPS receivers are mounted on the longitudinal axis of the body coordinate system. The measurement values of the two GPS receivers are (x1, y1, z1) and (x2, y2, z2), and the components of the baseline vector of two GPS receivers along the body coordinate system are(10)Δx=x2−x1,Δy=y2−y1,Δz=z2−z1.According to the relationship between attitude angle and position, the measurement model of the GPS receiver is established.(11)ΔxΔyΔz=Δy⋅cotψΔx⋅tanψΔx2+Δy2⋅tanθ+η⟶4,where η⟶4 represent the measurement errors.Choosing the measurement varianceZ=(ax, ay, az, hx, hy, hz, Δx, Δy, Δz, ωgx, ωgy, ωgz)T, according to equations (7)–(11), the measurement system model can be given.(12)Zt=G1X,tG2X,tG3X,tG4X,t+η⟶t,where G2X,t=cosϕcosψ−sinϕsinθsinψcosϕsinψ+sinϕsinθcosψ−sinϕcosθ−cosθsinψcosθcosψsinθsinϕcosψ+cosϕsinθsinψsinϕsinψ−cosϕsinθcosψcosϕcosθH⟶, G1X,t=cosϕsinϕsinθ−sinϕcosθ0cosθsinθsinϕ−cosϕsinθcosϕcosθg⟶, G3X,t=cotψΔytanψΔxtanθΔx2+Δy2, G4X,t=ωxωyωz, and measurement errors η⟶t=η⟶2η⟶3η⟶4η⟶1T.


## 2.3. Attitude Estimation Based on EKF

Equation (6) can be discretized by the difference approximation method:(13)XkT=Xk−1T+TFXk−1T,k−1T+ε⟶k−1T,where T is the sampling time.If theT = 1, equation (13) is expressed as(14)Xk=Xk−1+FXk−1,k−1+ε⟶k−1.Remembering thatfXk−1=Xk−1+FXk−1,k−1 and Wk−1=ε⟶k−1, the discretization model of motion state equation is obtained as(15)Xk=fXk−1+Wk−1,where fXk is a nonlinear function and Wk is the noise vector.Similarly, the discretization model of the measurement equation is(16)Zk=GXk+Vk,where GXk is a nonlinear function and Vk is the noise vector.According to the EKF method [35], we can get(17)X^k=fXk−1,(18)P^k=Ak−1Pk−1Ak−1T+Qk,(19)Kk=P^kBkTBkP^kBkT+Rk−1,(20)Xk=fXk−1+KkZk−GX^k,(21)Pk=I−KkBkP^k−1,where Αk−1=∂fXk−1/∂X|X=X^k−1, Bk=∂GXk/∂X|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.When the initial values ofX^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.


## 2.4. 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 anti-jamming of the UAV.The 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, Figure1 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.Figure 1
Adaptive fuzzy PID control algorithm.Taking the errore 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 ∆KP, ∆KI, and ∆KD and then make the revisions input into the PID controller, and finally the control variance u can be obtained.


### 2.4.1. Fuzzy PID Controller

e and ec of attitude angles can be given as(22)ek=Xd−X^k,eck=ek−ek−1,where Xd is the expected value.When designing a fuzzy controller, a fuzzy subset of the input and output must be obtained first. In this paper, 7 language variances {NB, NM, NS, ZE, PS, PM, PB} are selected to represent fuzzy subsets of the PID control. Therefore, the fuzzy subsets ofe, ec and the output s of the controller are defined as {NB, NM, NS, ZE, PS, PM, PB}. In order to correspond the specific values of the input and output quantities to the fuzzy subsets, a quantization function needs to be introduced. In the actual system of UAVs, considering the saturation characteristics of the actuator and the asymmetry of variables, the change ranges of e, ec, and s are [emin, emax], [ecmin, ecmax], and [smin, smax], respectively. Their fuzzy domain is [−1, 1] through normalization, and then the quantization function can be obtained.(23)E=Kee−emax−emin2,EC=Kecec−ecmax−ecmin2,S=Lss−smax−smin2,where E represent the fuzzy variances of e; EC represent the fuzzy variances of ec; S represent the fuzzy variances of s; Ke=2/emax−emin; Kec=2/ecmax−ecmin; and Ls=smax−smin/2.According to equation (23), the quantization factors Ke, Kec and the scale factor Ls are adaptively adjusted. According to the quantized value, a certain fuzzy subset can be obtained through the degree of membership function. The 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.The 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 ofKp and KI are increased, the error e is reduced; when the value of KD 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].Table 1
Fuzzy rules of ∆KP.
∆KPecPBPMPSZENSNMNBePBNBNBNMNMNMZEZEPMNBNMNMNMNSZEPSPSNMNMNSNSZEPSPSZENMNMNSZEPSPMPMNSNSNSZEPSPMPMPMNMNSZEPSPSPMPBPBNBZEZEPSPSPMPBPBTable 2
Fuzzy rules of ∆KI.
∆KIecPBPMPSZENSNMNBePBPBPBPMPMPSZEZEPMPBPBPMPSPSZEZEPSNMNMNSNSZENSNMZEPMPMPSZENSNMNMNSPSPSZENSNSNMNBNMZEZENSNSNMNBNBNBZEZENSNSNMNMNBTable 3
Fuzzy rules of ∆KD.
∆KDecPBPMPSZENSNMNBePBPBPSPSPMPMPMPBPMPBPSPSPSPSPSPBPSZEZEZEZEZEZEZEZEZENSNSNSNSNSZENSZENSNSNMNMNSZENMZENSNMNMNBNSPSNBPSNMNBNBNBNSPSAccording to the fuzzification results ofE and EC, combined with three fuzzy rule tables and Mamdani’s min-max reasoning rule [40], the degree of membership of fuzzy subsets S1, S2, and S3 of the parameter revisions ∆KP, ∆KI and ∆KD can be obtained.(24)R=∪i=1nRi=∪i=1nCi×Di×Oi,μRi=minμCiE,μDiEC,μOiSm,μOs=maxminμC×DE,EC,μRE,EC,Sm,where R is the fuzzy rule set; n is the number of rules; Ri is the ith rule; μ is the degree of membership; Ci, and Di are the inputs under the ith rule; and Oi is the output under the ith rule.The precise value of each output is calculated by the typical center of gravity defuzzification method.(25)S=Oi∑iμOiSiOi∑iμOiSi.According to equations (23) and (25), the actual revisions of the fuzzy controller parameters can be obtained.(26)ΔKP=LsPSP+sPmax−sPmin2,ΔKI=LsISI+sImax−sImin2,ΔKD=LsDSD+sDmax−sDmin2.According to the results of equation (26), the parameters of PID controller can be given.(27)KP=KP+ΔKP,KI=KI+ΔKI,KD=KD+ΔKD.According to the above results and the structure characteristics of UAVs, the control outputu is obtained.(28)uk=KP⋅ek+KI⋅∑i=1kei+KD⋅ek−ek−1.


### 2.4.2. Self-Adjustment of Fuzzy Rules

For completing the modulation of control rules online, a performance function is given.(29)J=∑k=1ne2k+ρ⋅ec2k,where ρ is the weighting coefficient.The partial differential ofJ is(30)∂J∂ek=eke2k+ρ⋅ec2k,(31)∂J∂eck=ρ⋅ecke2k+ρ⋅ec2k.According to equations (30) and (31), the negative gradient function can be given.(32)−∇J=−∂J∂ek−ρ∂J∂eck.Referring to the idea of neural network optimization [41], the control variance is obtained.(33)ΔS=λ⋅−∇J⋅ekeck,where λ is the learning rate and 0 < λ < 1.According to the results of equations (32) and (33), the control rules can be modified as(34)ΔOi=ΔS⋅μOiSi∑iμOiSi,Oi=Oi+ΔOi,where μOiSi is the degree of membership and ΔOi is the revision of the output.


## 2.4.1. Fuzzy PID Controller

e and ec of attitude angles can be given as(22)ek=Xd−X^k,eck=ek−ek−1,where Xd is the expected value.When designing a fuzzy controller, a fuzzy subset of the input and output must be obtained first. In this paper, 7 language variances {NB, NM, NS, ZE, PS, PM, PB} are selected to represent fuzzy subsets of the PID control. Therefore, the fuzzy subsets ofe, ec and the output s of the controller are defined as {NB, NM, NS, ZE, PS, PM, PB}. In order to correspond the specific values of the input and output quantities to the fuzzy subsets, a quantization function needs to be introduced. In the actual system of UAVs, considering the saturation characteristics of the actuator and the asymmetry of variables, the change ranges of e, ec, and s are [emin, emax], [ecmin, ecmax], and [smin, smax], respectively. Their fuzzy domain is [−1, 1] through normalization, and then the quantization function can be obtained.(23)E=Kee−emax−emin2,EC=Kecec−ecmax−ecmin2,S=Lss−smax−smin2,where E represent the fuzzy variances of e; EC represent the fuzzy variances of ec; S represent the fuzzy variances of s; Ke=2/emax−emin; Kec=2/ecmax−ecmin; and Ls=smax−smin/2.According to equation (23), the quantization factors Ke, Kec and the scale factor Ls are adaptively adjusted. According to the quantized value, a certain fuzzy subset can be obtained through the degree of membership function. The 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.The 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 ofKp and KI are increased, the error e is reduced; when the value of KD 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].Table 1
Fuzzy rules of ∆KP.
∆KPecPBPMPSZENSNMNBePBNBNBNMNMNMZEZEPMNBNMNMNMNSZEPSPSNMNMNSNSZEPSPSZENMNMNSZEPSPMPMNSNSNSZEPSPMPMPMNMNSZEPSPSPMPBPBNBZEZEPSPSPMPBPBTable 2
Fuzzy rules of ∆KI.
∆KIecPBPMPSZENSNMNBePBPBPBPMPMPSZEZEPMPBPBPMPSPSZEZEPSNMNMNSNSZENSNMZEPMPMPSZENSNMNMNSPSPSZENSNSNMNBNMZEZENSNSNMNBNBNBZEZENSNSNMNMNBTable 3
Fuzzy rules of ∆KD.
∆KDecPBPMPSZENSNMNBePBPBPSPSPMPMPMPBPMPBPSPSPSPSPSPBPSZEZEZEZEZEZEZEZEZENSNSNSNSNSZENSZENSNSNMNMNSZENMZENSNMNMNBNSPSNBPSNMNBNBNBNSPSAccording to the fuzzification results ofE and EC, combined with three fuzzy rule tables and Mamdani’s min-max reasoning rule [40], the degree of membership of fuzzy subsets S1, S2, and S3 of the parameter revisions ∆KP, ∆KI and ∆KD can be obtained.(24)R=∪i=1nRi=∪i=1nCi×Di×Oi,μRi=minμCiE,μDiEC,μOiSm,μOs=maxminμC×DE,EC,μRE,EC,Sm,where R is the fuzzy rule set; n is the number of rules; Ri is the ith rule; μ is the degree of membership; Ci, and Di are the inputs under the ith rule; and Oi is the output under the ith rule.The precise value of each output is calculated by the typical center of gravity defuzzification method.(25)S=Oi∑iμOiSiOi∑iμOiSi.According to equations (23) and (25), the actual revisions of the fuzzy controller parameters can be obtained.(26)ΔKP=LsPSP+sPmax−sPmin2,ΔKI=LsISI+sImax−sImin2,ΔKD=LsDSD+sDmax−sDmin2.According to the results of equation (26), the parameters of PID controller can be given.(27)KP=KP+ΔKP,KI=KI+ΔKI,KD=KD+ΔKD.According to the above results and the structure characteristics of UAVs, the control outputu is obtained.(28)uk=KP⋅ek+KI⋅∑i=1kei+KD⋅ek−ek−1.


## 2.4.2. Self-Adjustment of Fuzzy Rules

For completing the modulation of control rules online, a performance function is given.(29)J=∑k=1ne2k+ρ⋅ec2k,where ρ is the weighting coefficient.The partial differential ofJ is(30)∂J∂ek=eke2k+ρ⋅ec2k,(31)∂J∂eck=ρ⋅ecke2k+ρ⋅ec2k.According to equations (30) and (31), the negative gradient function can be given.(32)−∇J=−∂J∂ek−ρ∂J∂eck.Referring to the idea of neural network optimization [41], the control variance is obtained.(33)ΔS=λ⋅−∇J⋅ekeck,where λ is the learning rate and 0 < λ < 1.According to the results of equations (32) and (33), the control rules can be modified as(34)ΔOi=ΔS⋅μOiSi∑iμOiSi,Oi=Oi+ΔOi,where μOiSi is the degree of membership and ΔOi is the revision of the output.


## 3. Simulink-Based Design and Analysis of Simulation Platform

### 3.1. Simulink-Based Design of Simulation Platform for ACS

Figure2 shows a simulation platform of the ACS.Figure 2
Simulation platform of the ACS.The simulation platform mainly includes 10 unit modules. The specific design and implementation are as follows.


#### 3.1.1. 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.Figure 3
Attitude dynamics module.


#### 3.1.2. 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.Figure 4
Attitude kinematics module.


#### 3.1.3. Measurement System Module

The measurement system includes a gyroscope, an accelerometer, a magnetometer, and two GPS receivers. Therefore, the measurement system module includes four simulation modules. The 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.Figure 5
Gyroscope module.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. Therefore, the simulation module of the three-axis accelerometer is built as shown in Figure 6.Figure 6
Accelerometer module.Similarly, the simulation modules of the magnetometer are built as shown in Figure7. The simulation modules of the GPS are built as shown in Figure 8.Figure 7
Magnetometer module.Figure 8
GPS module.


#### 3.1.4. Attitude Angle Estimation Module

According to equations (5), (12), and (17)–(21), the simulation module of attitude angle estimation is built as shown in Figure 9.Figure 9
Attitude angle estimation modules.


#### 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.Figure 10
Feedback module.


#### 3.1.6. PID Controller Module

Figure11 shows the simulation module of the PID controller.Figure 11
PID controller modules.


#### 3.1.7. Actuator Module

The motor is selected as the actuator, and we can get [42](35)M=KmVLs+R,where V is the voltage; M is the torque; L is the inductance; Km 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.Figure 12
Actuator module.According to the above results, the simulation platform of the ACS can be shown in Figure13.Figure 13
Simulation platform of the ACS.


### 3.2. 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.The estimation results of the attitude angles are shown in Figure14. 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 14
The estimation curve of attitude angles. (a) The estimation curve ofφ. (b) The estimation curve of θ. (c) The estimation curve of ψ.
(a)(b)(c)Figure15 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.Figure 15
Comparison of control output of attitude angles. (a) The output curve ofφ. (b) The output curve of θ. (c) The output curve of ψ.
(a)(b)(c)


## 3.1. Simulink-Based Design of Simulation Platform for ACS

Figure2 shows a simulation platform of the ACS.Figure 2
Simulation platform of the ACS.The simulation platform mainly includes 10 unit modules. The specific design and implementation are as follows.


### 3.1.1. 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.Figure 3
Attitude dynamics module.


### 3.1.2. 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.Figure 4
Attitude kinematics module.


### 3.1.3. Measurement System Module

The measurement system includes a gyroscope, an accelerometer, a magnetometer, and two GPS receivers. Therefore, the measurement system module includes four simulation modules. The 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.Figure 5
Gyroscope module.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. Therefore, the simulation module of the three-axis accelerometer is built as shown in Figure 6.Figure 6
Accelerometer module.Similarly, the simulation modules of the magnetometer are built as shown in Figure7. The simulation modules of the GPS are built as shown in Figure 8.Figure 7
Magnetometer module.Figure 8
GPS module.


### 3.1.4. Attitude Angle Estimation Module

According to equations (5), (12), and (17)–(21), the simulation module of attitude angle estimation is built as shown in Figure 9.Figure 9
Attitude angle estimation modules.


### 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.Figure 10
Feedback module.


### 3.1.6. PID Controller Module

Figure11 shows the simulation module of the PID controller.Figure 11
PID controller modules.


### 3.1.7. Actuator Module

The motor is selected as the actuator, and we can get [42](35)M=KmVLs+R,where V is the voltage; M is the torque; L is the inductance; Km 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.Figure 12
Actuator module.According to the above results, the simulation platform of the ACS can be shown in Figure13.Figure 13
Simulation platform of the ACS.


## 3.1.1. 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.Figure 3
Attitude dynamics module.


## 3.1.2. 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.Figure 4
Attitude kinematics module.


## 3.1.3. Measurement System Module

The measurement system includes a gyroscope, an accelerometer, a magnetometer, and two GPS receivers. Therefore, the measurement system module includes four simulation modules. The 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.Figure 5
Gyroscope module.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. Therefore, the simulation module of the three-axis accelerometer is built as shown in Figure 6.Figure 6
Accelerometer module.Similarly, the simulation modules of the magnetometer are built as shown in Figure7. The simulation modules of the GPS are built as shown in Figure 8.Figure 7
Magnetometer module.Figure 8
GPS module.


## 3.1.4. Attitude Angle Estimation Module

According to equations (5), (12), and (17)–(21), the simulation module of attitude angle estimation is built as shown in Figure 9.Figure 9
Attitude angle estimation modules.


## 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.Figure 10
Feedback module.


## 3.1.6. PID Controller Module

Figure11 shows the simulation module of the PID controller.Figure 11
PID controller modules.


## 3.1.7. Actuator Module

The motor is selected as the actuator, and we can get [42](35)M=KmVLs+R,where V is the voltage; M is the torque; L is the inductance; Km 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.Figure 12
Actuator module.According to the above results, the simulation platform of the ACS can be shown in Figure13.Figure 13
Simulation platform of the ACS.


## 3.2. 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.The estimation results of the attitude angles are shown in Figure14. 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 14
The estimation curve of attitude angles. (a) The estimation curve ofφ. (b) The estimation curve of θ. (c) The estimation curve of ψ.
(a)(b)(c)Figure15 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.Figure 15
Comparison of control output of attitude angles. (a) The output curve ofφ. (b) The output curve of θ. (c) The output curve of ψ.
(a)(b)(c)


## 4. 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. The research results can resolve the contradiction between high precision and rapid stability of complex systems to a certain extent.



---

*Source: 1543949-2022-06-20.xml*