# LoRaWAN Networking in Mobile Scenarios Using a WiFi Mesh of UAV Gateways
## 3 The LoRaUAV System
### VSF Mobility Algorithm  
LoRaUAV implements a force-based distributed mobility algorithm that can push or pull an UAV closer or further from other UAVs or GNs. In this way, UAVs are kept within communication range of each other, collisions are avoided and the objective of covering the GNs is pursued. The implemented VSF algorithm is an adapted version of the algorithm described by [PERSON] et al. in [4]. Modifications affect the weights of AtA and AtG forces. The algorithm runs at fixed regular intervals \(\Delta T\). At each time step, each UAV generates a set of virtual springs, having one end attached to the UAV that generated them, and the other end attached to either a GN (AtG spring) or another UAV (AtA spring). For each spring, the force \(F_{ij}\) between node \(i\) and node \(j\) is calculated as follows:  
\[\overrightarrow{F_{ij}}=K\cdot(LB_{ij}-LB_{req})\overrightarrow{x}, \tag{6}\]  
where \(K\) is a proportionality factor, \(LB_{ij}\) is the real or estimated link budget between node \(i\) and node \(j\), and \(LB_{req}\) is the required link budget. Link budget measurements give a better indication of the quality of the link and allow to better select the parameters according to application-specific QoS requirements. The total force \(F_{tot}^{i}\) applied to UAV \(i\) is:  
\[\overrightarrow{F_{tot}^{i}}=\sum_{j=0}^{N}\overrightarrow{F_{ij}}, \tag{7}\]  
where \(N\) is the number of springs originating from UAV \(i\). AtG springs are established with all the GNs that have sent to the UAV at least one update in the last \(t_{AtG}\) seconds. AtA springs, instead, are established with any one-hop neighboring UAV. AtA and AtG springs are only established with direct neighbors, thus lowering the computations and the complexity of the interactions. The \(K\) parameter is fundamental to determine the weight and priority of each spring force \(F_{ij}\). For AtA springs, \(K\) is updated according to the following expression:  
\[K_{AtA}=K_{p}\left(\frac{N_{neighs}^{max}}{n_{neighs}}\right), \tag{8}\]  
where \(K_{p}>0\) is a scaling factor, \(N_{neighs}^{max}\) is the maximum expected number of neighboring UAVs and \(n_{neighs}\) is the current number of neighboring UAVs. Equation (8) allows to scale the magnitude of the AtA forces on the basis of the relative number of neighboring UAVs. In this way, UAVs with few neighbors have a higher tendency to stick to the formation, while UAVs with many neighbors exhibit the opposite behavior, therefore assigning more relevance to AtG springs. A good value of \(N_{neighs}^{max}\) typically resides in the interval \([6,8]\), since UAVs tend to arrange themselves in hexagonal grid formations when subject only to AtA forces. If the number of drones is small, \(N_{neighs}^{max}\) can be approximated with the total number of UAVs. The \(K\) parameter takes a different value at each time step for each AtG spring attached to GN \(j\):  
\[K_{AtG}^{j}=\frac{u_{max}}{u_{j}}, \tag{9}\]where \(u_{max}\) is the highest number of neighboring UAVs sharing one or more covered GNs and \(u_{j}\) is the current number of UAVs covering GN \(j\). This relation gives more priority to the GNs that are covered by less UAVs, and drones are therefore expected to distribute themselves uniformly between the GNs that are in range.