bardhh / cbfkit

Toolbox for Robotics Control
BSD 3-Clause "New" or "Revised" License
43 stars 4 forks source link

CBFKit: A Control Barrier Function Toolbox for Robotics Applications

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.

Table of Contents

Key Features

Supported Models

CBFKit accommodates a range of control-affine system models:

Applications

CBFKit can be applied to diverse robotics applications, including:

Installation

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:

1. VS Code DevContainer Launch

  1. Open the project in VS Code.
  2. Click the green button at the bottom right of the window to launch the DevContainer.
  3. All necessary components are pre-installed for immediate use.

2. Docker Command Line

  1. Build the image:
    docker build -t cbfkit:latest -f Dockerfile.$(uname -m) .
  2. Run the container:
    docker run -it --name container-name -v .:/workspace cbfkit:latest

Start with Tutorials

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.

Simulation Arhitecture

The flowchart below summarizes the architecure

cbfkit_architecture

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.

ROS2

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:

Citing CBFKit

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}
}

License

CBFKit is distributed under the BSD 3-Clause License. Refer to the LICENSE file for detailed terms.