# Virtual Pheromone Based Network Flow Control For Modular Robotic Systems
## 3 Virtual Pheromone Based Network Flow Control
### Gradient-Based Routing Algorithm  
After discovering to obtain neighbourhood information, we explain how the gradient-based routing algorithm is used to generate communication paths for delivery of data packets from _any module to the root_. An example of a configuration of physically connected robotic modules with automatically generated gradient-based ID can be seen in Figure 1. The root is activated with the lowest gradient, i.e., zero, and the gradient is dispersed over its neighbour so the other robots receive their corresponding gradient, which is increased from the _root_. Some modules might have the same gradients because they belong to different paths. A gradient dispersion algorithm can be seen in Algorithm 1. Once the gradient has been generated, it is automatically adjusted in a distributed fashion by a _path recovery mechanism_. If a module is manually removed from the network configuration, e.g., \(B_{2}\) in Figure 1(a), its neighbours are aware of disconnections through the link maintenance process. \(B_{2}\) has a smaller gradient than \(B_{3}\), so \(B_{3}\) requests a new gradient from its remaining neighbours. Meanwhile, \(B_{1}\) remains its existing gradient as it has smaller gradient than \(B_{2}\). Hence, a new path is formed with the updated gradient of involved robots. On the other hand, if a new module is added to the network configuration, e.g., \(B_{2}\), it collects all the gradients from its immediate neighbours and selects the lowest one. To let its neighbour update their gradients, this module will transmit its gradient to all of its immediate neighbours. As a result, a communication path is constructed by involved modules without a centralized control from a master. This _path recovery mechanism_ can be applied for any distributed modular robotic systems. While local communication between neighbourhood modules is well managed by the physical layer and the link access & management layer [17], a _path recovery mechanism_ with its _gradient recovery procedure_ is used to deal with reconfiguration of communication networks. An algorithm of communication path recovery can be seen in Algorithm 2. ```
1:procedureGradient recovery
2:\(1D\gets gradient\)
3:start:
4:ifcurrent state \(\leftarrow\) neighbourthen
5:send gradient to new neighbour
6:elseif lost neighbourthen
7:check current state
8:if lost neighbour has greater gradientthen
9:keep current gradient
10:elseif lost neighbour has smaller gradientthen
11:clear current gradient
12:request gradient from other neighbours
13:endif
14:endif
15:endprocedure
```  
**Algorithm 2** Communication path recovery mechanism  
Once the gradient has been generated, it is automatically adjusted in a distributed fashion by a _path recovery mechanism_. If a module is manually removed from the network configuration, e.g., \(B_{2}\) in Figure 1(a), its neighbours are aware of disconnections through the link maintenance process. \(B_{2}\) has a smaller gradient than \(B_{3}\), so \(B_{3}\) requests a new gradient from its remaining neighbours. Meanwhile, \(B_{1}\) remains its existing gradient as it has smaller gradient than \(B_{2}\). Hence, a new path is formed with the updated gradient of involved robots. On the other hand, if a new module is added to the network configuration, e.g., \(B_{2}\), it collects all the gradients from its immediate neighbours and selects the lowest one. To let its neighbour update their gradients, this module will transmit its gradient to all of its immediate neighbours. As a result, a communication path is constructed by involved modules without a centralized control from a master. This _path recovery mechanism_ can be applied for any distributed modular robotic systems. While local communication between neighbourhood modules is well managed by the physical layer and the link access & management layer [17], a _path recovery mechanism_ with its _gradient recovery procedure_ is used to deal with reconfiguration of communication networks. An algorithm of communication path recovery can be seen in Algorithm 2.