# Devising Mobile Sensing and Actuation Infrastructure with Drones
## 2 Designing DaaG
### Main Functions of DaaG
#### 2.3.3 Path Planning  
Assume that DaaG knows the position of sensors and actuations, \(pos_{i}=\left(x_{i},y_{i}\right)\) for \(\forall i\in V\), where undirected graph \(G=\left(V,E\right)\), \(V\) is a set of nodes and \(E\) is a set of edges. First, DaaG calculates the edge weight for all links in the \(E\) as follows:  
\[w_{ij}=\sqrt{\left(x_{i}-x_{j}\right)^{2}+\left(y_{i}-y_{j}\right)^{2}}\text{,} \tag{3}\]  
for \(\forall i,j\in S\) where \(S\subset V\) is a set of sensors. To gather the data from the sensors, the position error of the sensor should not be larger than the communication range, in our case, about 10 m.  
Then, DaaG runs a path-planning algorithm, which is described in Algorithm 2. In the path-planning algorithm, the beaconing algorithm is used to collect the sensor data. The purpose of DaaG is to retrieve the sensor data in the sensor network, which is similar to the traveling salesman problem with neighborhoods (TSPN) [24] and close enough traveling salesman problem (CETSP) [25]. Therefore, it does not need to visit all sensors in the sensor network because using wireless communication can help DaaG get the sensor data without approaching the sensor. This point makes Algorithm 2 different from other path-planning algorithms, such as the nearest-based algorithm. However, since using this algorithm alone can result in missing a node in the sensor network, DaaG marks the flag value \(F_{i}\) of the sensed node as one, and sets the flag value as two for the visited node. Finally, DaaG moves toward the node that has the lowest weight among the nodes. ```
1:for\(i=1\) to \(|S|\)do\(\triangleright\) Initialize all \(F_{i}\) to 0
2:\(F_{i}=0\)
3:endfor
4:while any \(F_{i}=0\) exists do\(\triangleright\) Run until DaaG collects data from every sensor
5:if DaaG visits \(s_{i}\)then
6:\(F_{i}=2\)
7:\(s_{k}=\) getSensorToVisit(\(s_{i}\))\(\triangleright\) Get unvisited sensor \(s_{k}\), which has the highest \(w_{ik}\)
8:\(\big{(}pos_{sx}\), \(pos_{sy}\big{)}=\) getPosition(\(s_{k}\))
9: moveDaaGTo(\(pos_{sx},pos_{sy}\big{)}\)\(\triangleright\) Command flight controller to move to \(\big{(}pos_{sx},pos_{sy}\big{)}\)
10:endif
11:\(T=\) getSensorListFromCollectedData(\(D\))\(\triangleright\) Get list of sensed sensors from \(D\)
12:for each \(s_{i}\) in \(T\)do
13:if\(F_{i}=0\)then
14:\(F_{i}=1\)
15:endif
16:endfor
17:endwhile
```  
**Algorithm 2** Path-planning algorithm in the sensor network. Once DaaG collects all sensor data in the sensor network, it uses Algorithm 3 to move DaaG to the actuator network and to give command messages to the appropriate actuator in the case of the data ferry network method. ```
1:\(PSL=\) runSmartDataProcessing(\(D\))\(\triangleright\) Get PSL with smart data processing
2:\(VL=\) List(empty)\(\triangleright\) Initialize visited list \(VL\)
3:\(ACL=\) List(empty)\(\triangleright\) Initialize actuator correlation value list \(ACL\)
4:for\(j=1\) to \(\big{|}\big{|}\big{|}\big{|}\)do\(\triangleright\) Calculate \(ac_{j}\) for all actuators
5:\(ac_{j}=\sum_{i=1}^{|PSL|}corr_{s_{i},a_{j}}\)
6:\(ACL\)insert(\(ac_{j}\))
7:endfor
8:if data ferry then
9:while\(VL\
eq A\)do\(\triangleright\) Run until DaaG visits every actuator
10:\(a_{j}=\) getActuatorToCommunicate(\(A\setminus VL,ACL\))\(\triangleright\) Get \(a_{j}\) with highest \(ac_{j}\) in \(A\setminus VL\)
11:\(\big{(}pos_{sx},pos_{sy}\big{)}=\) getPos(\(a_{j}\))\(\triangleright\) Put \(a_{j}\) into VL
12:\(VL\).insert(\(a_{j}\))\(\triangleright\) Put \(a_{j}\) into VL
13: moveDaaGTo(\(pos_{sx},pos_{sy}\))
14:endwhile
15:elseif multi-hop then
16:\(a_{j}=\) getActuatorToCommunicate(\(A,ACL\))
17:\(\big{(}pos_{sx},pos_{sy}\big{)}=\) getPosition(\(a_{j}\))
18:\(s_{i}=\) getNearestSensorFrom(\(a_{j}\))
19:\(\big{(}pos_{sx},pos_{sy}\big{)}=\) getPosition(\(s_{i}\))
20:for k = 1 to \(n_{d}\)do
21: moveDaaGTo\(\big{(}\frac{kpos_{sx}+(n_{d}+1-k)\cdot pos_{sx}}{n_{d}+1},\frac{kpos_{sy}+(n_{d}+1-k) \cdot pos_{sy}}{n_{d}+1}\big{)}\)
22:endfor
23:endif
```  
**Algorithm 3** Path-planning algorithm in the actuator network.