CBFKit is a Python/ROS2 toolbox designed to facilitate safe planning and control for robotics applications, particularly in uncertain environments. The toolbox utilizes Control Barrier Functions (CBFs) to provide formal safety guarantees while offering flexibility and ease of use. We additionally provide efficient JAX implementatio of Model Predictive path Integral (MPPI) with support for reach avoid specifications.
CBFKit accommodates a range of control-affine system models:
CBFKit can be applied to diverse robotics applications, including:
CBFKit is readily deployable via a Docker image. After setting up Docker (refer to the official Docker documentation for detailed instructions), proceed with one of the following methods:
docker build -t cbfkit:latest -f Dockerfile.$(uname -m) .
docker run -it --name container-name -v .:/workspace cbfkit:latest
Explore the tutorials
directory to help you get started with CBFKit. Open the Python notebook in the tutorials
directory to get started. The script simulate_new_control_system.ipynb
automatically generates the controller, plant, and certificate function for a Van der Pol oscillator. It also generates ROS2 nodes for the plant, controller, sensor, and estimator. These serve as a starting point for developing your own CBF-based controller.
Generated files/folders:
van_der_pol_oscillator
┣ certificate_functions
┃ ┣ barrier_functions
┃ ┃ ┣ __init__.py
┃ ┃ ┣ barrier_1.py
┃ ┃ ┗ barrier_2.py
┃ ┣ lyapunov_functions
┃ ┃ ┣ __init__.py
┃ ┃ ┗ lyapunov_1.py
┃ ┗ __init__.py
┣ controllers
┃ ┣ __init__.py
┃ ┣ controller_1.py
┃ ┗ zero_controller.py
┣ ros2
┃ ┣ __init__.py
┃ ┣ config.py
┃ ┣ controller.py
┃ ┣ estimator.py
┃ ┣ plant_model.py
┃ ┗ sensor.py
┣ __init__.py
┣ constants.py
┣ plant.py
┗ run_ros2_nodes.sh
We recommend going through the tutorials in the following order to get familiar with the architecture of our library.
simulate_new_control_system.ipynb
multi_robot_example.ipynb
simulate_mppi_cbf.py
simulate_mppi_cbf_ellipsoidal_stochastic_cbf.py
simulate_mppi_stl.py
The flowchart below summarizes the architecure
Each function (dynamics, cost, constraint, controller) must follow a specific structure.
The data (python dictionary) in planners and controllers is designed to cater to needs of different types of comntrollers and planners. For example, CBF-QP does not need to maintain internal state but planners/controllers like MPC or MPPI need to initialize their initial guess with solution from previous time step when implemented in receding horizon fashion. Since we focus on functional programming for computational efficiency, instead of maintaining this internal state, we pass it as input and output arguments. Controllers like CBF-QP need to maintain any internal state and can have empty dictionary whereas MPPI stores its solution trajectory in the dictionary (and received it back at next time step of the simulation). The data must therefore be populated appropriately. In case of planners, the control trajectory must be associated with the key u_traj and state trajectory must be associated with the key x_traj. See cbf_clf_qp_generator.py
and mpi_generator.py
files to understand in more detail.
The ROS2 nodes are generated in the ros2
directory. The nodes are generated for the plant, controller, sensor, and estimator. This support is in the initial stage and will be improved soon.
To run the nodes, execute the following command in the van_der_pol_oscillator
directory:
bash run_ros2_nodes.sh
The generated nodes interact as follows:
plant_model
node simulates the physical system and publishes the system state.sensor
node receives the system state and adds noise to simulate real-world measurements.estimator
node receives the noisy measurements and estimates the true system state.controller
node receives the estimated state and computes the control input based on the CBF formulation.If you use CBFKit in your research, please cite the following PAPER:
@misc{black2024cbfkit,
title={CBFKIT: A Control Barrier Function Toolbox for Robotics Applications},
author={Mitchell Black and Georgios Fainekos and Bardh Hoxha and Hideki Okamoto and Danil Prokhorov},
year={2024},
eprint={2404.07158},
archivePrefix={arXiv},
primaryClass={cs.RO}
}
CBFKit is distributed under the BSD 3-Clause License. Refer to the LICENSE
file for detailed terms.