## 3 Nonlinear Dynamic Inversion Control Law
### Inner Fast Loop  
The most inner fast loop dynamic states \((p,\ q,\ r)\) are controlled by the control surfaces commands \((\delta_{a},\delta_{e},\delta_{r})\). The angular rate dynamic inversion is derived from the moment in Equation (4) of the Tiger-Trainer (a small commercial off-the-shelf Radio-Controlled) airplane model is given in [21] by solving for the control surface commands.  
\[\mathbf{I}_{B}\dot{\vec{\omega}}_{B}=\vec{\omega}_{B}\times\mathbf{I}_{B}\vec {\omega}_{B}+\vec{M}_{B} \tag{4}\]  
where the body fixed rotational rates \(\stackrel{{\rightarrow}}{{\omega}}_{B}=[p,\ q,\ r]^{T}\), and \(\mathbf{I}_{B}=[I_{x},\ I_{y},\ I_{z},\ I_{xz}]^{T}\) is the moment of inertia matrix. The total body coordinate system's moments \(\stackrel{{\rightarrow}}{{M}}_{B}=[l,\ m,\ n]^{T}\) are composed partially by moments generated by the aerodynamics of the air-frame \(M_{a}\) and partially by moments generated by the control surface deflections \(M_{c}\). The moment equation is given in Equation (5).  
\[\mathbf{I}_{B}\dot{\vec{\omega}}_{B}=\vec{\omega}_{B}\times\mathbf{I}_{B}\vec {\omega}_{B}+\vec{M}_{a}+\vec{M}_{c}\delta \tag{5}\]  
Applying NLDI to Equation (5) results in an expression for the control surface deflections \(u=[\delta_{a},\delta_{e},\delta_{r}]^{T}\), which is given in Equation (6).  
\[[\delta_{a},\delta_{e},\delta_{r}]^{T}=\vec{M}_{c}^{-1}\left[\mathbf{I}_{B} \
u-\vec{\omega}_{B}\times\mathbf{I}_{B}\vec{\omega}_{B}-\vec{M}_{a}\right] \tag{6}\]  
Figure 3: Two-timescale dynamic inversion controller.  
where \(\
u=[\
u_{p},\
u_{q},\
u_{r}]^{T}\) are the designed control laws for roll, pitch, and yaw angular rates, respectively, given in Equations (7)-(9).  
\[\
u_{p} =\dot{p}_{c}-K_{p}(p-p_{c}) \tag{7}\] \[\
u_{q} =\dot{q}_{c}-K_{q}(q-q_{c})\] (8) \[\
u_{r} =\dot{r}_{c}-K_{r}(r-r_{c}) \tag{9}\]  
where \((p_{c},\ q_{c},\ r_{c})\) are the desired angular rates with their derivatives \((\dot{p}_{c},\ \dot{q}_{c},\ \dot{r}_{c})\), and \((K_{p},\ K_{q},\ K_{r})\) are constant positive gains represent the bandwidth frequencies of the control signals in the roll, pitch, and yaw channels, respectively. The gains are set as high as possible without exciting structural modes or being subjected to the bandwidth limitations of the control actuators. The designed control law guarantees the global asymptotic stability of the system i.e., the error difference between the desired angular rate and the actual one will exponentially decay to zero for any initial conditions. Assuming the error \((e_{p}=p-p_{c},\ e_{q}=q-q_{c},\ e_{r}=r-r_{c})\), then from Equations (7)-(9), the error vector is given in Equations (10)-(12)  
\[\dot{e}_{p}+K_{p}e_{p} =0 \tag{10}\] \[\dot{e}_{q}+K_{q}e_{q} =0\] (11) \[\dot{e}_{r}+K_{r}e_{r} =0 \tag{12}\]  
The frequencies of the roll, pitch, and yaw channels are set to \((K_{p}=K_{q}=K_{r}=50\ \mathrm{Hz})\) to ensure the avoidance of coupling between the inner loop and the outer loop. Continuously increasing the frequencies will increase the rate of error decaying, which considering the channel's frequencies rise, will result in the higher coupling effect in the lateral plane between the roll and yaw states.