Consensus Control and Provable Safety in Swarms

A weekend exploration on how drones with no leader can track patterns and avoid collisions with guarantee.

By @shmoshmik


I occasionally read aerospace engineering books from my undergraduate days. While reading Prof. Anderson’s Introduction to Flight, I realized I never really read about multi vehicle control. Even during my days at Aerial Robotics Kharagpur, we once controlled ~12 crazyflies concurrently using a naive potential field model, but that was it. Most of our controls research was on novel, low level controllers for ARK’s in-house, autonomous AVs. This Friday, I educated myself a bit.

I learnt about 2 beautiful concepts. First, the entire logic for leaderless multi-agent coordination can be a single matrix multiply. Second, you can bolt on mathematically guaranteed collision avoidance as a thin filter, without touching the original controller at all. Moreover, without knowing what that controller even does!

This post walks through both ideas of consensus control and Control Barrier Functions. We’ll build a simulator where six agents form shapes with no leader, switch topologies on the fly, and provably never collide.

I’ve tried to write this blog as something my freshman self would have loved reading, without any control theory priors. All the code is Python with pygame, numpy & cvxpy (optional). I didn’t touch ROS this time :)


The Setup: Six Agents, No Leader

Here’s the problem. You have six agents (think drones, warehouse robots, or autonomous vehicles). You want them to arrange themselves into a formation (a triangle, a hexagon, a V-shape). But:

Can they still converge to the formation? And can we guarantee they won’t crash into each other along the way?

The answer to both is yes, and the math is PRETTY. Let’s build it from scratch.

Here’s a quick demo before we dive into things

https://youtu.be/VdwcuvvTtKw