What it did
Spawn N TurtleBots in a shared Gazebo world; each runs an identical decentralized controller that reads (a) its own pose, (b) nearest neighbors’ poses (via a shared TF tree), and (c) obstacle proximities from its own laser. Converge the swarm into a target formation (line, circle, V-shape) without any central coordinator.
The approach
Each robot computes a velocity command as a weighted sum of three “force” vectors:
- Goal force — pulls toward its assigned formation slot.
- Separation force — repels from neighbors closer than
d_min. - Obstacle force — repels from any LIDAR return closer than
d_safe.
A small saturation step clamps the resultant to the TurtleBot’s max linear + angular velocity. The whole control loop is ~30 LOC of Python.
What was actually tricky
- Spawning N robots in one Gazebo world required namespace
prefixing the entire ROS topic tree per robot.
turtlebot1/odom,turtlebot2/odom, etc. — the launch file balloons. - Initial conditions matter a lot. If two robots start exactly on top of each other, the separation force is undefined and the swarm explodes outward. Need symmetry-breaking via small random initial offsets.
- Reactive controllers oscillate when goal and separation forces are similar magnitude. Damping helps; better: switch to goal-only when within a tolerance band, separation-only when too close.
What I’d do differently with hindsight
- Use a proper consensus controller (e.g., Olfati-Saber’s flocking) rather than ad-hoc force weights. The theory predicts stability conditions; force-blending is hope-and-tune.
- CBF / safety filter for the separation constraint. Treating “don’t crash” as a hard constraint enforced by a quadratic program is cleaner than a soft repulsive force.
- Test in a real robot. Gazebo’s perfectly synchronized clocks and zero-latency comms hide all the hard problems of real swarms.
What it taught me
Decentralized control is appealing in theory and very hard in practice. The local rules are simple; the emergent behavior is what needs proofs. For a class project, “looks roughly right in Gazebo” is the bar; for anything real, you want theory backing the parameters you tuned.