Swarm Flocking Behavior

The swarm_flocking_behavior is a core component of the as2_behaviors_swarm_flocking package in Aerostack2.

This behavior generates dynamic and complex swarm structures around a virtual centroid, allowing multiple drones to move in formation. It relies on the ROS 2 Tf2 Library to manage reference frames and transformations.

The implementation is based on Reynolds’ boids rules: Separation, Cohesion, and Alignment.

Working Principle

The behavior receives the following information:

  • Virtual Centroid: Relative pose of the centroid with respect to the frame it must follow.

  • Swarm Formation: List of relative poses of the drones in the swarm with respect to the virtual centroid, including the ID of each drone.

  • Drone Namespace: List of the drone namespaces in the swarm. The order must match the swarm formation list.

When the action command is received:

  1. A static TF is created for the centroid with respect to the frame it must follow.

  2. A static TF is created for each drone with respect to the centroid, according to the swarm formation.

  3. A follow_reference behavior is created for each drone so it follows its corresponding TF with respect to the centroid. The velocity reference is generated by the flocking algorithm.

  4. The swarm moves when the reference frame followed by the centroid moves. The drones maintain formation around the centroid while adapting dynamically according to the flocking rules.

Behavior Actions

  • Pause: Pauses the follow_reference behavior of each drone, stopping their motion around the centroid.

  • Resume: Resumes the follow_reference behavior of each drone.

  • Modify: Allows modification of:

    • The virtual centroid pose with respect to the reference frame.

    • The number of drones in the formation.

    • The relative poses of the drones around the centroid.

Configuration Parameters

The behavior can be configured via the config/config_default.yaml file.

Launching the Behavior

You can launch the behavior using the provided launch file:

Manual Mode

ros2 launch as2_behaviors_swarm_flocking swarm_flocking_behavior.launch.py

Sending the Goal manually:

You can send a goal to the behavior with a specific formation configuration using the following command:

ros2 action send_goal /<namespace>/SwarmFlockingBehavior as2_msgs/action/SwarmFlocking "{
  virtual_centroid: {header: {frame_id: '<frame_id>'},
   pose: {position: {x: <x>, y: <y>, z: <z>}, orientation: {x: <x>, y: <y>, z: <z>, w: <w>}}},
  swarm_formation: [
    {id: '<drone_id>',
    pose: {position: {x: <rel_x>, y: <rel_y>, z: <rel_z>}, orientation: {x: <x>, y: <y>, z: <z>, w: <w>}}}
  ],
  drones_namespace: ['<drone_id>']
}"