## 3 Flight Controller Design
### Attitude Controller Design  
The purpose of the attitude controller is to the derive the virtual torque \(\Gamma=[R,P,Y]^{T}\) from the desired attitude, which is given as \(\Theta_{r}=[\phi_{r},\theta_{r},\psi_{r}]^{T}\). To achieve stable and robust control, a SMC approach based on disturbance observer that we have proposed before [32] is used to calculate the control law for the attitude control subsystem. In this method, the SMC part is to produce a robust control law and the disturbance observer is adopted to deal with the modeling errors and the external disturbances. Based on (14), the attitude control subsystem can be rewritten as follows [33],  
\[J(\Theta)\ddot{\Theta}=-C(\Theta,\dot{\Theta})\dot{\Theta}+\Gamma+d_{\Gamma}+ \triangle_{p} \tag{36}\]  
\[J(\Theta)= \begin{bmatrix}I_{xx}&0&-I_{xx}s\theta\\ 0&I_{yy}c^{2}\phi+I_{zz}s^{2}\phi&(I_{yy}-I_{zz})c\phi s\phi c\theta\\ -I_{xx}s\theta&(I_{yy}-I_{zz})c\phi s\phi c\theta&I_{xx}s^{2}\theta+I_{yy}s^{2} \phi c^{2}\theta+I_{zz}c^{2}\phi c^{2}\theta\end{bmatrix}  \tag{37}\]  
where \(\Theta=[\phi,\theta,\psi]^{T}\) is the actual attitude; \(J(\Theta)\) denotes the inertia matrix; \(C(\Theta,\dot{\Theta})\) denotes the Coriolis matrix; and \(d_{\Gamma}\) and \(\triangle_{p}\) represent the external disturbances and the modeling errors, respectively. \(c\cdot\) and \(s\cdot\) are symbolize cosine and sine function respectively. Generally, the pitch angle satisfies \(\theta\in(-\dfrac{\pi}{2},\dfrac{\pi}{2})\), so \(J(\Theta)\) is an invertible and positive definite symmetric matrix. Define the error vector as \(x_{1}=\Theta_{r}-\Theta\), \(x_{2}=\dot{\Theta}_{r}-\dot{\Theta}\). Then, we can obtain the attitude error system as  
\[\begin{cases}\  
To achieve accurate estimation of \(D\), the nonlinear disturbance observer is designed as follows,  
\[ \begin{cases}d_{e}=-\frac{\partial\beta}{x_{1}}x_{2}-\frac{\partial\beta}{x_{2}} J(\Theta)^{-1}[J(\Theta)\dot{\Theta}_{r}-(\Gamma+\hat{D}-C(\Theta,\dot{\Theta}) \dot{\Theta})]\\ \beta(x_{1},x_{2})=-k_{2}x_{2}\end{cases}  \tag{40}\]  
where \(k_{2}\) is a positive constant that related to the convergence speed of the disturbance estimation. Assume that the disturbance \(D\) is a slow time-varying variable compared to the state of the system, so that the derivative of \(D\) can be omitted. Then, we can get  
\[ \begin{split}\dot{e}&=d_{e}+\dot{\beta}(x_{1},x_{2}) \\ &=-k_{2}J(\Theta)^{-1}e\end{split}  \tag{41}\]  
As \(J(\Theta)^{-1}\) is a positive definite symmetric matrix and \(k_{2}\) is a positive constant, \(-k_{2}J(\Theta)^{-1}\) is Hurwitz. If \(k_{2}\) is appropriately chosen, certain disturbance estimation accuracy can be guaranteed. If the actual disturbance is a constant, \(e\) converges to 0. If it is a variable, the estimation error exists and satisfies  
\[|e|\leq D_{e}^{*}=\underset{t>0}{sup}|d_{2}+\beta(x_{1},x_{2})-D| \tag{42}\]  
Based on the designed disturbance observer above, the following part is to develop the sliding mode controller based on the disturbance observer, such that the chattering is alleviated and the robustness can be improved without sacrificing nominal control performance. To achieve stable control for the attitude subsystem (38), the control law based on SMC approach can be designed as follows [32],  
\[\Gamma=C(\Theta,\dot{\Theta})\dot{\Theta}+J(\Theta)\dot{\Theta}_{r}+J(\Theta) k_{a}(\dot{\Theta}_{r}-\Theta)+c_{a}s_{a}+\varepsilon_{a}\operatorname{sgn}(s_{a})-\hat{D} \tag{43}\]  
where \(k_{a}\) and \(c_{a}\) are positive constants, \(\varepsilon_{a}>D_{e}^{*}\), and the sliding manifold is \(s_{a}=k_{a}x_{1}+x_{2}\). Proof. : The derivative of the sliding mode surface \(s_{a}\) can be written as  
\[ \begin{split}\dot{s}_{a}&=k_{a}\dot{x}_{1}+\dot{x}_ {2}\\ &=k_{a}x_{2}+J(\Theta)^{-1}[J(\Theta)\dot{\Theta}_{r}-(\Gamma+D- C(\Theta,\dot{\Theta})\dot{\Theta})]\end{split}