BarrierFormer: Transformer-Guided Predictive Barrier Enforcement for Safe Robot Control

Arizona State University
Conference on Robot Learning (CoRL) 2026

Overview of BarrierFormer. In Step 1, a causal transformer autoregressively generates a finite-horizon predictive rollout via the action and dynamics heads, reconstructing each predicted observation as $\hat{\mathbf{o}} = o(\hat{\mathbf{x}})$. In Step 2, a barrier critic $h_\phi$ evaluates DTCBF constraint violations along those predicted observations.

Abstract

Control barrier functions (CBFs) have become one of the most popular tools for encoding and enforcing state constraints in safety-critical robotics. Standard CBF approaches are inherently myopic in nature as they enforce safety only at the current time step. Consequently, the system can be driven toward the boundary of the safe set where no feasible safe control exists at a future timestep. Model predictive control (MPC) based approaches address this by enforcing state constraints over a receding horizon. However, such approaches generally require the model to be known for solving a constrained optimization problem at every step, which is computationally expensive for real-time deployment. We propose BarrierFormer, a barrier-supervised transformer framework that addresses these limitations by encoding rollout-level CBF constraints in learning a model-free safe policy. A causal transformer encodes observation-action history, autoregressively generates a predictive rollout through the dynamics head to replace the model, and provides a residual correction to a nominal controller through the action head to replace the online computation. A barrier critic operating on local observations evaluates CBF constraint violations along this rollout, and a safety teacher computes barrier-consistent actions satisfying these constraints as direct supervision targets for the learned control policy. During inference, the policy maps observation-action history to control actions without any online optimization or model knowledge, enabling real-time model-free predictive safety enforcement. Evaluations across linear and nonlinear, 2D and 3D dynamical systems for safe goal-directed navigation demonstrate that BarrierFormer outperforms existing reinforcement learning (RL)-based, diffusion-based, MPC-based, and transformer-based approaches in safety rate and inference latency.

Method

The agent has no prior knowledge of obstacle locations and perceives its environment through $n_\text{rays}$ evenly-spaced LiDAR rays within a fixed sensing radius $R$. A single observation is therefore insufficient to characterize the safety of the current state: the agent may be currently safe but on a trajectory toward an obstacle that has not yet entered its sensing range. BarrierFormer enforces the barrier condition over a predicted rollout rather than pointwise at the current state.
    • Problem setting: The agent follows $\mathbf{x}_{t+1} = f(\mathbf{x}_t) + g(\mathbf{x}_t)\mathbf{u}_t$ but observes only $\mathbf{o}_t = o(\mathbf{x}_t) = (\mathbf{x}_t,\; \mathbf{p}_\text{goal} - \mathbf{p}_t,\; \mathbf{y}_{t,1}, \ldots, \mathbf{y}_{t,n_\text{rays}})$: its own state, the goal-relative position, and per-ray LiDAR features. The policy sees just the observation-action history $\mathcal{H}_t$ of length $T$, and must both stay safe, $d(\mathbf{p}_t, \mathcal{O}_i) \geq r$ for all $M$ obstacles, and reach the goal, $\inf_{t \geq 0} \|\mathbf{p}_t - \mathbf{p}_\text{goal}\| = 0$.
    • Why pointwise CBFs fall short: The DTCBF condition $h(\mathbf{o}^+) - h(\mathbf{o}) \geq -\alpha(h(\mathbf{o}))$ constrains a single transition, so satisfying it at every step can still drive the system into a state where no safe action remains. BarrierFormer instead enforces $h(\mathbf{o}_{t+k+1}) \geq (1-\gamma)\, h(\mathbf{o}_{t+k})$ across a horizon $k = 0, \ldots, H-1$. Note the barrier is defined on observations, not full states.
    • Step 1: Autoregressive rollout. A GPT-2-style causal transformer encodes $\mathcal{H}_t$ into a latent $\mathbf{z}_t$ feeding two heads: an action head that outputs a residual correction to a nominal controller $\mu_\text{nom}$, and a dynamics head that predicts a state increment. Each predicted state is mapped back through the observation model, $\hat{\mathbf{o}} = o(\hat{\mathbf{x}})$, using only obstacles encountered so far, not a global map. Iterating this generates the predictive rollout, standing in for the model that MPC would require.
    • Step 2: Barrier critic. A critic $h_\phi$ maps each predicted observation to a barrier value, which is what makes it usable under partial observability. Per-step violations are aggregated across the horizon by a smooth log-sum-exp of the worst case.
    • SQP safety teacher: A sequential quadratic program computes the minimal correction to $\mu_\text{nom}$ that satisfies every horizon barrier constraint. Only its first action is kept, as the supervision target for the action head. It runs during training only.
    • Data labeling: Because a collision-free state can still be doomed, labels come from the states that follow an observation in the same stored rollout: an observation is safe only if its state and all subsequent $T_\text{label} = 32$ steps are collision-free, unsafe if the state is in collision, and otherwise left unlabelled.
    • Training and deployment: All components train jointly under actor, dynamics, and barrier losses. At deployment, Step 2 is gone: the transformer maps history straight to actions, with no SQP, no rollout, no online optimization, and no model.

Seeing the Predicted Rollout

The predictive horizon, visualized. The left panel shows the full workspace: the agent (blue) executes the trajectory in solid blue toward the goal (green star), while the orange dashed line is the $H = 6$ step plan predicted by the transformer at that instant. The right panel zooms in on the agent, showing its LiDAR rays and the numbered steps of that predicted plan. This rollout is what the barrier critic evaluates during training, and it is precisely what a myopic, single-step CBF never looks at.

Double Integrator, $4 \times 4$ workspace, 12 obstacles.

BarrierFormer on the training distribution ($l = 4$ workspace, 8 obstacles). The agent perceives obstacles only through LiDAR rays within its sensing radius $R = 0.5$ and has no prior knowledge of obstacle locations. Safety is enforced purely by the policy parameters, with no safety filter, no online optimization, and no model at inference.

Double Integrator (2D, linear)

Dubins Car (2D, nonlinear)

Evaluations

We evaluate BarrierFormer on three dynamical systems: one linear (Double Integrator, DI) and two nonlinear (Dubins Car, DC and Crazyflie, CF). The safety rate is the fraction of episodes in which the robot never collides with an obstacle; the reaching rate is the fraction in which it reaches its goal; the success rate requires both. All results are reported as mean $\pm$ std over 3 random seeds $\times$ 32 environments. We compare against four baselines spanning three model-free paradigms and one model-based paradigm: CBF-RL (RL-based), CoBL-Diffusion (diffusion-based), ConBaT (transformer-based), and MPC (model-based). All baselines are re-implemented in our framework using the same dynamics, observation model, and obstacle configurations.

Performance comparison in terms of safety rate (Safe), goal reaching rate (Reach), success rate (Success) and per-step computational time (Time). Ours (Dyn-Head) generates predictive rollouts with the learned dynamics head, while Ours (Sim) uses the true simulator during training. Among model-free methods, Ours (Dyn-Head) achieves the best balance between safety and goal-reaching with competitive inference time. Among model-based methods, Ours (Sim) matches MPC while reducing per-step inference time by over three orders of magnitude.
Env. Metric Model-Free Model-Based
CBF-RL CoBL-Diff ConBaT Ours (Dyn-Head) MPC Ours (Sim)
DI Safe 67.71 ± 2.9576.04 ± 3.9072.9 ± 8.20 95.83 ± 1.47 98.96 ± 1.4798.96 ± 1.47
Reach 67.71 ± 2.9526.04 ± 7.8094.8 ± 1.50 89.58 ± 6.42 96.88 ± 2.5587.50 ± 4.42
Success 67.71 ± 2.9521.88 ± 5.1068.8 ± 6.80 88.54 ± 6.42 95.83 ± 1.4786.46 ± 3.90
Time (μs) 9.24 ± 0.36–†6.63 ± 0.04 4.99 ± 0.02 8256 ± 9004.96 ± 0.03
DC Safe 56.25 ± 5.1070.83 ± 3.9064.6 ± 13.10 95.83 ± 2.95 97.92 ± 1.4797.92 ± 1.47
Reach 52.08 ± 3.902.08 ± 2.9527.1 ± 3.90 92.71 ± 2.95 95.83 ± 1.4793.75 ± 1.42
Success 52.08 ± 3.902.08 ± 2.9521.9 ± 2.60 92.71 ± 2.95 94.79 ± 1.4793.75 ± 4.42
Time (μs) 9.90 ± 0.21–†6.70 ± 0.02 4.79 ± 0.01 9280 ± 12624.82 ± 0.04
CF Safe 88.54 ± 2.9598.96 ± 1.8091.7 ± 5.90 96.88 ± 2.55 93.75 ± 0.0093.75 ± 2.55
Reach 85.42 ± 3.900.00 ± 0.0096.9 ± 2.60 92.71 ± 3.90 100.00 ± 0.0094.79 ± 5.31
Success 85.42 ± 3.900.00 ± 0.0088.5 ± 3.90 89.58 ± 8.20 93.75 ± 0.0088.54 ± 7.37
Time (μs) 9.51 ± 0.38–†8.63 ± 0.03 5.12 ± 0.04 2773 ± 1035.08 ± 0.03

† Inference time is not reported for CoBL-Diffusion, as diffusion-based planners require iterative denoising at inference, resulting in slow inference speeds. CoBL-Diffusion achieves a higher safety rate on CF but at the cost of a near-zero reaching rate, consistent with the local trap problem where CBF-guided gradient projection during denoising prevents the planner from making progress toward the goal.

Zero-shot generalization across obstacle densities and workspace sizes. Obstacle density is $\rho = M/l^{n_p}$, where $M$ is the number of obstacles and $n_p \in \{2,3\}$ is the dimension of the position space. Models are trained only at the smaller workspace and lowest density: $l = 4$ with $M = 8$ for DI and DC, giving $\rho = 0.50$, and $l = 3$ with $M = 6$ for Crazyflie, giving $\rho = 6/27 \approx 0.22$. They are then evaluated without retraining at $\rho \in \{0.50, 0.75, 1.00\}$ and $l \in \{4, 6\}$ (DI, DC) or $l \in \{3, 4\}$ (CF). Note that every Crazyflie column is therefore out of distribution in density: even the sparsest evaluated setting, $M = 13$ at $l = 3$, is more than twice the training density. To ensure a controlled, paired comparison, each instance is initialized at the highest density and lower-density variants are obtained by removing a random subset of obstacles while preserving the poses of all remaining ones, so density is the only factor that varies. Safety rates generally decrease with increasing density, as higher clutter reduces navigable space; at fixed density, performance generally decreases as the workspace grows, likely due to longer navigation paths and increased exposure to obstacles. Both variants retain substantial safety under these distribution shifts, with the largest drop when high density and a larger workspace are combined.

The same evaluation in numbers, at the training workspace size. The table below tabulates the smaller-workspace bars of Fig. 2 ($l = 4$ for DI and DC, $l = 3$ for CF) across the three densities, for both the Sim and Dyn-Head variants.
Env. $\rho$ $M$ Safe Reach Success
SimDyn-Head SimDyn-Head SimDyn-Head
DI 0.508 98.96 ± 1.4794.79 ± 3.90 96.88 ± 2.5593.75 ± 4.42 95.83 ± 2.9589.58 ± 3.90
0.7512 97.92 ± 2.9592.71 ± 5.31 95.83 ± 3.9092.71 ± 5.31 93.75 ± 4.4286.46 ± 5.89
1.0016 94.79 ± 3.9091.67 ± 5.31 93.75 ± 4.4290.62 ± 6.75 88.54 ± 5.3183.33 ± 8.96
DC 0.508 97.92 ± 2.9596.88 ± 2.55 91.67 ± 6.4287.50 ± 4.42 91.67 ± 6.4287.50 ± 4.42
0.7512 97.92 ± 2.9594.79 ± 3.90 88.54 ± 5.3184.38 ± 5.10 88.54 ± 5.3183.33 ± 6.42
1.0016 95.83 ± 1.4793.75 ± 2.55 79.67 ± 5.3177.08 ± 5.89 79.17 ± 5.3177.08 ± 5.89
CF 0.5013 90.62 ± 5.1091.67 ± 3.90 92.71 ± 5.8989.58 ± 3.90 84.38 ± 9.2081.25 ± 6.75
0.7520 86.46 ± 5.3187.50 ± 2.55 93.75 ± 6.7589.58 ± 5.31 82.29 ± 8.2079.17 ± 5.89
1.0027 80.21 ± 9.6686.46 ± 5.31 94.79 ± 5.3184.38 ± 4.42 77.08 ± 12.0675.00 ± 6.75

Mean ± std over 32 environments and 3 seeds, 1024 timesteps.

Generalization in Action

Every clip below comes from a policy trained only on a $4 \times 4$ workspace with 8 obstacles. Nothing is retrained or fine-tuned. Moving left to right increases obstacle density $\rho = M/l^{n_p}$; moving down enlarges the workspace, which lengthens the path to the goal and increases exposure to obstacles over the episode. Episodes run for 1024 control steps. The $8 \times 8$ rows go beyond the $l \in \{4, 6\}$ range reported in Fig. 2 above.

Double Integrator

$4 \times 4$ workspace (the training size)

$\rho = 0.50$ · 8 obstacles

$\rho = 0.75$ · 12 obstacles

$\rho = 1.00$ · 16 obstacles

$6 \times 6$ workspace

$\rho = 0.50$ · 18 obstacles

$\rho = 0.75$ · 27 obstacles

$\rho = 1.00$ · 36 obstacles

$8 \times 8$ workspace ($4\times$ the training area)

$\rho = 0.50$ · 32 obstacles

$\rho = 0.75$ · 48 obstacles

$\rho = 1.00$ · 64 obstacles

Dubins Car

$4 \times 4$ workspace (the training size)

$\rho = 0.50$ · 8 obstacles

$\rho = 0.75$ · 12 obstacles

$\rho = 1.00$ · 16 obstacles

$6 \times 6$ workspace

$\rho = 0.50$ · 18 obstacles

$\rho = 0.75$ · 27 obstacles

$\rho = 1.00$ · 36 obstacles

$8 \times 8$ workspace ($4\times$ the training area)

$\rho = 0.50$ · 32 obstacles

$\rho = 0.75$ · 48 obstacles

$\rho = 1.00$ · 64 obstacles

Ablations

Effect of the predictive horizon $H$ on Double Integrator, with history length fixed at $T = 12$. The $H = 1$ setting corresponds to pointwise barrier supervision without multi-step predictive rollout, and gives the lowest safety rate. Increasing the horizon from $H = 1$ to $H = 6$ improves safety from $83.33\%$ to $95.83\%$, demonstrating the benefit of enforcing barrier constraints over predicted rollouts rather than only at the next step. Increasing $H$ further does not consistently help when the history length is fixed, because longer rollouts accumulate dynamics-head prediction error and introduce more linearized barrier constraints in the SQP subproblem. We therefore use $H = 6$ with $T = 12$ in the main experiments.
Method $H$ Safe Reach Success
Ours (Dyn-Head) 183.33 ± 4.7890.63 ± 6.2578.12 ± 5.42
388.54 ± 5.8997.92 ± 1.4787.50 ± 6.75
695.83 ± 1.4789.58 ± 6.4288.54 ± 6.42
989.58 ± 5.3197.92 ± 1.4787.50 ± 6.75
1289.58 ± 3.90100.00 ± 0.0089.58 ± 3.90

Mean ± std over 32 environments and 3 seeds.

Freezing the transformer backbone and dynamics head after Phase 1. The frozen variant trains only the action head and barrier critic in Phase 2, while Ours denotes the full training setup. The frozen dynamics head accumulates prediction error as the action head’s distribution shifts away from the pretraining distribution, and because the backbone is also frozen, the latent $\mathbf{z}_t$ cannot adapt, yielding inaccurate rollouts for barrier constraint evaluation. This motivates joint online training of all components.
Env. Safe Reach Success
FrozenOurs FrozenOurs FrozenOurs
DI 79.17 ± 8.2095.83 ± 1.47 96.88 ± 2.5589.58 ± 6.42 77.08 ± 9.6688.54 ± 6.42
DC 67.71 ± 2.2595.83 ± 2.95 100.00 ± 0.0092.71 ± 2.95 67.71 ± 2.2592.71 ± 2.95
CF 93.75 ± 5.1096.88 ± 2.55 89.58 ± 3.9092.71 ± 3.90 84.38 ± 9.2089.58 ± 6.42

Mean ± standard deviation across 3 seeds, with each seed evaluated on 32 environments. Best mean values are bolded.

Dynamics-head rollout accuracy. Because the dynamics head is a learned model, its accuracy depends on the coverage of the (state, action) pairs it saw during pretraining. Phase 1 therefore pretrains on trajectories from three different control policies (GCBF+, a QP safety controller, and the nominal LQR controller), giving a training distribution that spans learned safe actions, optimization-based corrections and nominal control. Each pretrained dynamics head is then evaluated on 50 independently generated episodes of 256 steps per input signal. The $H = 1$ column is the one-step RMSE; the rest report autoregressive rollout RMSE over the horizon. The upper block of each table is closed-loop controller inputs, the lower block synthetic open-loop signals never encountered during pretraining.

History length $T = 12$

Input signal $H = 1$$H = 8$$H = 16$$H = 24$$H = 32$
GCBF+0.0002820.001620.002100.002580.00310
QP0.0009130.002150.002550.003200.00393
LQR0.0003830.001430.001860.002530.00301
Action head (BarrierFormer)0.0003500.001600.002140.002470.00301
Action head + noise0.0003430.001590.002190.002710.00300
Constant0.0005670.004090.003950.004830.00539
Uniform random0.0019100.004310.005140.005070.00489
Matched random0.0014410.004490.005430.005580.00680
Polynomial0.0006520.004600.004990.004840.00538
Sinusoidal0.0012090.003650.005300.006690.00831
Zero0.0002040.004470.006670.008810.01113

History length $T = 32$

Input signal $H = 1$$H = 8$$H = 16$$H = 24$$H = 32$
GCBF+0.0001700.000840.001710.002460.00326
QP0.0002900.001690.002290.003100.00386
LQR0.0001300.001100.001760.002520.00325
Action head (BarrierFormer)0.0003000.000890.001630.002430.00332
Action head + noise0.0003000.000980.001640.002420.00335
Constant0.0002200.001760.002260.002850.00342
Uniform random0.0006200.001940.002170.002510.00292
Matched random0.0005400.001670.002310.002590.00322
Polynomial0.0003700.002030.002320.002610.00297
Sinusoidal0.0003600.001610.002480.003210.00410
Zero0.0001500.004840.007760.009610.01154

Increasing the history length to $T = 32$ consistently reduces prediction error on controller-based inputs through $H = 24$. At $H = 32$ the two are comparable on those inputs (mean RMSE $0.00321$ vs. $0.00341$), but the longer history helps clearly on unseen nonzero open-loop inputs, cutting their mean $H = 32$ RMSE from $0.00615$ to $0.00333$, about a $46\%$ reduction. The zero-action input is the exception, where both accumulate similar long-horizon error.

Robustness to dynamics perturbations on Double Integrator. All policies are trained on the unperturbed dynamics and evaluated without retraining, under a parametric velocity mismatch $\dot{\mathbf{p}} = \alpha_\text{vel}\mathbf{v}$ and state-wise scaled process noise $\dot{\mathbf{x}} = f(\mathbf{x},\mathbf{u}) + \mathbf{w}$, $\mathbf{w} \sim \mathcal{N}(\mathbf{0}, \boldsymbol{\Sigma}_w)$. Under velocity mismatch the safety rate stays high across all tested $\alpha_\text{vel}$; the lower reaching rate at $\alpha_\text{vel} = 0.8$ is expected, since the robot moves more slowly and more often hits the episode time limit before arriving. Additive process noise is more challenging: safety remains above $92\%$ for $\sigma \leq 0.0025$ but drops as the disturbance magnitude increases. These are empirical robustness tests, not formal robust safety guarantees.
Perturbation Value $T = 12,\ H = 6$
SafeReachSuccess
$\dot{\mathbf{p}} = \alpha_\text{vel}\mathbf{v}$ 0.895.8475.0073.96
0.996.8884.3784.37
1.096.8889.5888.54
1.195.8396.8893.75
1.295.8396.8892.71
$\dot{\mathbf{x}} = f(\mathbf{x},\mathbf{u}) + \mathbf{w}$ $\sigma = 0$96.8889.5888.54
$\sigma = 0.001$98.9689.5889.58
$\sigma = 0.0025$92.7186.4683.33
$\sigma = 0.005$73.9682.2968.75
$\sigma = 0.0075$53.1279.1750.00
$\sigma = 0.01$42.7178.1338.54

Rates reported as percentages over 3 seeds with 32 environments per seed. For process noise, $\sigma_p = \sigma_v = \sigma$.

BibTeX

@inproceedings{chauhan2026barrierformer,
  title     = {BarrierFormer: Transformer-Guided Predictive Barrier Enforcement for Safe Robot Control},
  author    = {Chauhan, Anandsingh and Garg, Kunal},
  booktitle = {Conference on Robot Learning (CoRL)},
  year      = {2026}
}