# Formation Control Technology of Fixed-Wing UAV Swarm Based on Distributed Ad Hoc Network
## 3 Waypoint-Based Formation-Switching Method
### Consensus-Based Waypoints Planning
#### 3.2.2 Flying to Formation Waypoint in Consistent Time  
Once the formation waypoints were obtained, only local waypoints from the current position of the UAV\({}_{i}\) to its formation waypoint needed to be designed so that the flight time of each UAV was equal. In this section, a distributed UAV swarm flying method based on time consistency is proposed, and local waypoints are designed under dynamic constraints to achieve UAV swarm formation switching when flying at a constant speed. 1. Dynamic constraints  
Maximum turning angle constraint: when the UAV turns according to the waypoint, the turning angle \(\beta\) (as shown in Figure 2) needs to be lower than the maximum turning angle \(\beta_{\max}\):  
\[\beta\leq\beta_{\max} \tag{8}\]  
Minimum route length constraint [28]: assuming that the UAV was flying under the available overload at the turn, the turning radius \(R\) was a fixed value. As shown in Figure 2,  
Figure 2: Dynamic constraints. the turning angle of the UAV in this section of the route was \(\beta\). For the UAV to make two consecutive turns, the route of this section needed to be lower than the minimum track length constraint \(d_{s}\):  
\[d_{s}=2\times R\times\tan\frac{\beta}{2} \tag{9}\]  
(2) Waypoint design  
When a UAV flev to formation waypoint, we first took the UAV that was going to fly the longest path as the time base, and then planned for other UAVs to fly around in the horizontal plane so that the final time to reach the formation waypoint was consistent. The longest path \(C_{\text{max}}\) is:  
\[C_{\text{max}}=\text{max}(C_{i})+d_{y} \tag{10}\]  
where \(d_{y}\) is the vertical flight distance margin to ensure that the vertical distance meets the constraint of the minimum route length \(d_{s}\). The turning angle of this method is a fixed value \(\beta=90^{\circ}\), so we set \(d_{y}=2\times d_{s}=4\times R\), \(C_{i}\) as the route distance that the UAV\({}_{i}\) needed to fly:  
\[C_{i}=\Delta x_{i}+\Delta y_{i}+\Delta t_{i}\times V \tag{11}\]  
where \(\Delta x_{i}\) and \(\Delta y_{i}\) are the horizontal distance and vertical distance of UAV\({}_{i}\) from the current position to the formation waypoint; \(V\) is the flight speed of the UAV; and \(\Delta t_{i}\) is the waiting time of UAV\({}_{i}\), which can be selected according to the actual project. If it was a formation switch scenario, \(\Delta t_{i}=0\). If it was a formation assembly scenario, \(\Delta t_{i}\) was the launch interval of UAV\({}_{i}\) from the first UAV. The dynamic constraints of the flight plan needed to consider the maximum turning angle constraint and the minimum route length constraint. The flight project was divided into the following sections:  
As shown in Figure 3, the flight project was composed of four right-angle turning sections. The solid line is the planned route, which was sections 1, 2, 3, 4, and 5. The dashed line is the actual flight route considering the UAV turning process. The solid point is the UAV waypoint. To make the flying distance the same, the length of the distances of 1, 2, 3, 4, and 5 were designed as:  
\[\left\{ \begin{array}{l}L_{1x,i}=L_{5x,i}=r\\ L_{3x,i}=\Delta x_{i}-4\times r\\ L_{2y,i}=L_{4y,i}=\frac{C_{\text{max}}-\Delta x_{i}-\Delta y_{i}}{2}\end{array} \right. \tag{12}\]  
Figure 3: Dynamic constraints. where \(L_{1x,i}\), \(L_{3x,i}\), and \(L_{5x,i}\) are the horizontal distances of UAV\({}_{\rm i}\) in segments 1, 2, 3, 4; and \(L_{2y,i}\), \(L_{4y,i}\) are the vertical distances of UAV\({}_{\rm i}\) in segments 2 and 4, respectively. The local waypoints of the UAV\({}_{\rm i}\) could be calculated according to the starting waypoint and the distance lengths of 1, 2, 3, 4, and 5:  
\[\left\{ \begin{array}{ll}P_{\rm 1}(x_{1},y_{1})=P_{\rm 0}(x_{\rm i0}+L_{1x,i},y_{ \rm i0})\\ P_{\rm 2}(x_{\rm i2},y_{\rm i2})=P_{\rm 1}(x_{\rm i1},y_{\rm i1}+L_{2y,i})\\ P_{\rm 3}(x_{\rm i3},y_{\rm i3})=P_{\rm 2}(x_{\rm i2}+L_{3x,i},y_{\rm i2})\\ P_{\rm 4}(x_{\rm i4},y_{\rm i4})=P_{\rm 3}(x_{\rm i3},y_{\rm i3}-L_{4y,i})\\ \end{array} \right.