WorksComputer Science
Distributed Predictive Flocking for a Swarm of Miniature Vibration-Driven Robots in a Confined Arena
Abstract
Coordinating many miniature robots in a confined arena, with no leader, central planner, or global map, is a core challenge for swarm robotics. As the swarm grows denser, collision avoidance becomes the limiting factor, and the number of safely coexisting robots depends on the formulation of the inter-robot safety constraint. We present a distributed predictive flocking controller in which each robot solves its own nonlinear model predictive control (NMPC) problem, optimizing swarm cohesion and alignment costs, inter-robot and obstacle safety, and a task objective, while exchanging only predicted trajectories with local neighbors. Within this generalized controller architecture, solved in real time, we compare six barrier and control-barrier-function (CBF) safety formulations on a digital twin of an open-source vibration-driven bristlebot in a arena. A look-ahead discrete-time CBF performs best overall, with the fewest collisions and the widest inter-robot margins across nearly every swarm size tested. We deploy it on phototaxis, phototactic orbiting, and cohesion without a stimulus tasks, using swarm sizes starting from ten robots and up to the geometric packing limit. The swarm holds well: collisions stay low in small swarms, rising steeply as the packing limit approaches, while coordination and cohesion degrade gently rather than collapsing. The swarm is found not to trade safety for order, keeping both across the confined arena, with local alignment high at every swarm size.
_gset:Nn __short_title: Distributed Predictive Flocking for a Swarm of Miniature Vibration-Driven Robots in a Confined Arena
_gset:Nn __short_authors: Shrestha et al.
[orcid=0009-0005-9585-3800]
Introduction
Autonomous multi-robot systems are a promising approach for tasks in cluttered, inaccessible, or hazardous spaces, from confined-structure inspection to search in collapsed buildings and medical micro-robotics [14]. In these settings, many miniature robots must coordinate in proximity within a tight, bounded arena. As in natural swarms, such as flocking of starlings, schooling of fish, the crowded colonies of ants and honey bees, and even the collective migration of cells, robust group behavior emerges from purely local interactions among simple agents [9, 7, 6], with no central control [14]. Miniaturization, however, tightly bounds onboard compute, memory, and power [15], demanding control that is theoretically principled yet computationally light. Moreover, when the arena is fixed, a growing number of robots increases the density of the swarm and hinders smooth motion. When it is also cluttered with obstacles, coordination is even harder. In this scenario, collision avoidance becomes the central challenge.
The standard way to coordinate such a swarm from purely local interactions is Reynolds’ boid model [1, 2], which reduces collective motion to three local rules (cohesion, alignment, and separation) that produce coherent group motion without global information [8]. Early control laws formalized these as artificial potential fields over a communication graph [4, 5], and reactive velocity-matching rules scale to tens of drones [13]. Such reactive methods, however, offer no predictive horizon, no formal safety guarantee under nonlinear dynamics, and no systematic handling of kinodynamic limits. These shortcomings are especially severe in confined, high-density settings, where many underactuated robots have little room to recover from unsafe motions.
Model predictive control (MPC) [18] addresses these limitations. For the nonlinear dynamics of mobile robots, this takes the form of nonlinear MPC (NMPC). It solves a finite-horizon optimal control problem (OCP) online, which provides closed-loop feedback, constraint satisfaction, and explicit multi-objective trade-offs. Distributed MPC (DMPC) extends this to a swarm by splitting the global problem into per-agent OCPs coupled through shared constraints [19, 20, 21, 22]. Solvers such as the Sequential Quadratic Programming real-time iteration (SQP-RTI) [55] solve each per-agent OCP in real time. Similarly, optimization-based swarm planners achieve strong real-world navigation [23, 25, 24, 27]. These methods are mainly developed for point-to-point navigation [20, 26], with collision avoidance typically encoded as geometric constraints such as separating hyperplanes or safe corridors.
The closest works embed Reynolds behaviors in NMPC. They have been demonstrated on up to 16 quadrotors [28, 29], leader-follower teams [30, 31, 32], and fixed-wing unmanned aerial vehicles (UAVs) [33]. Most share one regime. They assume sparse flight in large 3D airspace, with the swarm migrating toward a shared goal. Even when several obstacles are present, they remain sparse relative to the available space, keeping the environment effectively low-density. Few address the opposite regime that we target, where many underactuated robots coordinate at high density in a fixed, confined, and cluttered arena under a task objective such as following a light gradient. Here, the inter-robot safety formulation, not free-space planning, governs how many robots can coexist. Each of these works, however, fixes a single safety formulation in advance, usually a distance constraint or a penalty. It remains open which formulation fits the most robots into a fixed arena with minimal collisions.
Safety formulations differ in how collision avoidance is encoded as a constraint in the OCP. Such a constraint is classically formulated using a barrier function whose safe set is kept forward invariant to certify safety [34], typically imposed as a hard [36] or soft [37] distance constraint. A Control Barrier Function (CBF) [34] relaxes this strict boundary condition by allowing to decrease at a rate bounded by a class- function, and its discrete-time form (Dt-CBF) [35] imposes this at each MPC stage. [38] enforces it as a hard constraint, which is often infeasible. Feasibility is restored by softening the decay with slack variables [39, 40, 41], adding terminal barrier terms [43, 44], or anchoring a soft CBF with one hard step [42]. Beyond feasibility, when the constraint has relative degree greater than one, as for a distance constraint under unicycle dynamics, a higher-order CBF (HOCBF) [45, 46] chains the barrier conditions. [42] compare a distance-constraint MPC, a hard discrete-time CBF, a slacked CBF, and their combination on a common footing, but for a single robot. In the multi-robot setting, safety is enforced by reactive schemes [48, 49], by post-hoc CBF-QP (quadratic program) filters [50], or by a CBF inside a decentralized MPC with neighbors as predicted trajectories [51, 52, 53, 54]. A formulation’s collision performance, however, likely changes with the swarm density. A comparison across densities is required to find the best one.
In this work, we investigate the maximum number of miniature robots a distributed predictive controller can flock in a fixed arena, and design a controller to push that limit. Each robot solves its own NMPC combining Reynolds cohesion, alignment, and separation (gated by neighbor presence) with inter-robot/obstacle safety and the task objective. It selects the nearest neighbors within the communication radius and exchanges predicted trajectories synchronously as OCP parameters, giving a fully distributed, leader-free architecture with no central planner or global map. We evaluate it on a physics-informed digital twin [17] of the GRASPion [16], an open-source vibration-driven bristlebot studied as an active-matter model system. We characterize how densely the swarm packs a arena while sustaining two behaviors. These are phototaxis (ascending toward a moving Gaussian light gradient) and a phototactic orbital mode (orbiting the source along the intensity level-set). We compare six inter-robot safety formulations on a common footing (§ 3.3). A slacked barrier paired with a discrete-time CBF at a forward handle [47] sustains the highest density with the fewest collisions. The main contributions of this paper are as follows:
A distributed predictive control system for dense swarms of miniature vibration-driven robots. Each robot solves its own NMPC fusing flocking, safety, and the task objective, coupled to neighbors only through exchanged predicted trajectories.
Demonstration that a single controller generalizes across qualitatively different collective behaviors. The same architecture produces gradient-ascending phototaxis, stable phototactic orbital formation, and generic flocking with no modification to the safety or coordination layers, showing that task objectives and coordination structure are separable and that new tasks can be added without re-deriving safety guarantees.
A careful comparison of six inter-robot safety formulations within one identical controller, isolating the safety constraint as the only varying factor. The Look-ahead Slack Dt-CBF gives the best overall trade-off for the phototaxis deployment target.
Characterization of the operating swarm density that the controller sustains in a fixed arena. The swarm stays cohesive with few collisions in small swarms; collisions rise steeply towards the geometric packing limit, as saturation sets in, while coordination and feasibility degrade gently rather than collapse.
The remainder of this paper is structured as follows. § 2 presents the robot model, light field, control architecture overview, behavior generation, flocking rules, and the DMPC OCP. § 3 reports the simulation results, including the safety-formulation study (§ 3.3), the analysis of collective behavior (§ 3.4), and the quantification of collision avoidance under different tasks (§ 3.5). § 4 summarizes the work and provides an outlook for future studies.
Preliminaries and Problem Statement
In this work, we consider a swarm of robots operating in a bounded arena , with each robot labeled by . The state of robot is , where is the position and the heading. Inter-robot communication is modeled as a directed sensing graph , where denotes the set of robots and is the communication set of ordered pairs for which robot can observe robot . The neighbor set of robot is . We adopt a topological neighborhood with fixed cardinality , selecting the nearest robots within communication radius of robot . This choice keeps the neighbor count constant and avoids the cost discontinuities that arise under Voronoi or attraction-based topologies [10, 11, 12]. Each robot additionally accounts for up to nearby static circular obstacles within a sensing range , indexed by , with obstacle at center and radius . The environment also includes a single light source whose intensity field serves as the swarm stimulus.
The OCP is compiled once with a fixed parameter dimension. Neighbor and obstacle information therefore enters two fixed-size blocks of and slots, the neighbor block and the obstacle block. At each control step, robot receives a predicted trajectory from each neighbor , where and are the predicted position and velocity of neighbor at horizon stage . Throughout, a hat denotes a quantity the per-robot OCP treats as fixed data (the ego robot’s current measured state and the neighbors’ received predicted trajectories). The ego robot’s own predicted states are decision variables. These trajectories fill the neighbor block, and the number of occupied slots changes from step to step. Each neighbor slot therefore carries a binary activation mask , where if slot is occupied at stage and otherwise. The obstacle block is filled the same way. Robot selects the nearest obstacles within obstacle sensing range and writes each center into a slot together with its own activation flag.
Robot Model
Each robot is modeled as a rigid ellipse with semi-major axis and semi-minor axis , matching the physical footprint of the GRASPion open-source bristlebot [16], as illustrated in Figure 1. The simulated elliptical agent is modeled after this hardware platform, following the physics-informed digital twin of [17], so the simulation study is grounded in a physical robot footprint and can serve as a precursor to future physical experiments.


Figure 1. (Left) Two elliptical robots with minimum safe distance and semi-axes () and (). (Right) The physical GRASPion open-source bristlebot hardware.
The dynamics of each robot are described by a three-state kinematic unicycle model with state , input , and continuous-time dynamics given by
where is the position, the heading angle, the linear velocity, and are the velocity components, and the angular velocity. The continuous-time dynamics (3) are integrated using an explicit Runge-Kutta 4 (ERK-4) integrator with three steps per control interval, yielding the discrete-time map .
Light Field Model
The arena contains a time-varying light field that each robot senses locally to compute its navigation reference. The field is modeled as a Gaussian intensity profile whose source either orbits the arena center or remains stationary.
Light Source
The light source produces a Gaussian intensity field
where is an arbitrary position, is the peak intensity, is the position of the source at time , and represents the spatial spread of intensity.
Source Dynamics
The light source supports two motion modes. In circular rotation mode, the source orbits the center of the arena at a fixed radius with angular speed , with the position of the source given by
where is the initial angle of the source in the orbit and is the speed of the source along the orbit. In stationary mode, the source remains fixed at the arena center.
Intensity Gradient
The intensity gradient with respect to the robot position is computed analytically as
This analytic gradient is the local cue that the collective-behavior modes of § 2.4 convert into each robot’s look-ahead reference.
Control Architecture Overview
Every robot runs an identical decentralized controller, outlined in Figure 2. At each control step, the robot senses the local light field, and a behavior module maps this reading to a look-ahead reference that encodes where the robot should head next. A per-robot optimal control problem (OCP) tracks that reference. Flocking rules keep the group cohesive and heading-aligned, while barrier and control-barrier-function constraints enforce inter-robot and obstacle safety. Robots publish their predicted trajectories over the sensing graph and re-solve synchronously from their neighbors’ previous plans, coordinating the swarm without a central node. The rest of this section develops the remaining components in turn. These are the behavior module (§ 2.4), the flocking rules (§ 2.5), the six safety formulations (§ 2.5.3–§ 2.5.4), the reference-tracking and control-effort costs (§ 2.6), the assembled OCP (§ 2.7), and the decentralized execution loop (§ 2.8).

Figure 2. Per-robot control architecture for the DMPC swarm. Each robot runs three concurrent subsystems. The Perception block estimates the robot’s state comprising position and , orientation , and velocity and . The Planning and Control block uses this state to compute a look-ahead reference based on the active swarm behavior (phototaxis or phototactic orbital) and then solves the local NMPC problem to produce control commands, which are passed through a Calibration layer before reaching the Actuator. The Communication block handles all inter-robot data exchange, where solid arrows denote state signals and dotted arrows denote predicted trajectory exchanges. Incoming broadcasts are filtered by a Neighbor Filter (within communication range and -nearest selection) and stored in the robot’s neighbors buffer before being used by the NMPC solver.
Collective Behavior Modes
Collective motion emerges when individual agents produce coordinated group-level movement through purely local interactions in the absence of centralized planning [1, 3]. In our controller, a behavior module translates local sensory observations into a look-ahead reference at each control step, which the OCP then tracks while maintaining flocking coherence and safety. We describe two such modes, phototaxis and phototactic orbital behavior.
At each control step, the light-field gradient is evaluated analytically from (4)–(6). The resulting reference heading depends on the selected collective behavior mode. Once the heading is obtained, the look-ahead reference position is computed as
where is the look-ahead distance, and the clipping function constrains the reference position to remain inside the arena. The reference velocity is set to a constant target value , and the reference angular velocity is fixed at zero.
Phototaxis Behavior Mode
Phototaxis drives each robot to ascend the intensity gradient of the light field without knowledge of the global source position. The reference heading is aligned with the steepest ascent direction:
where is a small gradient threshold. When the field is nearly flat (), the robot holds its current heading rather than turning randomly.
Phototactic Orbital Behavior Mode
In the phototactic orbital mode, each robot follows the tangent of the light intensity level set, effectively orbiting the source without knowledge of its global position. The reference heading is obtained by rotating the gradient direction from (8) by , with the orbital direction governed by the circulation parameter (where generates counter-clockwise motion, and generates clockwise motion):
Extensibility to Arbitrary Behaviors
Decoupling the reference generator from the OCP makes the architecture task-agnostic. Any behavior (directed migration, dispersal, transport, shape formation) can be integrated by mapping local observations to a look-ahead reference , while the DMPC preserves safety and flocking coherence.
Reynolds Flocking Rules
The behavior modes set each robot’s individual objective, while the collective motion arises from the local steering rules proposed by Reynolds [1, 2]. Cohesion binds robots into a group, alignment coordinates their heading, separation keeps them from colliding, and obstacle avoidance steers them clear of static hazards. The controller encodes cohesion and alignment as quadratic cost terms in the per-robot OCP, while separation and obstacle avoidance are enforced through barrier and discrete-time CBF constraints [34, 35]. We focus on the separation and obstacle avoidance by comparing six different formulations, ranging from hard barriers to slacked variants (§ 2.5.3 and § 2.5.4).
Cohesion
The active-neighbor centroid at stage is computed as a masked weighted average of predicted neighbor positions:
where the soft neighbor count
prevents division by zero when there are no neighbors in the vicinity. The cohesion penalty is
with weight , gated by the activation gate
When at least one neighbor slot is active, and the cost is enabled. In isolation, when and it vanishes. Separating (denominator safety) from (which enables the cohesion and alignment costs only when a neighbor is present) keeps the per-robot cost well posed for the SQP-RTI solve. Finally, cohesion uses the stage-matched predicted positions rather than current measured ones, pulling robot toward where its neighbors are predicted to be.
Alignment
The mean heading direction () of active neighbors is estimated from their predicted velocity vectors:
The neighbor velocities are summed rather than normalized, so faster neighbors weigh more heavily. The offsets regularize near a zero velocity sum (fixing at only at exact cancellation, an edge case). The resulting then defines the alignment heading error, wrapped to :
and the alignment penalty is
with weight . As in the cohesion term, the shared gate disables both cohesion and alignment when robot is isolated.
Inter-Robot Separation
The inter-robot separation constraint builds on a pairwise safety barrier and its Dt-CBF extension. For neighbor slot at stage , the barrier
is non-negative exactly when robot and neighbor are at least apart. Starting from this barrier, the same safety constraint can be encoded in several ways, each imposed hard or slacked. We consider six formulations that differ only in the safety constraint, and observe the corresponding change in swarm behavior. § 3.3 then evaluates all six under identical conditions and retains the best-performing one. The last three share a common structure consisting of a slacked barrier anchor paired with a rate condition. They differ only in the rate condition, which is a one-step Dt-CBF on the body, the same condition on a forward handle, or a two-step higher-order chain.
(a) Hard BF
The plain barrier imposed as a hard constraint,
is the most direct encoding of the rule. It forbids any predicted configuration closer than at every stage. It is purely reactive (it acts only once a neighbor is within range) and, as a hard constraint, allows no slack, so a robot surrounded by several neighbors at once can leave its OCP with no feasible input.
(b) Hard Dt-CBF
The discrete-time CBF condition as a hard constraint,
compares the barrier with its one-step-ahead value . The latter is formed by a forward-Euler step of the ego position and a constant-velocity step of each neighbor,
The ego step is linear in , which keeps the quadratic-program subproblems well conditioned. It is a first-order approximation used only inside the barrier constraint, separate from the ERK-4 discretization of the dynamics (3). The condition does not forbid but limits how fast the barrier may shrink each step, to at most a fraction (a discrete class- rate). The robot therefore starts slowing while still safely separated rather than braking at the boundary, giving smoother, early avoidance. This is exactly the MPC-CBF formulation of [38]. Being a hard constraint, it carries the same infeasibility risk as Hard BF with dense congregations of robots.
(c) Slack BF
The plain barrier mentioned in Hard BF, softened by its slack,
keeps the OCP solvable in the crowded configurations that make Hard BF infeasible. When no input can satisfy , the penalized slack opens just enough to admit a feasible, minimally-violating solution instead of failing.
(d) Slack Dt-CBF
The slacked barrier anchor (23) and the discrete-time CBF condition softened by its own slack,
imposed together on the same neighbor, each with its own slack. The rate condition combines the before-contact activation of Hard Dt-CBF with the improved solvability of Slack BF. The anchor guards the footprint at every stage while the CBF constraint shapes the approach rate. This is the reference point for the next two formulations: they retain this anchored structure and change only where or how the rate condition is evaluated, so the ensuing description only mentions those two choices.
(e) Look-ahead (LA) Slack Dt-CBF
This formulation is a modification of Slack Dt-CBF with its rate condition moved from the body onto a forward handle a fixed distance () ahead of the robot, adapting the offset-point construction of [47] to discrete time,
with the slacked condition imposed on the handle. A body distance barrier has relative degree two under unicycle dynamics, so the turn rate does not appear in its one-step form and a robot can only slow down to keep clear. The handle moves with the heading, so enters the one-step barrier directly. The robot can, therefore, also steer around a neighbor, while the body anchor (23) still guards the true footprint.
(f) Slack Dt-HOCBF
The slacked barrier anchor (23) together with a slacked higher-order (relative-degree-two) chain [46, 45] is built natively in discrete time from successive barrier values rather than from derivatives. With and , the barrier evaluates the one-step and two-step prediction under the held input ,
with decay rates . Expanding the chain gives the single constraint actually imposed,
where the two-step prediction advances the heading as and each neighbor by its constant velocity. This addresses the same relative-degree-two obstruction as (e) but analytically rather than geometrically: is absent from the one-step barrier, yet it enters through the rotated heading, with sensitivity .
Across the six formulations, a safety constraint is either imposed hard or softened by its own non-negative slack ( for a barrier constraint, for a Dt-CBF constraint), and the active slacks are penalized in the cost,
where collects the chosen formulation’s inter-robot slacks for neighbor , and are the quadratic and linear weights. The set holds both slacks for the hybrid, look-ahead, and higher-order variants (d)–(f), a single slack for Slack BF, and none for the hard variants. Each slack is driven to zero whenever its constraint is satisfiable and absorbs only the unavoidable residual otherwise. Inactive neighbor slots are padded () so their constraints and slacks vanish.
Obstacle Avoidance
The selected formulation (a)–(f) from § 2.5.3 is applied unchanged to static obstacles, so no new safety constraints are introduced. Each obstacle is treated as a neighbor with a fixed prediction. Three substitutions turn each inter-robot safety constraint of the chosen formulation into its obstacle counterpart. The neighbor position becomes the obstacle center (held at zero velocity). The clearance becomes (a fixed radius exceeding the obstacle radius ). The class- gains take their obstacle values (defaulting to the inter-robot ones). The obstacle barrier, for instance, is
The obstacle slacks are penalized analogously,
with the chosen formulation’s obstacle slacks for obstacle and the quadratic and linear weights. At the terminal stage , the one-step prediction is undefined, and all formulations revert to a plain terminal barrier.
Look-Ahead Reference Point and Control Effort
The look-ahead reference point produced by the behavior module of § 2.4, whatever the mode, enters the per-robot OCP through a quadratic tracking cost. The stage- deviations of the state from this reference point are then defined as
The wrapping in (34) maps the heading deviation to , avoiding discontinuities at . The deviations form a quadratic reference-tracking cost:
with weights . A control-effort term regularizes the inputs for smoother, more energy-efficient trajectories:
where .
OCP Formulation
Each robot solves a finite-horizon OCP over stages. The cost assembles the look-ahead, control-effort, cohesion, and alignment terms plus CBF slack penalties into a stage and a terminal cost. This cost is minimized subject to the dynamics, the state and input box constraints, and safety constraints that enforce separation and obstacle avoidance.
Stage Cost
The stage cost at horizon stage is
where the look-ahead, control-effort, cohesion, alignment, inter-robot slack, and obstacle slack terms are given by (36), (37), (12), (17), (30), and (32), respectively. Separation and obstacle avoidance no longer appear as cost terms. They are enforced through the barrier and Dt-CBF constraints of § 2.5.3–§ 2.5.4.
Terminal Cost
The terminal cost at stage is
where the position, heading, inter-robot slack, and obstacle slack terms are given by (33), (34), (30), and (32), respectively.
Full OCP
Every robot solves the following optimization problem (with neighbor data treated as stage-wise parameters), which incorporates all the previously defined cost terms and constraints in a unified formulation:
Here, and are the inter-robot and obstacle safety constraints of the selected formulation (a)–(f) (§ 2.5.3 and § 2.5.4), evaluated on the neighbors’ predicted trajectories and the obstacle positions . The bounds and are the state and input box limits. The slack vectors and hold up to and entries for . The predictive Dt-CBF rows require the one-step-ahead prediction, while the higher-order rows require the two-step prediction, so they drop at the terminal stage . For the hard formulations (a) and (b), the slacks are fixed to .
Simulation Workflow
Each control step executes a synchronous parallel update [59] in which all robots compute their optimal control sequences simultaneously using only neighbor information from the previous timestep (Algorithm alg:dmpc). This structure prevents any robot from exploiting another robot’s within-step update, matching the limited communication of a real distributed system. At the beginning of each control step, a KD-Tree [60] is constructed over the current robot positions . This spatial partitioning structure enables all -nearest-neighbor queries within communication range to be performed in total time compared to the naive pairwise distance search [61]. Each robot then samples the local light intensity and gradient to compute a look-ahead reference which encodes the desired position, heading, linear speed, and angular velocity according to the active swarm behavior mode. It also collects the nearby obstacle positions within range and the neighbors’ predicted trajectories buffered from the previous control step. Using these inputs, each robot solves a local OCP over horizon via a single SQP-RTI step, while updating the stage-wise parameter vector to incorporate the look-ahead reference, neighbor trajectories, and obstacle positions as time-varying coupling parameters in (?). After optimization, the robot applies the first control action and publishes its updated predicted trajectory for use by neighboring robots at time .
\small
\caption{DMPC Control Step at time $t$}
\label{alg:dmpc}
\begin{algorithmic}[1]
\State Advance light field: $I(\cdot,t) \leftarrow I(\cdot,t{+}\Delta t)$
\State \textbf{Spatial Indexing:} Construct KD-Tree from current positions
$\{\hat{\bm{p}}_1, \ldots, \hat{\bm{p}}_{N_b}\}$
\For{robot $i = 1,\ldots,N_b$ \textbf{in parallel}}
\Comment{Communication Phase}
\State Detect $K$ nearest neighbors $j \ne i$ via KD-Tree query with range
$R_{\rm comm}$
\State Buffer $\bm{\tau}_j = \{[\hat{\bm{p}}_j^{(k)},
\hat{\bm{v}}_j^{(k)}]\}_{k=0}^{N}$ from neighbors'
\emph{previous} trajectories
\EndFor
\For{robot $i = 1,\ldots,N_b$ \textbf{in parallel}}
\Comment{Computation Phase}
\State Sense light intensity $I(\hat{\bm{x}}_i)$ and gradient
$\nabla I(\hat{\bm{x}}_i)$
\State Compute look-ahead reference
$(\bm{p}^{\rm ref},\, \theta^{\rm ref},\, v^{\rm ref},\, \omega^{\rm ref})$
based on the active swarm behavior
\State Detect the $M$ nearest obstacles within range $d_{\rm obs}$ and
compute their center positions $\bm{p}_m$
\State Fetch trajectories $\bm{\tau}_j$ from neighbor buffer
\State Warm-start: $\bm{x}^{(k)} \leftarrow \hat{\bm{x}}_i$,\;
$\bm{u}^{(k)} \leftarrow \bm{u}_{\rm nom}$ $\forall k$
\For{$k = 0,\ldots,N$}
\State Build and set parameter block $\bm{\pi}^{(k)}$: look-ahead reference +
neighbor trajectory $\bm{\tau}_j$
+ obstacle positions $\bm{p}_m$
\EndFor
\State Execute one SQP-RTI step to obtain $\bm{u}^{(k)}$
\State Extract first optimal control input $\bm{u}_i^* \leftarrow \bm{u}^{(0)}$ and updated
$\bm{\tau}_i$ from solver
\EndFor
\State \textbf{Synchronize:} All robots publish updated trajectories $\bm{\tau}_i$
simultaneously \Comment{Available at $t{+}\Delta t$}
\For{robot $i = 1,\ldots,N_b$}
\Comment{Actuation Phase}
\State Apply $\bm{u}_i^*$
\EndFor
\end{algorithmic}
Simulation Results
We evaluate the proposed DMPC framework through a series of simulation studies. The studies characterize the operating density up to the geometric packing limit, compare the six inter-robot safety formulations under a common controller setup, demonstrate emergent collective behavior across the task modes, and assess real-time computational scalability with swarm size.
Simulation Setup
We implemented our DMPC framework symbolically in Python using CasADi [57] and exported the resulting OCP to acados [55], which generates and compiles highly optimized C code via its code-generation pipeline. The solver uses the acados SQP-RTI scheme, ERK-4 integration, and the interior-point QP solver HPIPM [56], and a Gauss-Newton Hessian approximation of the OCP. Simulations were performed on the compute nodes of a throughput cluster, each with two 16-core Intel Xeon Gold 6326 (Ice Lake) processors, i.e. 32 physical cores, and of RAM. Every run was pinned to a single core, so the per-robot solve times reported in § 3.6 are single-core numbers.
The physics environment was simulated using a custom 2D engine within a fixed workspace (horizon , control step , up to neighbors). The NMPC and Reynolds penalty weights were tuned via Bayesian optimization with Optuna [58] to maximize swarm coherence while prioritizing safety and solver stability. The lower speed bound m/s (Table 3) keeps every robot moving instead of letting it stop. The environmental Gaussian light source rotated along a circular trajectory in the phototaxis experiment and remained stationary in the phototactic orbital experiment. All robots were initialized at uniform random positions in a central sub-region covering 90% of the arena with a minimum initial separation of and ran for 9000 control steps (), long enough for the swarm to reach and hold a steady state rather than being measured mid-transient.
Metrics and protocol
All reported quantities are means over random seeds with confidence intervals. Steady-state quantities are averaged over the last of the steps (the final ). A robot-robot (or robot-obstacle) contact is a distinct overlap of the elliptical footprints, evaluated at the MPC-commanded positions and counted once per overlap episode. All runs include a lightweight reactive collision-response layer (a per-robot heading bias plus a few positional-separation sweeps) matching the deployed system. A contact is detected as soon as the footprints overlap, before the layer reacts. The layer then pushes the overlapping pair apart and biases their headings away from each other, so overlaps stay shallow and brief. Solver feasibility is the fraction of per-robot solves returning a successful acados status. The six formulations share an identical stack, weights, horizon, arena, seed set, and safe distance . Only the inter-robot safety and obstacle-avoidance constraints differ. For the look-ahead formulation, the pair was selected by a grid screening followed by Bayesian optimization, and for the anchored Slack Dt-CBF, the decay rate was selected by a direct two-point comparison, each re-verified over the full ten-seed protocol. Formulations (d) and (e) therefore share , which is what makes the look-ahead ablation below a single-variable comparison. The remaining formulations run at the gains inherited from their source implementations rather than at individually optimized ones; a single shared gain would not be meaningful across formulations that differ in structure, and we report this asymmetry because it bounds how the cross-formulation ranking should be read. The complete set of cost weights, CBF gains, slack weights, and environment constants is listed in Appendix § 6,Table 3.
Capacity and Operating Density
We now characterize how densely the swarm can pack in the fixed arena. This section establishes the geometric capacity and selects the operating point used in the later analysis.
Geometric capacity
The swarm size is limited by the safety buffer, not the physical footprint. The elliptical footprint is small, only of the arena at , against when the buffers are also considered. At , the buffers cap the swarm size at an upper limit of non-overlapping safety disks of radius (Table 1). This packing results in area coverage, just below the ideal hexagonal because of boundary and finite-size effects. The ceiling depends on the safety distance, ranging from at to at . Across these distances, the buffer occupancy at the limit stays near –. We therefore use buffer occupancy as a density measure comparable across safety distances.
Operating point
We select the operating point with a closed-loop DMPC sweep over and movement headroom . The sweep scores occupancy, collisions, feasibility, solve time, and neighbor-buffer utilization. Sweeping over over the four barrier and CBF formulations available at the time, it finds both viable, so we set , the tighter of the two. The working maximum then follows from the geometric headroom criterion with ( buffer occupancy), not from the sweep score. Beyond the safety buffers can no longer be packed without forced overlap, and the swarm stays feasible only through the slacked barrier.
| Physical Robot Footprint | Safety Buffer | |||
| 2-3 (lr)4-5 Swarm Size | Total Area | Occupancy | Total Area | Occupancy |
| () | (%) | () | (%) | |
| 1 | 14.14 | 0.22 | 38.48 | 0.60 |
| 10 | 141.40 | 2.21 | 384.85 | 6.01 |
| 25 | 353.50 | 5.52 | 962.11 | 15.03 |
| 50 | 707.00 | 11.05 | 1924.23 | 30.07 |
| 75 | 1060.50 | 16.57 | 2886.34 | 45.10 |
| 80 | 1131.20 | 17.68 | 3078.76 | 48.11 |
| 100 | 1414.00 | 22.09 | 3848.45 | 60.13 |
| 120 | 1696.80 | 26.51 | 4618.14 | 72.16 |
| 137 | 1937.18 | 30.27 | 5272.38 | 82.38 |
Table 1. Swarm size, physical robot footprint, and safety buffer occupancy in a () arena. The physical footprint uses and the safety buffer area is (). The green row () marks the representative swarm size used for the behavior figures. The yellow row () marks the largest swarm size that leaves some headroom to move. The red row marks the geometric non-overlapping packing limit ().
Safety Formulation Comparison
The inter-robot and obstacle safety constraints can be formulated in several ways. To map this design space, we compare the six formulations (a)–(f) of § 2.5.3 and § 2.5.4 for the phototaxis mode in the absence of obstacles. The slacked variants carry the feasibility-recovery idea of [39] over to our distributed swarm. Under the identical setup of § 3.1 (same stack, solver, and closed-loop simulator), the six formulations differ only in how they enforce inter-robot and obstacle safety, so the comparison isolates that single design choice. Each configuration is evaluated at over 10 seeds, with marked by the dashed vertical line in the figures. Figure 3 reports the solver feasibility, the collisions, and the mean QP solve time versus swarm size , and Table 2 summarizes the low-density operating point alongside a high-density operating point .

Figure 3. Safety-formulation comparison across the six variants (phototaxis, free space, 10-seed mean, CI bands). (a) Solver feasibility, (b) inter-robot collisions (distinct contacts over 9000 steps, log scale), and (c) mean per-robot QP solve time, versus swarm size . The dashed vertical line marks the geometric packing limit .
| Variant | Feas. (%) | Solve (ms) | Coll. | Coll. |
| Hard BF | ||||
| Hard Dt-CBF [38] | ||||
| Slack BF | ||||
| Slack Dt-CBF | ||||
| LA Slack Dt-CBF | ||||
| Slack Dt-HOCBF |
Table 2. Safety-formulation comparison (phototaxis, free space, 10-seed mean CI). Collisions are cumulative counts of distinct robot-robot contacts over 9000 steps, reported at a low density () and at a high-density operating point . Feasibility and solve time are at . Bold marks the best value in each column.
Feasibility
Solver feasibility separates the hard and slacked formulations most sharply (Figure 3a). The two hard formulations hold only about to feasibility at . When a solver is infeasible (roughly to of the per-robot OCPs), the robot falls back to a reactive potential-field controller (goal attraction with inter-robot, obstacle, and wall repulsion). This matches the recursive-infeasibility limitation that [38] identify for the hard discrete-time CBF. Softening the barrier with slack variables removes the problem. All four slacked formulations (Slack BF, Slack Dt-CBF, LA Slack Dt-CBF, and Slack Dt-HOCBF) hold at least feasibility across the entire density range, and up to ; the minimum over all densities and all four is , at the packing limit. The small remaining infeasibility comes from the hard arena-boundary constraint, not the safety constraint. At high density, robots pressed against the arena walls can briefly make it infeasible. Feasibility alone, however, does not separate these four. As the collision results show next, a formulation can be feasible everywhere yet still fail to keep robots apart.
Collisions
The formulations diverge in collision counts, not feasibility (Figure 3b), and they separate by structure rather than by barrier order. At the three formulations that pair a barrier anchor with a rate condition (d)–(f) average contacts, against for the three without an anchor (a)–(c), a factor of . The two groups do not overlap at any density in the sweep. Carrying an anchor alongside the rate condition therefore matters more than which rate condition is used.
Two further results follow within the anchored group. First, the look-ahead handle alone reduces contacts by a factor of at low and moderate density, falling to at the packing limit, where it takes them from to . Formulations (d) and (e) are identical apart from the handle, at the same decay rate , with disjoint confidence intervals at every density and no measurable solve-time cost. The reduction is therefore due to the handle, which gives the angular velocity direct authority over the constraint so a robot can steer around a neighbor rather than only brake. Second, the higher-order chain helps at moderate density and stops helping at the packing limit. The Slack Dt-HOCBF is second best in small swarms, but by it falls behind the LA Slack Dt-CBF, against . It does not fail by becoming infeasible, holding feasibility across the whole range against for (d) and (e). What it gives up is margin, and not just at the packing limit. The chain lets its robots run closer than the look-ahead variant at every density (Figure 4a), against at the packing limit. Its two-step condition allows the barrier to shrink further before the robot has to act. That costs nothing when the arena has unoccupied space. As the available area shrinks, a smaller gap leads to contact. On this task, the deployed LA Slack Dt-CBF is best or tied-best at every density except , where it is second behind the Slack Dt-HOCBF with disjoint confidence intervals. Elsewhere, the look-ahead advantage over the chain widens as the arena fills, from at to at .
Safety margins
The formulations also differ in the safety margin they sustain (Figure 4). These runs use the deployed closed loop with the reactive layer active (§ 3.1), and are measured on post-steering positions, so they never show interpenetration. Each value is a mean over robots and steps of the nearest-neighbor distance, not a per-step minimum. The margins separate along the same structural line as the collision counts. On the inter-robot axis, the three anchored formulations (d)–(f) hold – at and – at the packing limit. The three without an anchor (a)–(c) fall from – to –. Comparing group means, the anchor sustains roughly of extra clearance at maximum crowding. The deployed LA Slack Dt-CBF is widest of all at high density, with at and at . At , only the anchored formulations still hold a clear margin above , at –. The unanchored group sits at –, at or just either side of it. Beyond that density, every formulation operates inside the nominal buffer, already – against – at . The task drives this, not the choice of formulation. Phototaxis gathers the swarm at the light peak, so the robots there sit far closer than the arena average of buffer coverage at (Table 1) would suggest, and neighboring buffers have to overlap. What the anchor leads to is a consistently larger share of the space that remains, and from upward the formulation that holds the widest spacing also records the fewest contacts.
On the robot-obstacle axis, the ordering is similar, but the effect concentrates at the low-density end. At the Slack Dt-CBF and the LA Slack Dt-CBF (d),(e) keep about of clearance each, against – for the remaining four, the Slack Dt-HOCBF included. From and up, every formulation converges to –. At that density, robots are pressed against obstacles by their neighbors rather than by their own control choices, so the safety formulation can no longer set the obstacle clearance. This is the margin-side counterpart of the collision result that obstacles stop mattering once inter-robot congestion dominates (§ 3.5).

Figure 4. Safety margins of the six safety formulations versus swarm size (phototaxis with two static obstacles, deployed closed loop with the reactive collision-response layer active, 10-seed mean, CI bands). (a) Steady-state mean nearest-neighbor distance , center to center, dashed horizontal line at cm. (b) Mean robot-obstacle clearance , robot center to obstacle surface, dashed horizontal line at cm, since the obstacle barrier bounds the center-to-center distance. The gray band spans the footprint-contact range, which varies with orientation for elliptical robots (– between two robots, – from a robot center to an obstacle surface). The vertical dashed line marks the geometric packing limit.

Figure 5. Collective behavior in obstacle-free space with the LA Slack Dt-CBF formulation, . (a) Phototaxis, where the swarm stays cohesive and heading-aligned while tracking the moving light source. (b) Phototaxis with the coupling costs and avoidance constraints removed, where the robots pile up at the light peak and collide. (c) Phototactic orbiting, where the swarm co-rotates along the light’s intensity level set. (d) Cohesion without a stimulus, where the Reynolds costs alone keep the group cohesive. Each column corresponds to a certain time , and the orange field is the light source. Supplementary video 1 shows these four behaviors in the obstacle-free arena.
Computational cost
The LA Slack Dt-CBF costs slightly more to solve because of its added look-ahead constraints. Its per-robot solve time is about at , roughly above the cheapest formulations (Figure 3c). Each robot optimizes against a fixed number of neighbors, so this per-robot cost barely changes with swarm size and stays within – across the sweep. It is therefore well inside the budget of a loop at every density. § 3.6 reports the distribution and separates this per-robot cost from the per-step wall time of the single-process simulation, which does grow with . The extra cost is small, so on phototaxis, the deployment target, the LA Slack Dt-CBF gives the best trade-off across feasibility, collisions, and safety margin. Therefore, we adopt it as the deployed formulation for the collective behavior simulations.
Emergence of Collective Behavior
We characterize the emergent behavior of the swarm under the DMPC framework. The LA Slack Dt-CBF formulation governs both inter-robot separation and obstacle avoidance. We study three tasks, namely coordinated phototaxis, phototactic orbiting, and cohesion without a stimulus. Figure 5 shows representative snapshots at . The snapshots show how the local coupling terms regulate spatial density and heading agreement while each agent pursues its objective, without global communication or a central coordinator. With two and with twelve static obstacles in the arena, every behavior still holds its form while the swarm moves around the obstacles (Figure 8 and Figure 9 in Appendix § 5).
We assess coordination among the robots using two distinct metrics. The first is the polar order parameter calculated locally over only the set of active neighbors,
where is the set of active neighbors of each robot inclusive of the robot , and is the number of active neighbors for . When all the robots in every neighborhood are in near-perfect alignment, , whereas in a disordered state with random robot orientations, . This metric is widely used in biophysics to quantify order in a moving flock or swarm [8, 3]. The second metric is the nearest-neighbor distance averaged over all robots,
where is the nearest neighbor of robot . This metric finds pervasive use in quantifying internal group structure in natural and artificial flocks [64, 63]. While the NND varies with animal species, it unequivocally reaches a stable value at long time scales. The top and bottom rows of Figure 6 elucidate the variation in the local polar order and long-time NND for different swarm sizes and different obstacle numbers, under distinct modes of operation.
Phototaxis Behavior
We first examine the full DMPC formulation with all Reynolds steering rules (§ 2.5) active, demonstrating gradient-following behavior, followed by isolating the contribution of the social coupling by removing these terms entirely.
With Reynolds Flocking Rules – Collective Behavior
In phototaxis mode, each robot ascends the light gradient while the cohesion and alignment costs, together with the CBF separation constraints, produce collective motion. The CBF constrains the closing velocity toward each neighbor’s predicted position, so avoidance starts early, without the over-braking or deadlocks of purely reactive methods [53]. The swarm stays compact and heading-aligned as it tracks the rotating source (Figure 5a). The local polar order reduces with increasing swarm size, as radial phototaxis uses a convergent field that brings agents together from all directions, producing head-on encounters that locally cancel heading agreement (Figure 6a). A cluttered environment further worsen the alignment by introducing additional collision avoidance, which de-aligns the local heading. The NND (Figure 6d), on the other hand, decreases as the space for movement in the domain decreases (increasing swarm size), partly also attributable to the nature of the phototaxis mode, which attempts to converge the robots to a small location. Beyond , the NND falls below the safe buffer distance of , indicating some amount of buffer overlap. As the swarm size approaches the geometric packing limit, the phototaxis gradient forces the robots into oblique, blocking contacts, causing NND to fall as low as .
Without Reynolds Flocking Rules – Swarm Collapse
In the absence of the cohesion and alignment costs and the separation constraints, the collective behavior disappears. Each robot climbs the gradient on its own, so the swarm arrives at the light peak without spacing or heading agreement (Figure 5b). The swarm effectively collapses onto a small area in the domain, clearly attributing the occurrence of flocking to the Reynolds steering costs.
Phototactic Orbital Behavior
In the phototactic orbital mode, each robot follows the tangent of the sensed intensity level set through the gradient-rotation reference (9), orbiting the source without global localization. The CBF constraints (26) prevent collisions as robots compete for the same orbit while the cohesion and alignment costs keep the swarm compact and co-rotating. From arbitrary initial positions, it converges to a stable orbital formation (Figure 5c). Although the phototactic orbital mode is susceptible to crowding similar to the phototaxis mode, the decay of the local polar order is more muted in the former (Figure 6b). This is a direct consequence of the co-location of local neighbors along concentric orbital paths, leading to better heading agreement, even for large swarms. Similarly, the NND also settles slightly below the safe buffer distance even for , as the locally tangential motion along the orbital causes the robots to align along their major axes, allowing for sufficient separation among them (Figure 6e). Both metrics are only mildly affected by the addition of obstacles to the system.
Flocking in the Absence of Stimuli
In this mode, the light field is disabled, providing the robots no global stimulus. Hence, each robot holds its heading with a small random turn each step. The swarm drifts outward and settles into a band along the walls, with an empty interior (Figure 5d). Once a robot reaches a wall, it stays there until its heading drifts away, so the walls fill faster than they empty. Cohesion and alignment order the band, so the swarm circulates the arena similar to an edge current [62].

Figure 6. Local polar order (top row) and average nearest-neighbor distance (NND; bottom row) versus swarm size for the deployed LA Slack Dt-CBF, one column per collective behavior (10-seed mean with CI bands, steady state over the last ). The columns are phototaxis (a, d), phototactic orbiting (b, e), and cohesion without a stimulus (c, f). Each panel compares the obstacle-free arena, the few-obstacle arena ( obstacles), and the cluttered arena ( obstacles, positions randomized per seed). The dotted horizontal line marks the buffer distance of , while the vertical dashed line marks the geometric packing limit .
The flock remains relatively well-aligned at low swarm sizes, with heading disagreements as the domain starts getting crowded with robots and obstacles due to frequent steering for collision avoidance (Figure 6c). This is an expected outcome, showing that the alignment and cohesion costs work as intended. The band structure resembles the phototactic orbital, despite the difference in shape of the orbit. This is evident from the NND (Figure 6f), which follows a similar trend as in the phototactic orbital mode.
Collision Behavior Across Density and Tasks
The collision load of the deployed LA Slack Dt-CBF depends on both swarm size and task. We measure both here, across three obstacle environments.
Collisions versus swarm size
We sweep across three environments, namely obstacle-free, few-obstacle (), and cluttered (, positions randomized per seed). We count distinct robot-robot contacts over the -step run (Figure 7). Contacts stay negligible in small swarms. Free space averages contact at , with the nearest neighbor away on average, well above . Contacts then climb steeply, from at to at the packing limit, where the mean nearest-neighbor separation has fallen to . The growth is strongly linear. Contacts rise by a factor of between and while the robot count only doubles. Near the packing limit the full margin cannot be held for every pair, so the slacked CBF admits transient contacts while the solver stays feasible (§ 3.3).
Obstacles dominate in small swarms and hardly matter in large ones (Figure 7). At the cluttered arena produces three orders of magnitude more contacts than free space. By that gap has closed to a factor of , and by to . The crossover falls between and . The environment therefore dominates in small swarms, while in large swarms collisions come from the packing density.

Figure 7. Distinct contacts versus swarm size for the deployed LA Slack Dt-CBF. (a) Phototaxis, (b) phototactic orbiting, and (c) cohesion without a stimulus. Each panel compares the obstacle-free arena, the few-obstacle arena (), and the cluttered arena (, positions randomized per seed). The vertical axis is log-scaled. The dashed vertical line marks the packing limit . The band around each curve is the confidence interval over 10 seeds.
Effectiveness of avoidance is set by task geometry
Considering an identical controller, the number of contacts spans two orders of magnitude across the three behaviors, a factor of between the best and the worst at (Figure 7). Phototaxis concentrates the swarm at the peak intensity of the light source and has the highest number of contacts at . The orbital mode spreads robots along an intensity level set and has far fewer contacts at . Cohesion without a stimulus falls in between at . However, this order of effectiveness is not preserved across different swarm sizes. The stimulus-free mode is the worst in small swarm, with contacts at , whereas the other modes record none. The cause is how robots meet, not how crowded they are. At the stimulus-free swarm is the most spread out of the three, with a mean nearest-neighbor distance of against for phototaxis. The difference is in their headings. A shared gradient gives phototaxis and orbiting a common direction, so two robots that come close are already traveling the same way. Without a stimulus each robot follows its own random heading, and only the local coupling keeps neighbors together. In large swarms the same absence of a shared target protects it, since the robots never concentrate. At every larger swarm size orbiting stays safest and phototaxis worst, except in the cluttered arena where the stimulus-free mode moves ahead of orbiting at and . Obstacles raise contacts in every mode, but the orbital mode pays the largest penalty, at against for phototaxis. Obstacles sit directly on the orbit and force detours. The safety formulation decides how large a swarm can grow before contacts appear. The task decides how many contacts it has at any given size.
Computational Performance and Scalability
The experiments run one task per core on shared compute nodes, so other jobs on the same node could slow down the solve time. We repeated the measurement on an idle node reserved for this run alone. Averaged over the density sweep, each formulation’s mean agrees with its shared-node value to within , so sharing a node does not distort the per-robot times reported in § 3.3, and the idle run also gives the full distribution. Each solve covers the full per-robot control step, including both consensus iterations.
The mean and the th percentile stay well inside both the () and () budgets at every density. Across the six formulations peaks at , and at the operating densities it stays at or below . Worst-case single solves are larger and matter for a hard real-time guarantee. The maximum observed on the idle node is , so the budget is met at every density while the budget is not. These maxima are lone draws from the tail. They grow with only because a larger swarm performs more solves per run, from at to at , while the mean and do not grow. A deployment would therefore cap the solver iterations and fall back to the reactive controller on the rare overrun.
The per-step wall time necessarily grows with , since a single process advances all robots in sequence. It is at least times the per-robot cost, so , , and at . This is a simulation artifact. Each robot runs its own optimization onboard or in parallel when deployed, so the governing cost is the per-robot time. That cost is flat in (§ 3.3), so computation does not limit the swarm size. The current single-process simulation bottleneck can be removed through parallel execution and is left as future implementation work.
Conclusion
We presented a distributed predictive flocking controller for dense miniature ellipsoid robot swarms in a confined arena. Each robot solves a local NMPC combining task tracking, Reynolds-style flocking, and inter-robot and obstacle safety constraints, using only exchanged predicted trajectories of active neighbors, without a leader, central planner, or global map. The results demonstrate that the same controller architecture generalizes across different modal objectives such as gradient-ascending phototaxis, stable phototactic orbital formation, and even flocking in the absence of any stimulus. The emergent collective behavior arises purely from local optimization of cohesion and alignment costs, coupled with safety constraints that maintain separation. This separability between the task and the coordination points towards a modeling paradigm where new tasks can plausibly be added without necessarily re-deriving the safety features or coordination structure. Each robot optimizes against a fixed neighbor set, so solve time is in swarm size, measured at on average and flat across the density sweep, making the scaling limit architectural (a serial solve with a single workstation caps closed-loop control at roughly robots) rather than algorithmic.
Comparing six safety formulations under identical conditions showed that performance is determined by structure rather than barrier order; pairing a slacked barrier anchor with a rate condition reduces contact counts by a factor of relative to formulations without an anchor, with no overlap across the density sweep. Considering the phototaxis mode as the deployment target, the LA Slack Dt-CBF is found to be most effective in preventing collisions, while also providing the highest inter-robot margins for most swarm sizes tested. The look-ahead handle drives this improvement, giving the turn rate direct authority over the constraint so a robot can steer around a neighbor rather than only brake. Removing this handle alone raises contacts by up to a factor of at low density, and by at the geometric packing limit. Moreover, a higher-order rate chain improves performance further at moderate density but loses its advantage at the packing limit, showing that a higher barrier order does not automatically guarantee better safety.
The collective motion is analyzed through local polar order and NND analysis, which, apart from quantifying controller performance, also point toward a biomimetic reading of these results. The muted order decay and more efficient packing found for the orbital mode, versus the sharper degradation under phototaxis, mirror a structural distinction well documented in natural swarms: neighbors on a shared circulating path align through a shear-like velocity field, while neighbors converging on a common point align through a convergent one, with the latter being inherently more collision-prone and alignment-averse as group size grows. That our controller reproduces these qualitative results from local optimization alone, without it being an explicit design target, suggests the polar order and NND metrics already computed here could serve as a bridge to the natural flocking literature. Furthermore, the wall-following behavior observed in the absence of external stimuli concurs well with studies of natural fish schools and insect swarms in confined spaces, a systematic evaluation and comparison of which can open a path to tuning the flocking and safety weights toward biologically observed regimes rather than controller-internal ones.
The current work has two limitations. The vibration and friction induced locomotion of the real bristlebot is modeled only kinematically rather than physically, so variations involving surface, payload, and actuation asymmetry enter the controller only as unmodeled disturbance. The safety comparison is also internal by design: six formulations within one stack, which isolates the safety constraint but does not benchmark against external distributed-flocking baselines, most of which target fully actuated 3D quadrotors or underactuated 2D robots rather than vibration-driven platforms. Further extensions can be carried out in terms of optimization and learning; the slack weight, rate-condition horizon, and look-ahead distance form a compact design space suited to automated tuning against the contact-rate and feasibility metrics already collected here, while a learned residual dynamics model could absorb the friction disturbance currently left unmodeled, narrowing the gap between the kinematic model and the true vibration-driven actuation. Immediate next steps include physical validation on the GRASPion hardware, extension to dynamic obstacle avoidance, and robust or stochastic MPC formulations for stronger safety guarantees. Overall, these results establish a single, kinematic model-agnostic NMPC architecture that unifies task-driven behavior, emergent flocking, and safety against collisions, while the polar-order and NND signatures it reproduces open a concrete path toward grounding swarm-robotics control in the structure of natural collective motion.
Declaration of competing interest
The authors declare that they have no known competing financial interests or personal relationships that could have appeared to influence the work reported in this paper.
Data availability
No external data was used. The code and simulation environment that reproduce all results are available at https://github.com/prajolshrestha/bristlebot-swarm-mpc. The full set of simulation videos, including the full-length renders from which the supplementary videos are derived, is archived at https://doi.org/10.5281/zenodo.22642863.
Collective behaviors with static obstacles
Figure 8 and Figure 9 repeat the four panels of Figure 5 in cluttered arenas, with two and with twelve static obstacles. Each mode keeps the same qualitative behavior while the controller routes the swarm around the obstacles.

Figure 8. Collective behaviors with two static obstacles (LA Slack Dt-CBF formulation, ), one behavior per row. (a) Phototaxis, (b) phototaxis with the Reynolds coupling removed, (c) phototactic orbiting, and (d) cohesion without a stimulus. Columns are snapshots at , , , and . The red disks are the static obstacles and the orange field is the light source. Supplementary video 2 shows these four behaviors in the two-obstacle arena.

Figure 9. Collective behaviors with twelve static obstacles (LA Slack Dt-CBF formulation, ), one behavior per row. (a) Phototaxis, (b) phototaxis with the Reynolds coupling removed, (c) phototactic orbiting, and (d) cohesion without a stimulus. Columns are snapshots at , , , and . The red disks are the static obstacles and the orange field is the light source. Supplementary video 3 shows these four behaviors in the cluttered arena.
Supplementary data
Table 3 lists the complete set of controller, safety, environment, and simulation parameters used to produce every result, so the setup of § 3 is reproducible from the paper alone.
| Parameter | Value |
| Model and actuation bounds | |
| Arena | () |
| Position bounds | |
| Linear speed | |
| Angular rate | |
| Robot semi-axes | |
| Position, heading | |
| Speed, turn rate | |
| Control effort | |
| Cohesion, alignment | |
| Slack quadratic | |
| Slack linear | |
| Safe distance | |
| Decay (inter-robot) | |
| Decay (obstacle) | |
| Look-ahead handle | |
| Dt-HOCBF gains | |
| Dt-HOCBF obstacle gains | |
| Communication radius | |
| Max neighbors, obstacle slots | |
| Consensus iterations | |
| Obstacle sensing range | |
| Obstacle radius | |
| Obstacle counts (free/few/cluttered) | |
| Light spread , orbit radius | , |
| Source speed | |
| Behavior look-ahead , ref. speed | , |
| Horizon , control step | , |
| Episode length | steps () |
| Random seeds | |
| Integrator | ERK-4, 3 steps/interval |
| QP solver | acados SQP-RTI, HPIPM, Gauss-Newton |
Table 3. Complete controller, safety, environment, and simulation parameters used for all experiments. Robot-scale lengths are in cm, the arena and sensing ranges in m, and speeds in m/s; cost and slack weights are dimensionless. Values are those of the deployed LA Slack Dt-CBF; the cost weights, horizon, arena and platform limits are shared by every formulation, while , , and the slack weights are re-tuned per formulation (§ 3.1). The angular-rate bounds are asymmetric, reflecting the vibration-driven platform’s differing left- and right-turn authority.
References
- [1]Reynolds, C. W. (1987). Flocks, herds and schools: A distributed behavioral model. Proceedings of the 14th Annual Conference on Computer Graphics and Interactive Techniques, 25–34. https://doi.org/10.1145/37401.37406
- [2]Reynolds, C. W. (1999). Steering behaviors for autonomous characters. Proceedings of the Game Developers Conference 1999, 763–782.
- [3]Vicsek, T., & Zafeiris, A. (2012). Collective motion. Physics Reports, 517(3-4), 71–140.
- [4]Olfati-Saber, R. (2006). Flocking for multi-agent dynamic systems: algorithms and theory. IEEE Transactions on Automatic Control, 51(3), 401–420. https://doi.org/10.1109/TAC.2005.864190
- [5]Tanner, H. G., Jadbabaie, A., & Pappas, G. J. (2003). Stable flocking of mobile agents, part I: fixed topology. 42nd IEEE International Conference on Decision and Control (IEEE Cat. No.03CH37475), 2, 2010–2015Vol.2. https://doi.org/10.1109/CDC.2003.1272910
- [6]Jadbabaie, A., Lin, J., & Morse, A. S. (2003). Coordination of groups of mobile autonomous agents using nearest neighbor rules. IEEE Transactions on Automatic Control, 48(6), 988–1001. https://doi.org/10.1109/TAC.2003.812781
- [7]Vicsek, T., Czirók, A., Ben-Jacob, E., Cohen, I., & Shochet, O. (1995). Novel Type of Phase Transition in a System of Self-Driven Particles. Phys. Rev. Lett., 75, 1226–1229. https://doi.org/10.1103/PhysRevLett.75.1226
- [8]Couzin, I. D., Krause, J., James, R., Ruxton, G. D., & Franks, N. R. (2002). Collective Memory and Spatial Sorting in Animal Groups. Journal of Theoretical Biology, 218(1), 1–11. https://doi.org/10.1006/jtbi.2002.3065
- [9]Camazine, S., Deneubourg, J., Franks, N., Sneyd, J., Theraulaz, G., & Bonabeau, E. (2001). Self-Organization in Biological Systems. Princeton University Press.
- [10]Ballerini, M., Cabibbo, N., Candelier, R., Cavagna, A., Cisbani, E., Giardina, I., Lecomte, V., Orlandi, A., Parisi, G., Procaccini, A., Viale, M., & Zdravkovic, V. (2008). Interaction ruling animal collective behavior depends on topological rather than metric distance: Evidence from a field study. Proceedings of the National Academy of Sciences, 105(4), 1232–1237. https://doi.org/10.1073/pnas.0711437105
- [11]Strandburg-Peshkin, A., Twomey, C. R., Bode, N. W. F., Kao, A. B., Katz, Y., Ioannou, C. C., Rosenthal, S. B., Torney, C. J., Wu, H. S., Levin, S. A., & Couzin, I. D. (2013). Visual sensory networks and effective information transfer in animal groups. Current Biology, 23(17), R709–R711. https://doi.org/10.1016/j.cub.2013.07.059
- [12]Chen, Z., & Chu, T. (2013). Multi-agent system model with mixed coupling topologies for pattern formation and formation splitting. Mathematical and Computer Modelling of Dynamical Systems, 19(4), 388–400. https://doi.org/10.1080/13873954.2012.750614
- [13]Vásárhelyi, G., Virágh, C., Somorjai, G., Nepusz, T., Eiben, A. E., & Vicsek, T. (2018). Optimized flocking of autonomous drones in confined environments. Science Robotics, 3(20), eaat3536. https://doi.org/10.1126/scirobotics.aat3536
- [14]Yang, G.-Z., Bellingham, J., Dupont, P. E., Fischer, P., Floridi, L., Full, R., Jacobstein, N., Kumar, V., McNutt, M., Merrifield, R., Nelson, B. J., Scassellati, B., Taddeo, M., Taylor, R., Veloso, M., Wang, Z. L., & Wood, R. (2018). The grand challenges of Science Robotics. Science Robotics, 3(14), eaar7650. https://doi.org/10.1126/scirobotics.aar7650
- [15]Neuman, S. M., Plancher, B., Duisterhof, B. P., Krishnan, S., Banbury, C., Mazumder, M., Prakash, S., Jabbour, J., Faust, A., de Croon, G. C. H. E., & Reddi, V. J. (2022). Tiny Robot Learning: Challenges and Directions for Machine Learning in Resource-Constrained Robots. 2022 IEEE 4th International Conference on Artificial Intelligence Circuits and Systems (AICAS), 296–299. https://doi.org/10.1109/AICAS54282.2022.9870000
- [16]Novkoski, F., Mélard, M., Delens, M., Wéry, F., Noirhomme, M., Pande, J., Maier, A., Smith, A.-S., & Vandewalle, N. (2026). GRASPion: An open-source, programmable brainbot for active matter research. Review of Scientific Instruments, 97(1), 014704. https://doi.org/10.1063/5.0303152
- [17]Mammadli, I., Shrestha, P., Pande, J., Novkoski, F., Mohapatra, S., Noirhomme, M., Maier, A., Vandewalle, N., & Smith, A.-S. (2026). Physics-informed digital twin and onboard control of a brainbot for intelligent active matter. Physical Review Research, 8, 033164. https://doi.org/10.1103/rd1t-h2v6
- [18]Rawlings, J. B., Mayne, D. Q., & Diehl, M. M. (2017). Model Predictive Control: Theory, Computation, and Design. Nob Hill Publishing.
- [19]Van Parys, R., & Pipeleers, G. (2017). Distributed MPC for multi-vehicle systems moving in formation. Robotics and Autonomous Systems, 97, 144–152. https://doi.org/10.1016/j.robot.2017.08.009
- [20]Luis, C. E., Vukosavljev, M., & Schoellig, A. P. (2020). Online Trajectory Generation With Distributed Model Predictive Control for Multi-Robot Motion Planning. IEEE Robotics and Automation Letters, 5(2), 604–611. https://doi.org/10.1109/LRA.2020.2964159
- [21]Testa, A., Camisa, A., & Notarstefano, G. (2021). ChoiRbot: A ROS 2 Toolbox for Cooperative Robotics. IEEE Robotics and Automation Letters, 6(2), 2714–2720. https://doi.org/10.1109/LRA.2021.3061366
- [22]Pichierri, L., Testa, A., & Notarstefano, G. (2023). CrazyChoir: Flying Swarms of Crazyflie Quadrotors in ROS 2. IEEE Robotics and Automation Letters, 8(8), 4713–4720. https://doi.org/10.1109/LRA.2023.3286814
- [23]Zhou, X., Wen, X., Wang, Z., Gao, Y., Li, H., Wang, Q., Yang, T., Lu, H., Cao, Y., Xu, C., & Gao, F. (2022). Swarm of micro flying robots in the wild. Science Robotics, 7(66), eabm5954. https://doi.org/10.1126/scirobotics.abm5954
- [24]Kondo, K., Tewari, C. T., Tagliabue, A., Tordesillas, J., Lusk, P. C., Peterson, M. B., & How, J. P. (2025). PRIMER: Perception-Aware Robust Learning-Based Multiagent Trajectory Planner. 2025 IEEE International Conference on Robotics and Automation (ICRA), 14154–14160. https://doi.org/10.1109/ICRA55743.2025.11128011
- [25]Toumieh, C., & Floreano, D. (2024). High-Speed Motion Planning for Aerial Swarms in Unknown and Cluttered Environments. IEEE Transactions on Robotics, 40, 3642–3656. https://doi.org/10.1109/TRO.2024.3429193
- [26]Toumieh, C., & Lambert, A. (2022). Decentralized Multi-Agent Planning Using Model Predictive Control and Time-Aware Safe Corridors. IEEE Robotics and Automation Letters, 7(4), 11110–11117. https://doi.org/10.1109/LRA.2022.3196777
- [27]Şenbaşlar, B., & Sukhatme, G. S. (2025). DREAM: Decentralized Real-Time Asynchronous Probabilistic Trajectory Planning for Collision-Free Multirobot Navigation in Cluttered Environments. IEEE Transactions on Robotics, 41, 573–592. https://doi.org/10.1109/TRO.2024.3509015
- [28]Soria, E., Schiano, F., & Floreano, D. (2021). Predictive control of aerial swarms in cluttered environments. Nature Machine Intelligence, 3(6), 545–554. https://doi.org/10.1038/s42256-021-00341-y
- [29]Soria, E., Schiano, F., & Floreano, D. (2022). Distributed Predictive Drone Swarms in Cluttered Environments. IEEE Robotics and Automation Letters, 7(1), 73–80. https://doi.org/10.1109/LRA.2021.3118091
- [30]Nag, A., Huang, S., Themelis, A., & Yamamoto, K. (2022). Flock navigation with dynamic hierarchy and subjective weights using nonlinear MPC. 2022 IEEE Conference on Control Technology and Applications (CCTA), 1135–1140. https://doi.org/10.1109/CCTA49430.2022.9966067
- [31]Nag, A., & Yamamoto, K. (2024). Distributed control for flock navigation using nonlinear model predictive control. Advanced Robotics, 38(9-10), 619–631. https://doi.org/10.1080/01691864.2023.2299859
- [32]Gerdpratoom, N., & Yamamoto, K. (2025). Decentralized nonlinear model predictive control-based flock navigation with real-time obstacle avoidance in unknown obstructed environments. Frontiers in Robotics and AI, 12. https://doi.org/10.3389/frobt.2025.1540808
- [33]Kong, F., Chen, H., Li, H., Yan, J., Wang, X., & Fang, J. (2023). Flocking with Obstacle Avoidance for Fixed-Wing Unmanned Aerial Vehicles via Nonlinear Model Predictive Control. 2023 42nd Chinese Control Conference (CCC), 5957–5962. https://doi.org/10.23919/CCC58697.2023.10240689
- [34]Ames, A. D., Xu, X., Grizzle, J. W., & Tabuada, P. (2017). Control Barrier Function Based Quadratic Programs for Safety Critical Systems. IEEE Transactions on Automatic Control, 62(8), 3861–3876. https://doi.org/10.1109/TAC.2016.2638961
- [35]Agrawal, A., & Sreenath, K. (2017). Discrete control barrier functions for safety-critical control of discrete systems with application to bipedal robot navigation. Robotics: Science and Systems XIII. https://doi.org/10.15607/RSS.2017.XIII.073
- [36]Salimi Lafmejani, A., & Berman, S. (2021). Nonlinear MPC for collision-free and deadlock-free navigation of multiple nonholonomic mobile robots. Robotics and Autonomous Systems, 141, 103774. https://doi.org/10.1016/j.robot.2021.103774
- [37]Lindqvist, B., Mansouri, S. S., Agha-mohammadi, A.-. akbar ., & Nikolakopoulos, G. (2020). Nonlinear MPC for Collision Avoidance and Control of UAVs With Dynamic Obstacles. IEEE Robotics and Automation Letters, 5(4), 6001–6008. https://doi.org/10.1109/LRA.2020.3010730
- [38]Zeng, J., Zhang, B., & Sreenath, K. (2021). Safety-Critical Model Predictive Control with Discrete-Time Control Barrier Function. 2021 American Control Conference (ACC), 3882–3889. https://doi.org/10.23919/ACC50511.2021.9483029
- [39]Zeng, J., Li, Z., & Sreenath, K. (2021). Enhancing Feasibility and Safety of Nonlinear Model Predictive Control with Discrete-Time Control Barrier Functions. 2021 60th IEEE Conference on Decision and Control (CDC), 6137–6144. https://doi.org/10.1109/CDC45484.2021.9683174
- [40]Zeng, J., Zhang, B., Li, Z., & Sreenath, K. (2021). Safety-Critical Control using Optimal-decay Control Barrier Function with Guaranteed Point-wise Feasibility. 2021 American Control Conference (ACC), 3856–3863. https://doi.org/10.23919/ACC50511.2021.9482626
- [41]Minh, N. N., McIlvanna, S., Sun, Y., Jin, Y., & Van, M. (2024). Enhancing Mobile Robot Navigation Safety and Efficiency through NMPC with Relaxed CBF in Dynamic Environments. 2024 IEEE 20th International Conference on Automation Science and Engineering (CASE), 2308–2313. https://doi.org/10.1109/CASE59546.2024.10711662
- [42]Lu, Z., Feng, K., & Xu, J. (2024). Robot Safe Planning in Dynamic Environments Based on MPC Using Control Barrier Function. 2024 China Automation Congress (CAC), 3358–3363. https://doi.org/10.1109/CAC63892.2024.10864636
- [43]Wabersich, K. P., & Zeilinger, M. N. (2023). Predictive Control Barrier Functions: Enhanced Safety Mechanisms for Learning-Based Control. IEEE Transactions on Automatic Control, 68(5), 2638–2651. https://doi.org/10.1109/TAC.2022.3175628
- [44]Katriniok, A., Shakhesi, E., & Heemels, W. P. M. H. (2023). Discrete-Time Control Barrier Functions for Guaranteed Recursive Feasibility in Nonlinear MPC: An Application to Lane Merging. 2023 62nd IEEE Conference on Decision and Control (CDC), 3776–3783. https://doi.org/10.1109/CDC49753.2023.10384157
- [45]Xiao, W., & Belta, C. (2019). Control Barrier Functions for Systems with High Relative Degree. 2019 IEEE 58th Conference on Decision and Control (CDC), 474–479. https://doi.org/10.1109/CDC40024.2019.9029455
- [46]Nguyen, Q., & Sreenath, K. (2016). Exponential Control Barrier Functions for enforcing high relative-degree safety-critical constraints. 2016 American Control Conference (ACC), 322–328. https://doi.org/10.1109/ACC.2016.7524935
- [47]Huang, J., Liu, Z., Zeng, J., Chi, X., & Su, H. (2023). Obstacle Avoidance for Unicycle-Modelled Mobile Robots with Time-Varying Control Barrier Functions. IECON 2023- 49th Annual Conference of the IEEE Industrial Electronics Society, 1–6. https://doi.org/10.1109/IECON51785.2023.10312269
- [48]van den Berg, J., Guy, S. J., Lin, M., & Manocha, D. (2011). Reciprocal n-Body Collision Avoidance. In Robotics Research: The 14th International Symposium ISRR (Vol. 70, pp. 3–19). Springer. https://doi.org/10.1007/978-3-642-19457-3_1
- [49]Zhou, D., Wang, Z., Bandyopadhyay, S., & Schwager, M. (2017). Fast, On-line Collision Avoidance for Dynamic Vehicles Using Buffered Voronoi Cells. IEEE Robotics and Automation Letters, 2(2), 1047–1054. https://doi.org/10.1109/LRA.2017.2656241
- [50]Wang, L., Ames, A. D., & Egerstedt, M. (2017). Safety Barrier Certificates for Collisions-Free Multirobot Systems. IEEE Transactions on Robotics, 33(3), 661–674. https://doi.org/10.1109/TRO.2017.2659727
- [51]Mali, P., Harikumar, K., Singh, A. K., Krishna, K. M., & Sujit, P. B. (2021). Incorporating Prediction in Control Barrier Function Based Distributive Multi-Robot Collision Avoidance. 2021 European Control Conference (ECC), 2394–2399. https://doi.org/10.23919/ECC54610.2021.9655081
- [52]Wang, C., Zhang, S., & Wang, L. (2025). Distributed Safety-Critical MPC for Multi-Agent Formation Control and Obstacle Avoidance. 2025 IEEE 64th Conference on Decision and Control (CDC), 3288–3295. https://doi.org/10.1109/CDC57313.2025.11312786
- [53]Chandra, R., Zinage, V., Bakolas, E., Stone, P., & Biswas, J. (2025). Deadlock-free, safe, and decentralized multi-robot navigation in social mini-games via discrete-time control barrier functions. Autonomous Robots, 49(2), 12. https://doi.org/10.1007/s10514-025-10194-8
- [54]Goarin, M., Li, G., Saviolo, A., & Loianno, G. (2025). Decentralized Nonlinear Model Predictive Control for Safe Collision Avoidance in Quadrotor Teams with Limited Detection Range. 2025 IEEE International Conference on Robotics and Automation (ICRA), 5387–5393. https://doi.org/10.1109/ICRA55743.2025.11128389
- [55]Verschueren, R., Frison, G., Kouzoupis, D., Frey, J., Duijkeren, N. van ., Zanelli, A., Novoselnik, B., Albin, T., Quirynen, R., & Diehl, M. (2021). acados -- a modular open-source framework for fast embedded optimal control. Mathematical Programming Computation. https://doi.org/10.1007/s12532-021-00208-8
- [56]Frison, G., & Diehl, M. (2020). HPIPM: a high-performance quadratic programming framework for model predictive control. IFAC-PapersOnLine, 53(2), 6563–6569. https://doi.org/10.1016/j.ifacol.2020.12.073
- [57]Andersson, J. A. E., Gillis, J., Horn, G., Rawlings, J. B., & Diehl, M. (2019). CasADi -- A software framework for nonlinear optimization and optimal control. Mathematical Programming Computation, 11(1), 1–36. https://doi.org/10.1007/s12532-018-0139-4
- [58]Akiba, T., Sano, S., Yanase, T., Ohta, T., & Koyama, M. (2019). Optuna: A Next-Generation Hyperparameter Optimization Framework. The 25th ACM SIGKDD International Conference on Knowledge Discovery & Data Mining, 2623–2631. https://doi.org/10.1145/3292500.3330701
- [59]Bertsekas, D. P., & Tsitsiklis, J. N. (2015). Parallel and Distributed Computation: Numerical Methods. Athena Scientific.
- [60]Bentley, J. L. (1975). Multidimensional binary search trees used for associative searching. Communications of the ACM, 18(9), 509–517. https://doi.org/10.1145/361002.361007
- [61]Friedman, J. H., Bentley, J. L., & Finkel, R. A. (1977). An algorithm for finding best matches in logarithmic expected time. ACM Transactions on Mathematical Software, 3(3), 209–226. https://doi.org/10.1145/355744.355745
- [62]Beppu, K., Izri, Z., Sato, T., Yamanishi, Y., Sumino, Y., & Maeda, Y. T. (2021). Edge current and pairing order transition in chiral bacterial vortices. Proceedings of the National Academy of Sciences, 118(39), e2107461118. https://doi.org/10.1073/pnas.2107461118
- [63]Berlinger, F., Gauci, M., & Nagpal, R. (2021). Implicit coordination for 3D underwater collective behaviors in a fish-inspired robot swarm. Science Robotics, 6(50), eabd8668. https://doi.org/10.1126/scirobotics.abd8668
- [64]Partridge, B. L., & Pitcher, T. J. (1980). The sensory basis of fish schools: relative roles of lateral line and vision. Journal of Comparative Physiology, 135(4), 315–325. https://doi.org/10.1007/BF00657647