---
kind: concept
slug: control-barrier-function
title: Control barrier function (CBF)
summary: >-
  A barrier function defines a safe set as a superlevel set, and a controller keeps the state inside it. Backup CBF builds the safe set from a backup policy and filters the nominal input with a quadratic program. Learned CBFs in a differentiable QP layer, as in LiveNet, predict the barrier penalties with a network. Two sources, both with simulation results only.
tags: [safety, control, safety-filter, differentiable-qp]
papers: ["2412.04659", "2604.02401"]
related: [safety-filter, model-predictive-control, differentiable-optimization, imitation-learning]
status: draft
updated_at: 2026-10-25
---

## Overview

A control barrier function (CBF) is a scalar function h whose superlevel set
is a safe set. The safe set C is the superlevel set of h^C, and the terminal
set S_0 ⊆ C is the superlevel set of h^S [arxiv:2604.02401 §II-A] [eq. 2]
[eq. 3]. The goal is to keep the state in C for all time, starting from
states in a set D ⊆ C, even when the nominal controller does not guarantee
this [arxiv:2604.02401 §II-B].

The two cards use the term in different ways. The
[Backup-Based Safety Filters](/papers/2604.02401) review builds the barrier
from a backup policy and uses it inside a safety filter. The
[LiveNet](/papers/2412.04659) paper writes barrier constraints for collisions
and deadlocks into a QP layer on top of a neural controller, and a network
predicts the penalty terms in those constraints [arxiv:2412.04659 §4].

## Variants

### Backup CBF

The safe set is not written down by hand. It is the recoverable set of a
backup policy π_b over the horizon [0, T_B]: states that stay in C on the
whole interval and end in S_0 at time T_B [arxiv:2604.02401 §III] [eq. 6].
The paper cites a result from the literature. If S_0 is forward invariant
under the backup, this implicit set is controlled invariant and lies between
S_0 and C [arxiv:2604.02401 §III-A]. The backup policy must therefore keep
S_0 invariant and recover a neighbourhood of S_0 within T_B
[arxiv:2604.02401 §II-A]. Card: [Backup-Based Safety Filters](/papers/2604.02401).

The filter does not run the backup. At each step it solves a quadratic
program that changes the nominal input as little as possible, subject to
barrier constraints on the backup trajectory for all times in [t, t+T_B],
and on the terminal set [arxiv:2604.02401 §III] [eq. 10a] [eq. 10b] [eq. 10c].
The path constraints are a continuum, which the paper approximates with
finitely many collocation points [arxiv:2604.02401 §III-B]. The class-K
gain α is not specified in the paper [arxiv:2604.02401 §III-B].

### Learned collision and liveness CBFs in a QP layer

LiveNet trains one network per robot. The network outputs a reference
control u_ref and two sets of penalty terms, one for the collision barrier
and one for the liveness barrier. A QP layer then returns the control closest
to u_ref that satisfies the barrier rows [arxiv:2412.04659 §4]. Card:
[LiveNet](/papers/2412.04659).

- **Collision barrier.** For each other robot or static obstacle, the barrier
  is the squared distance minus the squared sum of radii. The inequality is
  second order in the control and contains two penalty terms
  [arxiv:2412.04659 §4.1]. The derivative of the penalty is set to zero
  [arxiv:2412.04659 §4.1].
- **Liveness barrier.** It is added only when the two heading rays cross. It
  compares the times at which each robot's critical point reaches the crossing
  point. The robot that goes second is held back. The path is fixed, so only
  speed enters the constraint [arxiv:2412.04659 §4.2].
- **Guarantee.** The paper's Theorem 1 gives liveness under the stated
  conditions, which include the penalty functions having the required
  relative degree [arxiv:2412.04659 §4.2]. The conclusion says the guarantee
  needs enough training data for the penalties to be learned
  [arxiv:2412.04659 §6].
- **Training.** Supervised learning on controls of a receding-horizon MPC that
  uses the same barrier functions [arxiv:2412.04659 §5.1].
- **Reported results.** In simulation with two robots, 0 collisions and 0
  deadlocks in 50 runs per scenario for the doorway and the intersection. The
  SMG-CBF baseline also had 0 collisions and 0 deadlocks [arxiv:2412.04659
  tab. 2]. The paper reports 10 to 20 times lower compute time per step than
  the specially designed optimisation baseline [arxiv:2412.04659 §1]. In 28
  perturbed doorway scenarios, LiveNet solved 25 and SMG-CBF solved 16
  [arxiv:2412.04659 §5.2].

Implementation notes from the released code, which differs from the paper in
the places below:

- **QP objective sign.** The paper writes the layer as maximising
  (u − u_ref)² [arxiv:2412.04659 §4]. The code minimises
  0.5 |u|² + u_refᵀu, so its unconstrained optimum is −u_ref
  [code: model.py#L100] [code: model.py#L268].
- **Liveness critical points.** The code builds the direction vector from
  swapped components, which places the critical points off the line between
  the robots. Use the paper's direction [code: model.py#L204-L206]
  [arxiv:2412.04659 §4.2].
- **Solver failure.** The paper does not say what happens if the QP cannot be
  solved. The code returns −u_ref, which breaks the guarantee
  [code: model.py#L271-L278].
- **Other robots' velocity.** The paper does not say how it is observed. The
  simulator estimates it by finite differences of position
  [arxiv:2412.04659 §4] [code: environment.py#L148]. A real robot must
  estimate it another way.
- **Penalty bounds.** The code bounds each penalty to (0, 4) through a
  sigmoid. The paper does not state a bound [code: model.py#L79].

### Other backup-based safety filters (not CBFs)

The same review compares Backup CBF with two other backup-based filters in
one framework. Model Predictive Shielding (MPS) tests a single switch time,
T_S = Δt, and accepts or rejects the nominal input as a whole [arxiv:2604.02401
§IV] [eq. 12] [eq. 13]. Gatekeeper searches for the largest valid switch time
in [0, T_H] and keeps the nominal input while that time is positive
[arxiv:2604.02401 §V] [eq. 15] [eq. 16]. The safety-filter
concept page is not written yet. The review proves that MPS
is a special case of gatekeeper when Δt ≤ T_H [arxiv:2604.02401 §VI-A]
[eq. 19].

## When to use which

Both sources report simulation results only. Their scenarios and metrics
differ, so their numbers should not be compared with each other.

| Situation | Use | Why |
|---|---|---|
| You want a QP-based filter that changes the nominal input as little as possible, and you have a backup policy | Backup CBF | It solves a QP with barrier constraints on the backup path [arxiv:2604.02401 §III]. |
| You want the nominal controller to run as long as safety allows, and can search a switch time | Gatekeeper, not Backup CBF | In the reach-avoid scenario it kept the nominal controller on 87.5% of steps, against 28.8% for Backup CBF [arxiv:2604.02401 tab. 2]. |
| You need a low per-step cost and accept a coarser filter | MPS or a parallel gatekeeper | Average time was 2.64 ms (MPS) and 2.97 ms (parallel gatekeeper) for highway overtake, against 27.90 ms for Backup CBF [arxiv:2604.02401 tab. 2]. |
| The backup cannot reach S_0 within T_B from the states you care about | Not stated | The paper gives no rule for this case. Validity depends on the backup and the model [arxiv:2604.02401 §VI-C]. |
| Several robots must pass each other in a narrow space, and you can produce expert MPC controls for training | Learned collision and liveness CBFs | The paper reports no collisions or deadlocks in its simulated doorway and intersection runs, with compute far below the optimisation baseline [arxiv:2412.04659 tab. 2] [§1]. |
| Path deviation is the metric that matters most | Check the baseline first | In the doorway, SMG-CBF changed the path less than LiveNet (0.001 m against 0.008 m). LiveNet changed speed less (0.002 m/s against 0.009 m/s) [arxiv:2412.04659 tab. 2]. |
| Hardware deployment with more than two robots | Not stated | The paper tests two robots in simulation only and defers real deployment [arxiv:2412.04659 §6]. |

The review says that Backup CBF and MPS both judge safety through the backup
maneuver. This can make them give up the nominal controller when it would be
safe. The paper calls this a shared weakness of the backup-based approach
[arxiv:2604.02401 §V-A] [§VI-C].

## Implementation sketch

Language-agnostic outlines of two CBF steps. Exact constraint forms are in the
cited equations and sections; check them there before coding. The class-K
gains of the Backup CBF are a free choice, not stated by the paper.

```pseudocode
# Backup CBF step  [arxiv:2604.02401 §III] [eq. 10a-c]
# Input:  state (x); nominal input (u_nom); backup policy (pi_b)
#         horizon (T_B); collocation times; barrier functions (h^C, h^S)
# Output: filtered input

def backup_cbf_input(x, u_nom, pi_b, T_B, times):
    # Solve for the input closest to the nominal one  [eq. 10a]
    u = qp_solve(objective=distance_to(u_nom))
    # Barrier constraints on the backup path at each collocation time  [§III-B]
    for tau in times:
        add_constraint(barrier_on_backup_path(x, u, pi_b, tau))
    # Terminal barrier constraint at the end of the backup  [eq. 10c]
    add_constraint(terminal_barrier(x, u, pi_b, T_B))
    return u
```

```pseudocode
# Learned-penalty CBF step for one robot  [arxiv:2412.04659 §4]
# Input:  own state (ego); observed other robots (others); trained net (F)
# Output: control u = (omega, a)

def learned_cbf_step(ego, others, F):
    # Network outputs a reference control and two penalty sets  [§4]
    u_ref, p_collision, p_liveness = F(ego, others)
    rows = []
    # Second-order collision barrier per other robot or obstacle  [§4.1]
    for other in others:
        rows.append(collision_cbf_row(ego, other, p_collision))
    # First-order liveness barrier only where the heading rays cross  [§4.2]
    for other in others:
        row = liveness_cbf_row(ego, other, p_liveness)
        if row is not None:
            rows.append(row)
    # Control closest to u_ref that satisfies all barrier rows  [§4]
    return qp_solve(u_ref, rows)
```

## Contradictions

- **Lie derivative sign.** The paper writes the second Lie derivative of the
  collision barrier with cos(θ^i + θ^j) [arxiv:2412.04659 §4.1] [code:
  model.py#L129]. A hand derivation from the drift alone gives
  cos(θ^i − θ^j). This was not checked numerically, and the paper does not
  settle it. Check the sign before implementing [arxiv:2412.04659 §4.1].
- **Headline versus table.** The paper's ratio of invasiveness reduction holds
  only in the doorway. In the intersection, the two methods' speed changes are
  0.011 m/s (LiveNet) and 0.012 m/s (SMG-CBF) [arxiv:2412.04659 tab. 2].
- **Between the two papers.** No direct disagreement. The review and LiveNet
  test different scenarios, so the claims are not comparable.

## Papers

- [Comparative review of backup-based safety filters (2026)](/papers/2604.02401): compares Backup CBF, MPS and gatekeeper in one framework, and proves MPS is a special case of gatekeeper.
- [LiveNet: Robust, Minimally Invasive Multi-Robot Control for Safe and Live Navigation in Constrained Environments (2024)](/papers/2412.04659): a neural controller whose outputs feed a QP layer with learned collision and liveness CBFs for two robots.
