# Three-Dimensional Obstacle Avoidance Strategy for Fixed-Wing UAVs Based on Quaternion Method
## 6 Simulation  
We performed a numerical simulation on a laptop to verify the effectiveness of the three-dimensional obstacle avoidance guidance algorithm proposed above. The laptop ran Windows 10 Professional 64-bit with an AMD Ryzen 7 4800H with Radeon Graphics CPU (2.9 GHz) and 16 GB RAM. All simulations were developed in the MATLAB 2020b environment. The parameters of the UAV, collision avoidance algorithm, and control system are summarized in Table 1. The initial states of the obstacle are set as \(\mathbf{p}_{OBS}^{n}(0)=\left[ \begin{array}{cccc}984.4&1396.43&390.1\end{array}  \right]^{\mathsf{T}}\), and \(\mathbf{v}_{OBS}=\left[ \begin{array}{cccc}0&-40&0\end{array} \right]^{\mathsf{T}}\). The deflection angle is constrained in the range of \(\pm 15^{\circ}\), and the maximum thrust of the engine is limited to 250 N.  
Figure 9 a shows the trajectory of the UAV and the obstacle in the inertial coordinate system. The solid line represents the flight trajectory of the UAV. It can be seen from Figure 9a that the controller of the UAV leads to a smooth and continuous trajectory. Dashed and dotted lines respectively represent the moving target and the UAV in a non-avoidance mode. They intersect at a collision point (\(t=23.8\) s), indicating that if the avoidance maneuver is not performed, a collision will occur at that time. Figure 9b shows the change of the distance between the UAV and the moving obstacle over time, and the minimum distance between the UAV and the moving obstacle is greater than \(r_{ps}\) as expected. It took 41.35 s to complete the task. \begin{table}
\begin{tabular}{c c c c} \hline \hline \multicolumn{2}{c}{**Fixed-Wing UAV**} & \multicolumn{2}{c}{**3D-VO Collision Avoidance**} & \multicolumn{2}{c}{**Control System**} \\ \hline \(m=20.64\) kg & \(\mathbf{p}_{UAV}^{n}(0)=\left[\begin{array}{cccc}0&-100\end{array}\right]^{ \mathsf{T}}\) & \(r_{ps}=100\) m & \(d_{suff}=500\) m & \(k_{1}=2\) & \(k_{2}=2\) \\ \(\mathbf{v}_{UAV}^{n}(0)=\left[\begin{array}{cccc}30&0&0\end{array}\right]^{ \mathsf{T}}\) & \(\mathbf{q}_{ss}(0)=\left[\begin{array}{cccc}1&0&0\end{array}\right]^{\mathsf{T}}\) & \(\lambda^{*}=90^{\circ}\) & \(\gamma_{d}=40\) m/s & \(\kappa_{1}=2\) & \(\kappa_{2}=2\) \\ \(\mathbf{w}_{ab}^{n}(0)=\left[\begin{array}{cccc}0&0\end{array}\right]^{ \mathsf{T}}\) & \(\mathbf{p}_{d}^{2}=\left[\begin{array}{cccc}20&10&10\end{array}\right]^{ \mathsf{T}}\) * \(10^{3}\) & \(\mathbf{n}_{\text{max}}=90^{\circ}\) & \(\tau=0.5\) s & \(K_{\
u}=2\)/l & \(\Lambda=5\) m \\ \hline \hline \end{tabular} Simulation 1: Use the algorithm that updates the avoidance plane in real time.  
\end{table} 
Table 1: Parameters of the fixed-wing UAV, collision avoidance and control system. Figure 10 shows the control input of the rotation loop and the translation loop, the velocity, the angular velocity, and the attitude information of the UAV. Figure 10c shows that the thrust engine is started in the initial stage (\(t\) = 0-2.1 s), pushing the UAV to a predetermined velocity. As shown in Figure 10d,e during the period (\(t\) = 0-17.2 s), the quaternion \(\mathbf{q}_{\text{ds}}^{*}\) representing the error between the \(d\)-frame and the \(s\)-frame gradually converges to zero, indicating that the UAV can be directed toward the destination point. When an obstacle is detected and Equation (15) is satisfied, signal Y becomes 1 and the controller continuously controls the UAV keeps a certain safety distance with the obstacle, as in Figure 10a,b. In Figure 10f, the dotted, dashed, and solid lines represent \(\mathbf{v}_{av_{\text{0}x}}\), \(\mathbf{v}_{av_{\text{0}x}}\) and \(\mathbf{v}_{av_{\text{0}z}}\), respectively. In the avoidance mode (\(t\) = 17.2-18.8 s), \(\mathbf{v}_{av_{\text{0}z}}\) increases, \(\mathbf{v}_{av_{\text{0}x}}\) as well as \(\mathbf{v}_{av_{\text{0}z}}\) decrease, and the thrust remains at 0, indicating that the UAV has only changed the direction of the velocity. Due to the avoidance maneuver, the attitude of the UAV changes drastically.