## 3 Nonlinear Dynamic Inversion Control Law
### Outer Slow Loop  
The outer slow loop dynamic states \((\alpha,\ \beta,\ \phi)\) are controlled by the most inner loop states \((p,\ q,\ r)\). The outer slow loop control laws are designed based on performing the slow response of the outer loop by exciting the fast dynamic loop. A fast-transient response is assumed so that they have a negligible effect on the slow states. The differential equations governing the variation in time of the controlled variables \(\alpha,\ \beta,\) and \(\phi\) are obtained by differentiation of the aerodynamic angles given in Equations (13) and (14) and the Tiger-Trainer UAV attitude equation given in [21], respectively.  
\[\alpha =atan2(w,u) \tag{13}\] \[\beta =atan2(v,V_{a}) \tag{14}\]  
where the body fixed velocity components are \((u,\ v,\ w)\), and \(V_{a}\) is the UAV airspeed. The equations relating the derivatives of the aerodynamic angles with the angular rates \((p,\ q,\ r)\) are given in Equations (15)-(17).  
\[\dot{\alpha} =q-(p\cos\alpha+r\sin\alpha)\tan\beta+\frac{Z\cos\alpha-(X+T) \sin\alpha+F_{\alpha\beta_{b}}}{mV_{a}\cos\beta} \tag{15}\] \[\dot{\beta} =p\sin\alpha-r\cos\alpha+\frac{Y-T\cos\alpha\sin\beta+F_{\beta \beta_{b}}}{mV_{a}}\] (16) \[\dot{\phi} =p+q\tan\theta\sin\phi+r\tan\theta\cos\phi \tag{17}\]  
where \(T\) is the engine thrust, \(X,\ Y,\ Z\) are the aerodynamic forces in body axes, \(m\) is the UAV mass, and \(F_{\alpha\beta_{b}},\ F_{\beta\beta_{b}}\) are the gravitational forces in body axes. Applying NLDI to the attitude Equations (15)-(17) results in an expression for the desired angular rates \([p_{c},\ q_{c},\ r_{c}]^{T}\) as given in Equation (18), which is the desired input for the most inner loop.  
\[\begin{bmatrix}p_{c}\\ q_{c}\\ r_{c}\end{bmatrix}=g^{-1}\left(\begin{bmatrix}v_{\alpha}\\ v_{\beta}\\ v_{\phi}\end{bmatrix}-\begin{bmatrix}F_{\alpha}\\ F_{\beta}\\ 0\end{bmatrix}\right) \tag{18}\]  
where \(g\) is a square matrix given in Equation (19) that relates the required angular rates \(p_{c},\ q_{c}r_{c}\) with the desired attitudes rate. \(v_{\alpha},v_{\beta},v_{\phi}\) are the designed control laws for \((\alpha,\ \beta,\ \phi)\) and are given in Equations (20)-(22).  
\[g=\begin{pmatrix}-\cos\alpha\tan\beta&1&-\sin\alpha\tan\beta\\ \sin\alpha&0&-\cos\alpha\\ 1&\tan\theta\sin\phi&\tan\theta\cos\phi\end{pmatrix} \tag{19}\]  
\[v_{\alpha} =\dot{u}_{c}-K_{\alpha}(\alpha-\alpha_{c}) \tag{20}\] \[v_{\beta} =\dot{p}_{c}-K_{\beta}(\beta-\beta_{c})\] (21) \[v_{\phi} =\dot{\phi}_{c}-K_{\phi}(\phi-\phi_{c}) \tag{22}\]  
where \((\alpha_{c},\ \beta_{c},\ \phi_{c})\) are the desired attitude angles with their derivatives \((\dot{\alpha}_{c},\ \dot{\beta}_{c},\ \dot{\phi}_{c})\), and \((K_{\alpha},\ K_{\beta},\ K_{\phi})\) are constant positive gains set to be 10 [Hz] to ensure the avoidance of coupling between the outer loop and the inner loop. The designed control law guarantees the global asymptotic stability of the system, i.e., the error difference between the desired attitude angle and the actual one will exponentially decay to zero for any initial conditions. Assuming the errors are \((\epsilon_{\alpha}=\alpha-\alpha_{c},\epsilon_{\beta}=\beta-\beta_{c},\epsilon _{\phi}=\phi-\phi_{c})\), then from Equations (20)-(22), the error vector is given in Equations (23)-(25).  
\[\dot{e}_{\alpha}+K_{\alpha}e_{\alpha} =0 \tag{23}\] \[\dot{e}_{\beta}+K_{\beta}e_{\beta} =0\] (24) \[\dot{e}_{\phi}+K_{\phi}e_{\phi} =0 \tag{25}\]  
As soon as the two control loops are designed with the desired inputs \((\alpha_{c},\ \beta_{c},\ \phi_{c})\) and the required control surfaces commands \((\delta_{\alpha},\delta_{\alpha},\delta_{\gamma})\), the flight control system is ready to track the desired trajectory. Therefore, the guidance law will be applied as a desired input for the outer dynamics control loop.