## 7 Simulation Results
### Software-in-the-Loop Simulation  
This section showcases the efficacy of the control design via realistic software-in-the-loop (SITL) simulations. The controller is implemented in the ArduPilot [43] open-source autopilot framework for fixed-wing UAVs. We simulate our code using ArduPilot's SITL framework, using the JSBSim flight dynamics engine with a model of a SIG Rascal 110.  
Roll and pitch reference angles are provided by ArduPilot's guidance system. Lateral guidance is performed using a nonlinear guidance law [14; 15], often called \(L1\) guidance, by commanding a lateral acceleration \(a_{scand}\) using  
\[a_{scand}=K_{L_{1}}\frac{V_{g}^{2}}{L_{1}}\sin(\varphi), \tag{50}\]  
where \(V_{g}\) is the ground speed of the UAV, \(L_{1}\) is the distance to a reference point on the desired path, ahead of the UAV, \(K_{L_{1}}\) is a tuning parameter, and \(\varphi\) is the angle between the ground speed vector and the \(L_{1}\) vector pointing from the UAV to the reference point on the path. The desired lateral acceleration is then converted into a desired roll angle \(\phi_{d}\) using a simplified version of the coordinated turn equation:  
\[\phi_{d}=\cos(\theta)\operatorname{atan}\left(\frac{a_{scand}}{g}\right). \tag{51}\]  
The pitch angle reference is calculated using the total energy control system (TECS) [91]. TECS is based on energy principles, and accounts for dynamic coupling in the longitudinal dynamics of the aircraft by simultaneously controlling altitude and airspeed using pitch and throttle. The pitch angle is used to control the energy distribution \(E_{D}\), i.e., the difference between (specific/per mass) potential and kinetic energy, given by  
\[E_{D}=gh-\frac{1}{2}V_{a}^{2}, \tag{52}\]  
where \(h\) is the altitude. For a desired altitude \(h_{d}\in\mathbb{R}\) and desired airspeed \(V_{a,d}\in\mathbb{R}_{+}\), define the desired specific energy distribution \(E_{D,d}=gh_{d}-V_{a,d}^{2}/2\) and the error \(\tilde{E}_{D}=E_{D,d}-E_{D}\). Then, the pitch reference is prescribed as follows:  
\[\theta_{d}=k_{1}\tilde{E}_{D}+k_{2}\int_{0}^{t}\tilde{E}_{D}d\tau+k_{3}\hat{E }_{D}+k_{4}\hat{E}_{D,d}, \tag{53}\]  
where \(k_{i}\in\mathbb{R}_{+}\), \(i=1\ldots 4\) are tuning gains.  
Figures 11-14 shows the results of a simulation run of the adaptive backstepping controller (40). As the derivatives of the reduced-attitude reference are not available in the ArduPilot code, we use a version of (40) where no information about the angular velocity reference is used in the feedforward part of the controller. In addition, up to 20 percent uncertainty is added to all elements of the matrices \(J,B\) and \(D\). This makes the controller more akin to (45), but with added integral action. The controller parameters are set to \(\kappa=2,k_{1}=10,K_{2}=\operatorname{diag}(5,7,5)\) and \(K_{3}=\operatorname{diag}(0.1,0.25,0.1)\).  
The simulated UAV is tasked with following a square pattern, shown in Figure 11. The actual horizontal position and altitude are shown, from takeoff and until a few rounds have been completed. It is clear that the proposed reduced-attitude controller successfully integrates into the ArduPilot infrastructure. Roll and pitch responses are shown in Figure 12, while Figure 13 shows the vector coordinates \(\eta\). The UAV tracks the reference well, except when there are large steps in roll angle going into a turn. This is where a feedforward from the angular velocity reference could help reduce the errors. Anyhow, the errors are relatively small and do not interfere with the overall control objective. Figure 11 shows that the altitude is kept approximately constant at 100 m, with only minor drops in altitude during sharp turns. The control input is shown in Figure 14. Except for some large