Open source · JAX

Control barrier functions
for robotics, in JAX.

A Control Barrier Function toolbox built on JAX. Safety filters for deterministic, disturbed, and stochastic dynamics — with MPPI planning, Monte Carlo verification, and code generation for new systems.

March 2026
Mitchell Black, Georgios Fainekos, Bardh Hoxha, Hideki Okamoto, Danil Prokhorov
Scroll

As robots move from controlled lab environments into the real world — navigating city streets, sharing factory floors with humans, and flying through cluttered airspace — the question is no longer can they work, but can we guarantee they are safe?

Classical control gives us stability. Machine learning gives us adaptability. But neither alone provides formal safety guarantees at runtime — the mathematical promise that a robot will never collide, never exceed a boundary, never enter a dangerous state, regardless of what its nominal controller wants to do.

This is the domain of Control Barrier Functions (CBFs): a framework that acts as a safety filter on top of any controller, solving a constrained optimization problem at each timestep to find the closest safe action to the desired one. The theory is elegant. The implementations have historically been painful — slow, inflexible, and difficult to extend.

CBFKit addresses this. It is built on JAX, so the safety filter is automatically differentiable, JIT-compiled, and vectorizable — the same code runs a single controller or thousands of Monte Carlo rollouts in parallel.

Composable Safety by Design

Every component in CBFKit is a pure function. No class hierarchies, no inheritance chains — just composable building blocks that you snap together into a simulation pipeline.

Planner
MPPI / RRT*
Nominal Ctrl
Goal reaching
Safety Filter
CBF-CLF-QP
Dynamics
f(x) + g(x)u
Integrator
RK4 / Euler
Sensor
Noisy / perfect
Estimator
EKF / UKF

The safety filter sits at the heart of the pipeline. It receives the nominal control signal — whatever your planner or tracking controller wants to do — and solves a Quadratic Program to find the minimally invasive correction that keeps the system within its safe set. If the nominal command is already safe, it passes through unchanged. If not, the CBF bends it just enough.

minu ‖u − unom‖² subject to ḣ(x, u) + α(h(x)) ≥ 0
CBF-QP: find the closest safe action to the desired one

JAX Under the Hood

Built on JAX from the ground up. Automatic differentiation for barrier gradients. JIT compilation for real-time loop performance. vmap for massively parallel Monte Carlo safety verification.

<2ms
Per-step CBF-QP solve
1000+
Parallel Monte Carlo trials
100%
Safety rate across parameter sweeps
0
Barrier violations in benchmarks

Every Tile Is a Runnable Example

Each animation below is rendered by a script in the repository — open a tile to read the source it came from.

Express Safety in a Few Lines

CBFKit's functional API lets you define dynamics, barriers, and controllers as composable building blocks. A complete safe simulation in under 40 lines.

unicycle_reach_goal.py
import jax.numpy as jnp
import cbfkit.simulation.simulator as sim
import cbfkit.systems.unicycle.models.accel_unicycle as unicycle
from cbfkit.controllers.cbf_clf import vanilla_cbf_clf_qp_controller
from cbfkit.certificates import concatenate_certificates, rectify_relative_degree
from cbfkit.certificates.conditions.barrier_conditions import zeroing_barriers

# 1. Define dynamics
dynamics = unicycle.plant(lam=1.0)

# 2. Define a nominal goal-reaching controller
nom_controller = unicycle.controllers.proportional_controller(
    dynamics=dynamics, Kp_pos=1.0, Kp_theta=1.0
)

# 3. Define obstacles and barrier functions
barriers = [
    rectify_relative_degree(
        function=ellipsoid_cbf(center, radii),
        system_dynamics=dynamics,
        state_dim=4, form="high-order",
    )(certificate_conditions=zeroing_barriers.linear_class_k(5.0))
    for center, radii in obstacles
]

# 4. Compose the safety filter
controller = vanilla_cbf_clf_qp_controller(
    control_limits=jnp.array([100.0, 100.0]),
    dynamics_func=dynamics,
    barriers=concatenate_certificates(*barriers),
)

# 5. Run the simulation — JIT-compiled for real-time speed
x, u, z, p, *_ = sim.execute(
    x0=jnp.array([0.0, 0.0, 0.0, 0.785]),
    dt=0.01, num_steps=1000,
    dynamics=dynamics, controller=controller,
    nominal_controller=nom_controller,
    use_jit=True,
)

Beyond Vanilla CBFs

Real-world robots face noise, disturbances, and model uncertainty. CBFKit provides a spectrum of CBF formulations that match the right safety guarantee to the right problem.

Vanilla CBF

ḣ(x,u) + α(h(x)) ≥ 0
The classic formulation. Exponential and high-order relative degree support for systems where the barrier function does not have direct control authority.

Robust CBF

ḣ(x,u) + α(h(x)) ≥ supw ‖Mw‖
For systems with bounded disturbances dx = f(x) + g(x)u + Mw. The barrier condition tightens to account for worst-case perturbations.

Stochastic CBF

Lh(x,u) + α(h(x)) ≥ β
For stochastic differential equations dx = (f + gu)dt + σdw. Safety guarantees hold in expectation over the diffusion term.

Risk-Aware CBF (CVaR)

CVaRα[h(xt+1)] ≥ γ
Adaptive Conditional Value-at-Risk formulation. Safety is defined over the tail of the distribution — guarding against rare catastrophic events.

All formulations share the same compositional API. You can concatenate multiple barriers (obstacle avoidance + workspace bounds + inter-robot separation) into a single QP, swap in a different solver backend (jaxopt, cvxopt, or casadi), and switch between deterministic and stochastic dynamics — all without changing the rest of your pipeline.

MPPI Meets Safety Filters

Sampling-based planning for complex environments, with CBF safety filtering on the executed trajectory. The best of both worlds.

Model Predictive Path Integral (MPPI) control generates candidate trajectories by sampling thousands of control sequences in parallel, weighting them by a user-defined cost function. CBFKit's MPPI implementation runs entirely in JAX — meaning the sampling, rollout, and cost evaluation are all JIT-compiled and GPU-acceleratable.

The MPPI planner outputs a reference trajectory. At each timestep, the CBF safety filter intervenes only if needed, ensuring that the executed control never violates the barrier constraints. This decouples planning quality from safety — you get aggressive, cost-optimal plans with ironclad safety guarantees.

1000+ parallel samples
Roll out thousands of candidate trajectories simultaneously using JAX's vectorization primitives. GPU acceleration makes this practical for real-time use.
JIT-compiled cost functions
Define stage and terminal costs as standard Python functions. JAX traces and compiles them once, then executes at native speed for every sample.
STL specifications
Express complex temporal objectives with Signal Temporal Logic. Reach region A within 5 seconds, then stay in region B for 3 seconds — all encoded as MPPI cost terms.

GPU-Accelerated Monte Carlo Safety Verification

Don't just simulate once. Simulate a thousand times in parallel and statistically verify that your controller is safe.

CBFKit's Monte Carlo engine uses jax.vmap to run hundreds to thousands of simulations simultaneously — each with different initial conditions, noise realizations, or disturbance profiles. The result is a statistical safety certificate: violation rates, minimum barrier values, and success probabilities across your entire operating envelope.

Combined with the Optuna-powered parameter sweep engine, you can automatically search for the CBF and class-K function parameters that maximize performance while maintaining zero safety violations. The sweep engine tracks per-trial metrics and produces structured JSON results for downstream analysis.

From Single Integrators to 6-DOF Quadrotors

Eight ready-to-use robotic systems with dynamics, controllers, and barrier functions. Start running experiments in minutes, not days.

Unicycle
Mobile robot with acceleration control. Reach-goal, reach-avoid, and obstacle avoidance examples.
CBF MPPI Stochastic Risk-Aware
Single Integrator
First-order dynamics in 2D, 3D, or N-D. The simplest testbed for barrier function research.
2D/3D/ND EKF UKF
Quadrotor 6-DOF
Full six-degree-of-freedom dynamics with geometric and proportional controllers. Multi-robot coordination.
3D Multi-Robot Geometric Ctrl
Fixed-Wing UAV
Beard 2014 kinematic model. Reach-and-drop-point missions with 3D obstacle avoidance.
3D Flight Missions
Pedestrian
Multi-agent pedestrian dynamics with crowd navigation scenarios: crossing, overtaking, head-on, and starburst.
Multi-Agent Crowd Nav
Van der Pol Oscillator
Nonlinear limit-cycle dynamics. Lyapunov regulation with fixed-time, stochastic, and risk-aware variants.
Lyapunov Stochastic
Differential Drive
Obstacle avoidance and human-aware navigation with barrier-activated and augmented CBF modes.
Human-Aware Dynamic Obs
Double Integrator
Position + velocity state space. Used in adaptive CVaR-CBF controller development and testing.
CVaR Adaptive

Three Backends, One API

From interactive exploration to publication-quality renders. Choose the visualization backend that fits your workflow.

Plotly
Interactive 3D HTML visualizations. Rotate, zoom, and inspect trajectories in the browser. Default backend.
Matplotlib
High-quality MP4 and GIF export. Publication-ready trajectory plots with obstacle rendering.
Manim
3D mathematical animations with distance-metric panels, safety bubbles, and camera motion.

The unified CBFAnimator class provides a single interface across all three backends. Visualize 2D trajectories, 3D multi-robot coordination with distance-to-goal panels, minimum inter-robot distance tracking, and per-robot safety metrics — all generated from the same simulation results.

Generate New Systems Automatically

Define dynamics as symbolic expressions. CBFKit's code generator builds a complete system module with controllers, barriers, and ROS 2 nodes.

The code generation engine uses Jinja2 templates to transform symbolic dynamics definitions into fully typed Python modules. Specify your drift dynamics as string expressions, provide a control matrix, and list your barrier function formulas. CBFKit generates a complete package: plant model, barrier functions with automatic differentiation, Lyapunov functions, and optionally ROS 2 nodes for deployment.

This is how multi-robot coordination scales. Instead of hand-coding N(N-1)/2 inter-robot collision avoidance barriers, you define the pattern once and generate for any number of agents. The 3D multi-robot tutorial demonstrates this with 4 robots, 6 pairwise collision barriers, and 4 obstacle barriers — all auto-generated and composed into a single QP.

Tutorials for Every Level

From first barrier function to multi-robot 3D reach-avoid with MPPI. Each tutorial builds on the last.

01
Code Generation Tutorial
Generate a Van der Pol oscillator system from scratch — dynamics, controllers, barriers, and ROS 2 nodes.
02
Multi-Robot Coordination
N-robot collision avoidance with inter-robot CBF constraints. Composable barrier packaging for scalable multi-agent safety.
03
MPPI + CBF Reach-Avoid
Sampling-based planning with safety filtering. Navigate complex obstacle fields with formal guarantees.
04
MPPI + STL Specifications
Signal Temporal Logic objectives encoded as MPPI cost terms. Express complex time-bounded reach-avoid missions.
05
Dynamic Obstacles
Single integrator with moving obstacles. Time-varying barrier functions that track obstacle state.
06
3D Multi-Robot Reach-Avoid
The full stack: 4 robots in 3D, MPPI planning, CBF safety, code generation, and Manim visualization.

Get started

CBFKit is open source and ready for your research. Install it in one line, run an example in five minutes.

pip install "cbfkit @ git+https://github.com/bardhh/cbfkit.git"