Azimuth Coordination

This behavior shows robots rotating towards an angle similar to the source. As the robots have their own local coordinate system, it relies on other robots to instruct them to rotate to the correct bearing. The relative azimuth of the robot from its neighbors is necessary this angle calculation. The robots in this behavior are split into three categories:

  • the source
  • robots who have not received their relative azimuth from their neighbors
  • robots who have received their relative azimuth from one of their neighbors

Neighbor Communication

In order for this behavior to work, there must be communication within its neighbors. This is done through the functions, neighbors.broadcast() and neighbors.listen(). In this behavior, a knowledge table is used in each robot to store and categorise the data in a dictionary with key pair values. An example of an entry in the knowledge table is {"x-y", data}, where x is the ID of the robot and y refers to the category of data.

Data Category

y Data
0 Own azimuth
1 Own azimuth relative to neighbor x
2 Neighbor distance
3 Visibility bit, set as 1 if neighbor is visible
4 Ready bit, set as 1 if robot is in position
5 Accumulated distance from neighbor x

Key 5-2 refers to the distance to robot whose ID is 5 and key 3-1 refers to my position relative to robot whose ID is 3.

rotation.bzz (Source)

              knowledge[key] = 0
          }
    })
    neighbors.foreach( function(rid, data) {
        # For each neighbor, send a message with its azimuth, as seen by the broadcasting robot
        message_id = string.tostring(rid)
        neighbors.broadcast(message_id, rtod(data.azimuth))
        # Record the neighbor azimuth in my own knowledge table
        write_knowledge(knowledge, rid, 0, rtod(data.azimuth))
        # Record the neighbor distance in my own knowledge table
        write_knowledge(knowledge, rid, 2, data.distance)
        # Set neighbor as visible
        write_knowledge(knowledge, rid, 3, 1)
    })
}

function listen_to_your_neighborhood() {
    # For all "senders" in my neighborhood, record my azimuth, as seen by them
    message_id = string.tostring(id)
    neighbors.listen(message_id, function(vid, value, rid) {

The function above, inform_your_neighborhood(), first resets the visibility of all neighbors to reduce conflict of neighbors previously seen. Using the neighbors.foreach(), each robots's own azimuth is sent to its neighbors. Also within neighbors.foreach(), each robot's azimuth, distance and visibility is recorded into the knowledge table using write_knowledge().

rotation.bzz (Source)

    })
}

# Rads to degrees
function rtod(r) {
   return (r*(180.0/math.pi))
}

The function listen_to_your_neighborhood() is only called once at the start of the program. It enables the robots to listen to the neighbor broadcast as mentioned above. The data which is broadcasted is the azimuth of other neighbors. The azimuth is then written to the knowledge table with write_knowledge.

Calculation of bearing

Once relative azimuth is received from its neighbors, calculation of the new azimuth will be done to align the robot to an angle similar to the source. The robot would rotate until the azimuth of the broadcasting robot reaches its desired angle. In the Figure below, this angle for which the receiving robot will be aligned would be (180 + a) degrees taking in reference to the imaginary line drawn between the robots.

/images/angle_calc.JPG

Figure 1: Angle calculation

/images/angle_calc_done.JPG

Figure 2: Angle calculation after

Message Passing

Robots who have not received the azimuth wait and get the azimuth of the nearest broadcasting robot before rotating itself. Similar to the gradient behavior, neighbors.broadcast() and neighbors.listen() to achieve this. Once a robot has aligned with the source, it will broadcast its distance to the rest of its neighbors with neighbors.broadcast(). Robots who have no contact with the source robot will coordinate their direction with the nearest robot who is broadcasting its distance. align(desired_id) aligns the robot towards the nearest neighbor who is already aligned.

rotation.bzz (Source)

    if ((read_knowledge(knowledge, rid, 5)<mydist) and (read_knowledge(knowledge, rid, 5) >= temp_dist)) {
      temp_dist = read_knowledge(knowledge, rid, 5)
      desired_id = rid
    }
  })

  # Align with closest neighbor
  align(desired_id)
}

function nextState() {
  neighbors.broadcast("dist_to_source", mydist)
  debug("aligned")
}

Video

Back