This repository contains a MATLAB/Simulink implementation of a multimode control barrier function (CBF), along with the Simulink model used to generate ROS code and a collection of simulation test cases.
A control barrier function maintains system safety by turning a safety requirement into a constraint on the control input. At each simulation step, the CBF evaluates the current system state, the surrounding traffic conditions, and the nominal control command. It then determines whether the nominal command preserves the required safety margin and applies the appropriate constraint when it does not.
This implementation is multimode: the active safety constraint changes with the operating mode of the system. Mode transitions allow the CBF to represent different traffic or vehicle behaviors while preserving the safety requirement across those transitions. The resulting CBF subsystem can be inserted into a larger Simulink model between the nominal controller and the vehicle dynamics, where it provides a safety-aware control command for simulation or ROS deployment.
The state
| Constant | Value |
|---|---|
In all modes, the CBF command acceleration is calculated as:
The command acceleration is then:
In the third mode, the minimum distance is calculated as:
The mode-transition logic is summarized below. The three operating modes are
the full-range mode (
| Current mode | Next mode | Transition condition |
|---|---|---|
| Full range ( |
Stop-and-go ( |
|
| Stop-and-go ( |
Transition ( |
|
| Transition ( |
Stop-and-go ( |
|
| Transition ( |
Full range ( |
|
At every step, the active mode selects the corresponding CBF constraint. The vehicle or plant dynamics then provide the updated state and traffic measurements used to evaluate the next transition.
.
├── multimodecbf_subsystem.slx # CBF subsystem
├── multimodecbf.slx # Top-level model and ROS code-generation entry point
├── startup.m # Adds the repository and its subdirectories to the MATLAB path
├── test/
│ ├── case_*.slx # Simulation test cases
│ └── test_resources/ # Reusable subsystem models used by the tests
multimodecbf_subsystem.slxdefines the multimode CBF. Open this model to inspect or modify the barrier-function subsystem.multimodecbf.slxis the top-level model used to integrate the CBF and generate ROS code. Use the model's configured Simulink build/code-generation workflow when producing ROS output.
-
startup.minitializes the MATLAB environment by recursively adding the repository to the MATLAB path:addpath(genpath('.'))
The test/ directory contains the simulation test suite. Each
case_*.slx file represents a scenario used to exercise the CBF and the
surrounding vehicle/control models. The test/test_resources/ directory
contains reusable subsystem models and supporting Simulink models consumed
by those test cases.
Test case names describe the scenario being exercised, for example:
case_01_fast_steady.slx— fast, steady-state behaviorcase_04_slow_to_fast.slx— transition from slow to fast behaviorcase_09_30_to_2_to_0.slx— a speed profile that reaches a stopcase_13_hard_brake.slx— hard-braking behaviorcase_19_all_state_oscillation.slx— oscillation across all states
You will need:
- MATLAB
- Simulink
- The MATLAB/Simulink products required by the models and their configured ROS code-generation workflow
The exact MATLAB release and toolbox versions should match the environment in which the models were created and tested.
From the repository root, run:
startupAlternatively, execute startup.m from the MATLAB Current Folder browser.
Running the script first ensures that the top-level models and all test
resources are available on the MATLAB path.
- Run
startup. - Open
multimodecbf_subsystem.slxto inspect the CBF implementation, or open one of the models intest/to run a scenario. - Configure the model's normal Simulink simulation settings as needed.
- Run the simulation and inspect the model outputs and scopes/logs provided by the selected model.
- Run
startup. - Open
multimodecbf.slx. - Confirm that the model's ROS/code-generation configuration matches your target environment.
- Use the Simulink build or code-generation command configured for the model.
To cite the usage of this repository, use the following:
Kate Sanborn, George Gunter, Daniel B. Work, Ricardo G. Sanfelice, Jonathan Sprinkle. "Traffic Density with Multi-Mode Control Barrier Functions at Scale." in 2026 IEEE International Conference on Intelligent Transportation Systems (ITSC), (in press) 2026.
or using bibtex:
@inproceedings{sanborn2026single,
author = {Sanborn, Kate and Gunter, George and Work, Daniel B. and Sanfelice, Ricardo G. and Sprinkle, Jonathan},
title = {Traffic Density with Multi-Mode Control Barrier Functions at Scale},
booktitle = {2026 IEEE International Conference on Intelligent Transportation Systems (ITSC)},
year = {2026},
note = {in press}
}