CBF Lab

Interactive Educational Platform for Control Barrier Functions - Explore Safety-Critical Control Theory

2D Point Robot with Obstacle Avoidance

Watch the robot navigate safely around obstacles using Control Barrier Functions. Includes automatic deadlock resolution when the robot gets stuck at saddle points. Click on the canvas to set a new goal position.

1.25
Min CBF Value h(x)
SAFE
Safety Status
0%
Control Modification
OFF
Deadlock Resolution

Interactive Elements:

  • Green Robot - Safe, nominal control active
  • Orange Robot - CBF safety filter modifying control
  • Purple Robot - Infeasible constraints, emergency stop
  • Red Robot - Constraint violated (collision)
  • Red Obstacles - Click and drag to reposition
  • Dashed Circle - Safe set boundary
  • Blue Trail - Robot trajectory
  • Gray Arrow - Nominal control (desired)
  • Orange Arrow - CBF-filtered safe control

Click on canvas to set new goal position!

CBF Theory & Visualization

Control Barrier Function Mathematics:

Safety Set Definition:

$$\mathcal{C} = \{x \in \mathbb{R}^n : h(x) \geq 0\}$$

The safe set $\mathcal{C}$ contains all states where the barrier function is non-negative.

Barrier Function (Squared Distance Formulation):

$$h(x) = \|x - x_{obs}\|^2 - r_{safe}^2$$

Using squared distance $\|x - x_{obs}\|^2$ eliminates numerical issues and provides smooth gradients everywhere.

CBF Safety Constraint:

$$\dot{h}(x) + \alpha h(x) \geq 0$$

This ensures that if $h(x) > 0$ (safe), then $h(x)$ cannot decrease too rapidly toward the unsafe region.

Lie Derivative Expansion:

$$\dot{h}(x) = \nabla h(x) \cdot f(x) + \nabla h(x) \cdot g(x) u$$

For single integrator: $f(x) = 0$, $g(x) = I$, so $\dot{h} = \nabla h \cdot u$.

Gradient (Continuous & Smooth):

$$\nabla h(x) = 2(x - x_{obs})$$

Linear in distance, no singularities, computationally efficient.

Control Constraint:

$$u \in \{v \in \mathbb{R}^m : \nabla h(x) \cdot v \geq -\alpha h(x)\}$$

Any control satisfying this constraint ensures forward invariance of the safe set.

Key Advantages of Squared Distance CBF:
• Continuous gradients (no division by zero)
• Better numerical conditioning
• Smoother control synthesis
• $\alpha > 0$ controls how aggressively the system stays safe

Double Integrator with HOCBF

250
Position
0
Velocity
100
h₀(x)
0
Control u

HOCBF Theory

High-Order Control Barrier Functions:

For higher-order dynamics like double integrator $\ddot{x} = u$, we need High-Order CBFs because control doesn't appear directly in $\dot{h}_0$. We recursively construct barriers.

System Dynamics:

$$\begin{align} \dot{x} &= v \\ \dot{v} &= u \end{align}$$

Double integrator with position $x$, velocity $v$, and control $u$.

Zeroth-Order Barrier (Position Constraint):

$$h_0(x) = x - x_{obs}$$

Original safety constraint: stay away from obstacle at $x_{obs}$.

Relative Degree Issue:

$$\dot{h}_0 = \frac{\partial h_0}{\partial x} \dot{x} = 1 \cdot v = v$$

Control $u$ doesn't appear in $\dot{h}_0$! We need higher-order differentiation.

First-Order Barrier Construction:

$$h_1(x,v) = \dot{h}_0 + \alpha_1 h_0 = v + \alpha_1(x - x_{obs})$$

Combine velocity with scaled position constraint.

HOCBF Safety Constraint:

$$\dot{h}_1 + \alpha_2 h_1 \geq 0$$

Control Derivation:

$$\begin{align} \dot{h}_1 &= \frac{\partial h_1}{\partial x} \dot{x} + \frac{\partial h_1}{\partial v} \dot{v} \\ &= \alpha_1 v + 1 \cdot u = u + \alpha_1 v \end{align}$$

Final Control Constraint:

$$u \geq -\alpha_1 v - \alpha_2 h_1$$

Now control $u$ appears explicitly and can enforce safety!

Key Properties:
• $\alpha_1, \alpha_2 > 0$ ensure exponential stability
• Higher relative degree requires recursive barrier construction
• Maintains safety for dynamic systems with momentum
• Enables smooth braking before hitting constraints

Multi-Agent Collision Avoidance

Explore various multi-agent formations and bio-inspired scenarios using Control Barrier Functions for safety. Try different formation types and shepherding scenarios to see how agents navigate complex scenarios while maintaining safety. Use the dropdown to select different formation challenges and herding simulations.

45
Min Distance
0
Active CBFs
0
Collisions

Multi-Agent CBF Mathematics:

Inter-Agent Distance Constraint:

$$h_{ij}(x_i, x_j) = \|x_i - x_j\|^2 - d_{safe}^2 \geq 0$$

Agents $i$ and $j$ must maintain squared distance greater than safety threshold.

Lie Derivative for Agent $i$:

$$\dot{h}_{ij} = \nabla_{x_i} h_{ij} \cdot \dot{x}_i + \nabla_{x_j} h_{ij} \cdot \dot{x}_j$$ $$= 2(x_i - x_j) \cdot u_i + 2(x_j - x_i) \cdot u_j$$ $$= 2(x_i - x_j) \cdot (u_i - u_j)$$

Distributed CBF Constraint:

$$\dot{h}_{ij} + \alpha h_{ij} \geq 0$$ $$2(x_i - x_j) \cdot (u_i - u_j) + \alpha h_{ij} \geq 0$$

Decentralized Implementation:

$$2(x_i - x_j) \cdot u_i \geq -\frac{\alpha}{2} h_{ij} + 2(x_i - x_j) \cdot u_j^{nom}$$

Each agent assumes others follow nominal control $u_j^{nom}$ and takes half responsibility.

QP Formulation for Agent $i$:

$$\begin{align} \min_{u_i} &\quad \|u_i - u_i^{nom}\|^2 \\ \text{s.t.} &\quad 2(x_i - x_j) \cdot u_i \geq -\frac{\alpha}{2} h_{ij}, \; \forall j \neq i \end{align}$$

Key Features:
• Distributed: each agent computes own control
• Scalable: $O(n)$ constraints per agent for $n$ agents
• Reciprocal: both agents share avoidance responsibility
• Real-time: efficient QP solution for large swarms