# An Evolutionary Algorithm to Optimise a Distributed UAV Swarm Formation System
## 3 Distributed Formation Algorithm3 (DFA3)  
The proposed 3D formation system is focused on a swarm of autonomous flying robots (UAVs), surrounding and escorting a rogue drone out of a restricted area, e.g., an airport, while they conserve a predefined desired distance to the formation centre (Figure 1a). This is a challenging real-world problem, as achieving stable robot formation systems involves addressing different constraints, such as limited communication range, absence of absolute positions, and uncertain initial conditions. Each UAV in the swarm receives a beacon signal emitted by each of the other UAVs in the swarm and uses it to calculate its relative orientation and distance to the rest of the UAVs. Given the simplicity of the communications, no protocol is necessary, nor was it implemented. Moreover, no localisation system, such as GPS, is used by the UAVs. Additionally, the UAVs do not have a predefined final position in the formation. The rogue drone is tracked by using its own radio signal in our experiments, although other methods can be used, such as images from cameras, LIDAR data, etc. The 3D formation is collaboratively built by the UAVs arriving to the area from different positions. They use a series of attracting and repelling forces calculated from the received beacons, to find their final position in the surface of a virtual sphere around the  
Figure 1: A 2D representation of the 3D formation system. (**a**) Swarm of five drones escorting the rogue drone. (**b**) Attracting/repelling forces between each drone in the swarm and the rogue drone. (**c**) Attracting/repelling forces between drones. rogue drone. Depending on the number of UAVs, the final shape would be more or less effective as a dissuasive measure. The swarm members are spread by such a virtual sphere to improve their distribution, avoiding being too close each other. Hence, having a reduced number of UAVs could leave too much open space from where the rogue drone might escape. Two types of forces are considered: (i) between each UAV and the rogue drone and (ii) between the UAVs in the swarm (Figure 1b,c). The formation problem is defined by  
\[P=(\mathcal{G},rd,S,C), \tag{1}\]  
where the distance graph is given by  
\[\mathcal{G}=(V,E,D), \tag{2}\]  
where \(V=\{UAV_{1},\ldots,UAV_{N}\}\) represents the UAVs in the swarm, \(E=\{(i,j)\in V\times V\}\) represents the edges of the graph indicating the swarm connectivity, and \(D=\{d(i,j),\forall(i,j)\in E\}\) represents the distances between UAVs (\(D_{UAV}\)). Furthermore, \(rd\) stands for the rogue drone, the distances between the UAVs and the rogue drone are given by  
\[S=\{d(rd,u),u\in V\}, \tag{3}\]  
and the problem's constraints are given by  
\[C=\forall d(rd,j)\in S,d(rd,j)=D_{RD}, \tag{4}\]  
where \(D_{RD}\) is the desired distance to the rogue drone (formation radius). We propose four parameters for the swarm members in order to achieve stable formations: a distance threshold \(D_{th}\) to control the attracting/repelling movement between UAVs, the minimum distance \(D_{min}\) to the rogue drone, the intensity of the attracting/repelling force \(F_{RD}\), with respect to the rogue drone, and the moving speed \(Spd\) of the UAVs. The pseudocode of our distributed formation algorithm3 (DFA3) is detailed in Algorithm 1. Each UAV executes the same algorithm with its own parameters, and the same predefined formation radius, i.e., the desired distance to the rogue drone \(D_{RD}\), which is a constant value. The DFA3 first initialises the vector \(r\) where the calculation of the resulting attracting/repelling force to/from the rogue drone plus the other UAVs will be stored. Then, for each beacon received, the range and the vertical and horizontal bearings from the other robots are obtained and used to calculate the three components of \(r\), according to the given distance threshold \(D_{th}\). After that, the same calculation is performed with respect to the rogue drone.