## 3 Flight Control
### Attitude Controller  
Stable attitude control is the essential precondition for position control. From Equation (1), the attitude dynamics can be described by the following equation:  
\[\left\{ \begin{array}{l}\dot{\mathbf{\eta}}_{1}=\eta_{2}\\ \dot{\mathbf{\eta}}_{2}=J^{-1}(\mathbf{\tau}+\mathbf{\tau}_{0}-\mathbf{\omega}\times\mathbf{J}\mathbf{ \omega})\end{array} \right. \tag{11}\]  
where, we define the attitude angle of the vehicle as \(\mathbf{\eta}=\left[\phi,\theta,\psi\right]^{T}\). \(\phi\), \(\theta\), and \(\psi\) are defined as the roll, pitch, and yaw angle, respectively. Then \(\mathbf{\eta}_{2}=\left[\dot{\phi},\dot{\theta},\dot{\psi}\right]^{T}\) are define as the angular velocity of the vehicle. The tracking error associated with the dynamics of the FMAV can be represented by  
\[\delta_{1}=\mathbf{\eta}_{1d}-\mathbf{\eta}_{1} \tag{12}\] \[\delta_{2}=\mathbf{\eta}_{2d}-\mathbf{\eta}_{2}\]  
where, \(\mathbf{\eta}_{2d}\) is the desired angular velocity of the FMAV. Let us consider the candidate Lyapunov function \(\mathbf{V}_{1}\) as follow:  
\[V_{1}=\frac{1}{2}\mathbf{\delta_{1}}^{T}\mathbf{A_{1}}\mathbf{\delta_{1}} \tag{13}\]  
where \(\mathbf{A_{1}}\in\mathbf{R}^{3\times 3}\) is a positive diagonal matrix, and the derivative of this Lyapunov function \(\dot{V}_{1}\) is defined by  
\[\dot{V}_{1}=\mathbf{\delta_{1}}^{T}\mathbf{A_{1}}\mathbf{\delta_{1}}=\delta_{1}^{T}\mathbf{A_{ 1}}(\dot{\mathbf{\eta}}_{1d}-\dot{\mathbf{\eta}}_{1})=\delta_{1}^{T}\mathbf{A_{1}}(\dot\mathbf{{\eta}}_{1d}-\mathbf{\eta}_{2}) \tag{14}\]  
We define the desired angular velocity \(\mathbf{\eta}_{2d}\) as:  
\[\mathbf{\eta}_{2d}=\dot{\mathbf{\eta}}_{1d}+\mathbf{A_{2}}\delta_{1} \tag{15}\]  
where \(\mathbf{A_{2}}\in\mathbf{R}^{3\times 3}\) is a positive diagonal matrix. If the angular velocity \(\mathbf{\eta}_{2}\) equals the desired angular velocity \(\mathbf{\eta}_{2d}\), the \(\dot{V}_{1}\) in Equation (14) can be rewritten as follows:  
\[\dot{V}_{1}=-\delta_{1}^{T}\mathbf{A_{1}}\mathbf{\delta}_{1}<0,\forall\delta_{1}\
eq 0 \tag{16}\]  
According to the Invariant set theorem, the derivative of the Lyapunov function \(\dot{V}_{1}\) is negative. That is to say, \(\delta_{1}\) will converge to 0 asymptotically. In attitude control, we take the body's moment of inertia and bias torque as adaptive estimators. Then, the candidate Lyapunov function \(\mathbf{V}_{2}\) is designed as follows:  
\[V_{2}=\frac{1}{2}\delta_{1}^{T}\mathbf{A_{1}}\delta_{1}+\frac{1}{2}\delta_{2}^{T} \mathbf{J}\delta_{2}+\frac{1}{2}\tilde{\mathbf{\kappa}}^{T}\mathbf{\Gamma}\tilde{\mathbf{ \kappa}} \tag{17}\]  
where, \(\mathbf{J}\) is the actual inertia matrix. The adaptive model parameter is defined as \(\tilde{\mathbf{\kappa}}=\left[ \begin{array}{cccc}\hat{J}_{xx}&\hat{J}_{yy}&\hat{J }_{zz}&\hat{\tau}_{0x}&\hat{\tau}_{0y}&\hat{\tau}_{0z}\end{array} \right]^{T}\). \(\hat{J}_{xx}\), \(\hat{J}_{yy}\), and \(\hat{J}_{zz}\) are the components of the estimated moment of inertia in the \(x\), \(y\), and \(z\)-axis, respectively. \(\hat{\tau}_{0x}\), \(\hat{\tau}_{0y}\), and \(\hat{\tau}_{0z}\) are the components of the estimated bias torque in the \(x\), \(y\), and \(z\)-axis directions, respectively. \(\tilde{\mathbf{\kappa}}\) is the estimation error defined as \(\tilde{\mathbf{\kappa}}=\mathbf{\alpha}-\tilde{\mathbf{\kappa}}\). \(\mathbf{\Gamma}\) is a positive diagonal gain matrix.