ROS 2 packages to implement generic controllers based on Hierarchical Optimization (HO) and Model Predictive Control (MPC).
These packages have been tested with ROS 2 Humble and ROS 2 Iron on an Ubuntu system.
To use Torch with an NVIDIA graphics card, it is necessary to install the NVIDIA drivers for Ubuntu. Here.
The repository root is the colcon workspace: the ROS packages are in src/, the Docker files in docker/, and standalone scripts in scripts/.
Install Docker Community Edition (ex Docker Engine).
You can follow the installation method through apt.
Note that it makes you verify the installation by running sudo docker run hello-world.
It is better to avoid running this command with sudo and instead follow the post installation steps first and then run the command without sudo.
Follow with the post-installation steps for Linux.
This will allow you to run Docker without sudo.
Install NVIDIA Container Toolkit (nvidia-docker2).
From the repository root, build the docker image with
docker/build.bash [-a] [-f] [-h] [-l] [-r] [-t]Where the optional arguments represent:
-aor--all: build the image with all the dependencies-for--ffmpeg: build the image with ffmpeg (for saving videos)-hor--help: show the help message-lor--latex: build the image with LaTeX-ror--rebuild: rebuild the image-tor--torch: build the image with PyTorch
Run the container with
docker/run.bashThis repo also supports VS Code devcontainers.
The Docker setup is based on docker_ros_nvidia.
As an alternative, you can use Docker Compose. First, set up X11 forwarding (once per login session):
xhost +local:docker
XAUTH=/tmp/.docker.xauth; [ -f "$XAUTH" ] || (touch "$XAUTH" && xauth nlist $DISPLAY | sed 's/^..../ffff/' | xauth -f "$XAUTH" nmerge -)Then build, run in detached mode, and attach:
# Build the image (optional features via env vars: FFMPEG=1, LATEX=1, TORCH=1)
docker compose -f docker/docker-compose.yaml build
# Start the container in detached mode
docker compose -f docker/docker-compose.yaml up -d
# Open a shell inside the container (repeatable for multiple sessions)
docker compose -f docker/docker-compose.yaml exec ho_mpc bash
# Stop the container
docker compose -f docker/docker-compose.yaml downWhen I write <some_text>, you have to change the value in the <>.
Create a GitHub SSH key. Just do it.
Clone the repo, which is itself the workspace, and enter it
git clone --recursive git@github.com:ddebenedittis/hierarchical_optimization_mpc.git
cd hierarchical_optimization_mpcBuild the workspace with
colcon build --symlink-installSource the workspace with (you have to add it to the ~/.bashrc or do it on every newly opened terminal)
source install/setup.bashSingle robot example
ros2 run hierarchical_optimization_mpc example_single_robotMulti robot example
ros2 run hierarchical_optimization_mpc example_multi_robotToy problem 1 (multiple conflicting tasks to one robot)
ros2 run hierarchical_optimization_mpc toy_problem_1Python is more verbose than ROS, but you can pass options
Multi robot exmaple
python3 src/hierarchical_optimization_mpc/hierarchical_optimization_mpc/example_multi_robot.py [--hierarchical {True, False}] [--n_robots [int,int]] [--solver {clarabel, osqp, proxqp, quadprog, reluqp}] [--visual_method {plot, save, none}]Parameters:
--hierarchical bool: if True, uses the hierarchical approach.--n_robots list[int]: Number of unicycles and omnidirectional robots (default[6,0]).--solver {clarabel, osqp, proxqp, quadprog, reluqp}: QP solver to use.--visual_method {plot, save, none}: how to display the results.
Distributed examples can be run with the scripts network_simulation.py in the scenarios folder in distributed_ho_mpc package.
The following scenarios with the relative setting are already settend in the folders:
- Radial Switching
- Movement in Formation with obstacle avoidance
- Coverage
- Passing through a narrow gap
The relative pkg are:
- dhqp: run in different nodes the d-hqp algorithm
- limo_simulation provide a gazebo simulation for testing the algorithm. It spawns limo robots
ros2 launch limo_simulation gazebo_models_diff.launch.pythen
ros2 launch dhqp network.launch.pyInstall pre-commit and ruff (already installed in Docker)
pip3 install pre-commit ruffRun
pre-commit installThis will format all the Python code with Ruff.
Tests can be run with
colcon test
scripts/omni_results/ turns the omnidirectional comparison campaign into tables and figures.
It runs with the host Python (numpy, matplotlib, and a LaTeX installation for the paper-style figures), no ROS needed.
python3 scripts/omni_results/make_results.py # summary figures and tables
python3 scripts/omni_results/make_paper_figures.py # paper-style figuresBy default both read the campaign outputs in out/omni_campaign_2026-09-25 and out/omni_nl5_2026-09-26 and write to out/omni_results/; see --help for the options.
None.
If you find this project useful in your research, please consider citing my related work (available here):
@article{debenedittis2025managing,
author={De Benedittis, Davide and Garabini, Manolo and Pallottino, Lucia},
journal={IEEE Robotics and Automation Letters},
title={Managing Conflicting Tasks in Heterogeneous Multi-Robot Systems Through Hierarchical Optimization},
year={2025},
volume={10},
number={6},
pages={5305-5312},
doi={10.1109/LRA.2025.3559843}
}