This repository contains the code for reproducing the simulations in the paper: "Safe Beyond the Horizon: Efficient Sampling-based MPC with Neural Control Barrier Functions"
-
AutoRally experiments:
robot_planning/scripts/run_AutoRally_CBF_MPPI_for_experiment.py- Main AutoRally simulationrobot_planning/scripts/run_ablations.py- Ablation studies
-
Drone/Quadrotor2D experiments:
robot_planning/scripts/run_quadrotor2d.py- 2D quadrotor simulation
-
Additional experiments:
robot_planning/scripts/run_dubins3d.py- Dubins car simulation
ncbf/scripts/train_offline.py- Train NCBF for AutoRallyncbf/scripts/train_offline_drone.py- Train NCBF for dronencbf/scripts/eval_ncbf.py- Evaluate trained NCBF
robot_planning/scripts/functional_scripts/collect_offline_dset.py- Collect AutoRally datarobot_planning/scripts/functional_scripts/collect_offline_dset_drone.py- Collect drone data
robot_planning/scripts/functional_scripts/- Data processing and analysis utilitiesncbf/scripts/functional_scripts/- Visualization and debugging tools
The easiest way to install all dependencies with compatible versions is to use the provided conda environment:
# Create the conda environment with all dependencies
conda env create -f environment.yml
# Activate the environment
conda activate nsvimpc
# Install the local og package
pip install -e ./ogThis will install all dependencies including:
- JAX 0.4.24 with CUDA support for GPU-accelerated MPPI controllers
- TensorFlow Probability 0.25.0 for distributions (JAX substrate)
- NumPy 1.26.4 (compatible with JAX 0.4.24)
- PyTorch 2.5.1, matplotlib, scipy, and other scientific computing packages
- All other dependencies with tested, compatible versions
If you prefer manual installation, you can use pip with the requirements file:
# Install core dependencies (may have version conflicts)
pip install -r robot_planning/requirements.txt
# Install the local og package
pip install -e ./ogNote: Manual pip installation is not recommended due to potential dependency conflicts between JAX, TensorFlow Probability, and other packages. The conda environment approach provides tested, compatible versions. You are also welcome to install the most updated version of these packages with the updated og package, which can be found: https://github.com/oswinso/og
cd robot_planning
python scripts/run_AutoRally_CBF_MPPI_for_experiment.pycd robot_planning
python scripts/run_quadrotor2d.pyThe NCBF training process consists of multiple steps:
- Collect data:
cd robot_planning/scripts
python collect_offline_dset.pyThis collects trajectories and saves the dataset to data/raw_data.pkl.
- Process data:
# From the root directory
python robot_planning/scripts/functional_scripts/raw_to_dset.py data/raw_data.pklThis converts data/raw_data.pkl to data/dset.pkl.
- Train offline:
# From the root directory
python ncbf/scripts/train_offline.pyThis trains the model and saves checkpoints in the runs folder.
- Use the trained NCBF: Update the checkpoint path in your scripts to point to the trained model.
The MPPI controller has been tuned to give satisfactory performance.
For the sake of testing the algorithms, there are several parameters of interests that you can play with such that the MPPI becomes more or less reliable. In the file tests/configs/test_run_Autorally_MPPI.cfg, generally:
- Increasing or decreasing the parameter "number_of_trajectories" under [my_stochastic_trajectories_sampler1] will make the controller more and less stable, respectively.
- The diagonal terms of "covariance" under [my_noise_sampler1] determines the degree of exploration. Increasing them means searching in a larger area with sparser trajectory sampling, given a fixed value of "number_of_trajectories". For instance, making the diagonal terms of "covariance" to be 0.01 will result in extremely small exploration and causes the vehicle to crash the boundaries.
- The first dimension of "goal_state" under [my_goal_checker_for_tracking] is the target speed that MPPI tracks, please feel free to play with it.
- "trajectories_rendering" under [renderer1] is a switch for turning on and off rendering of sample trajectories. Turn it on to observe the difference that tuning "number_of_trajectories" or "covariance" makes. In our testing scripts, we sometimes use a boolean parameter "render" to overide the rendering switch.
If you use this code in your research, please cite our papers:
@inproceedings{yin2025safe,
title = {Safe Beyond the Horizon: Efficient Sampling-based MPC with Neural Control Barrier Functions},
author = {Ji Yin and Oswin So and Eric Yang Yu and Chuchu Fan and Panagiotis Tsiotras},
booktitle = {Proceedings of Robotics: Science and Systems (RSS)},
year = {2025},
address = {Los Angeles, CA},
month = {June},
day = {21--25}
}
@ARTICLE{yin2023shield,
author={Yin, Ji and Dawson, Charles and Fan, Chuchu and Tsiotras, Panagiotis},
journal={IEEE Robotics and Automation Letters},
title={Shield Model Predictive Path Integral: A Computationally Efficient Robust MPC Method Using Control Barrier Functions},
year={2023},
volume={8},
number={11},
pages={7106-7113},
keywords={Trajectory;Safety;Heuristic algorithms;Costs;Planning;Vehicle dynamics;Uncertainty;Autonomous driving;computational efficiency;optimal control and motion planning;vehicle safety},
doi={10.1109/LRA.2023.3315211}}This project is licensed under the MIT License - see the LICENSE file for details.