Gradient

This behavior forms a distance gradient from the source. The robot that has an ID = 0 will be the source.

Every robot broadcasts its distance from the source as well as listens to other robots. The broadcasts are done using neighbors.broadcast().

gradient.bzz (Source)

    neighbors.broadcast("dist_to_source", mydist)

neighbors.listen() is used to listen to the distance broadcasted by other robots. mydist refers to the distance from the source. It is calculated by getting the minimum value of mydist and the sum of the distance from the neighbor, neighbors.get(robot_id), and neighbor's distance from the source, value.

gradient.bzz (Source)

    neighbors.listen("dist_to_source",
      function(value_id, value, robot_id) {
        mydist = math.min(
          mydist,
          neighbors.get(robot_id).distance + value)
      })

Video

Value shown in top of the robots are its distance from the source. As the distance gradient calculation is too quick to be seen, it is calculated every 3 seconds in the video. The figure below shows this behavior implemented in a swarm of six Khepera IV robots. The source robot is located far left in the picture. As shown, a color gradient from red to blue is applied to the swarm.

/images/color_gradient.JPG

Figure 1: Color gradient applied to the swarm

Back