Skip to content

Commit 974bcc1

Browse files
authored
Feature/ros2 docker (#19)
* add dockerfile w/uhumans example * update docker instructions * dockerfile with zed * (wip) add profiles for different docker envs * update docker, add zed launch * zero rviz view * update docker readme * update docker readme * update docker readme * cleanup * cleanup * update hydra readme * update hydra readme * update docker readme * add profiles to makefile * update dockerfiles * update/rename zed, add/install rviz file * add a1 docker * add a1 launch * update docker readme * update docker readme * update readme * change a1 profile to dev profile * update readme * minor fixes to zed docker * Update README.md * Update README.md * Update README.md * rename commented tf for clarity * Update README.md * Update README.md * Update README.md * Update README.md * add mesh place to zed21 config, cleanup launch * nvidia runtime to compose, fix type in dockerfile * add zenoh to install * again, add zenoh to install * check .env for path before adding fallback * update readme * remove/move min/max range * move rviz files to visualizer
1 parent 001da6d commit 974bcc1

File tree

17 files changed

+1727
-142
lines changed

17 files changed

+1727
-142
lines changed

README.md

Lines changed: 13 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Hydra-ROS
1+
## Hydra-ROS
22

33
This repository contains the ROS interface for [Hydra](https://github.com/MIT-SPARK/Hydra) and is based on the following papers:
44
- ["Hydra: A Real-time Spatial Perception System for 3D Scene Graph Construction and Optimization"](http://www.roboticsproceedings.org/rss18/p050.pdf)
@@ -26,134 +26,29 @@ If you find this code relevant for your work, please consider citing us. A bibte
2626
}
2727
```
2828

29-
## Table of Contents
29+
### Acknowledgements and Disclaimer
3030

31-
- [Getting Started](#getting-started)
32-
- [Installation](#installation)
33-
- [Dataset Setup](#dataset-setup)
34-
- [Running Hydra](#running-hydra)
35-
- [Filing Issues](#filing-issues)
36-
- [Additional Resources](#additional-resources)
37-
- [Acknowledgements](#acknowledgements)
38-
39-
## Getting started
40-
41-
> :warning: **Warning** <br>
42-
> The ROS2 version of Hydra is in active development and is unstable and may not fully be feature-complete.
43-
44-
Hydra has been tested on Ubuntu 22.04 & ROS2 Iron and Ubuntu 24.04 & ROS2 Jazzy. It **should** build on newer distributions. It **will not** build on older ROS2 distributions than Iron (it depends on the `NodeInterfaces` suite of classes that were introduced in Iron).
45-
46-
You can follow the instructions [here](https://docs.ros.org/en/jazzy/Installation.html) to install ROS2 if you haven't already. The link points to Jazzy currently, pay attention to the distribution!
47-
48-
### Installation
49-
50-
#### Dependencies
51-
52-
First, make sure you have some general requirements
53-
```shell
54-
# this is an optional package in the ROS2 installation directions
55-
sudo apt install ros-dev-tools
56-
```
57-
and make sure you have set rosdep up:
58-
```shell
59-
sudo rosdep init
60-
rosdep update
61-
```
62-
63-
#### Building
64-
65-
To get started:
66-
67-
```shell
68-
mkdir -p ~/hydra_ws/src
69-
cd ~/hydra_ws
70-
# you may find it convenient to set the build type, etc.
71-
# you may also want to set `symlink-install: true`
72-
echo "build: {cmake-args: [-DCMAKE_BUILD_TYPE=Release]}" > colcon_defaults.yaml
73-
74-
cd src
75-
git clone [email protected]:MIT-SPARK/Hydra-ROS.git hydra_ros -b ros2
76-
vcs import . < hydra_ros/install/ros2.yaml
77-
rosdep install --from-paths . --ignore-src -r -y
78-
79-
cd ..
80-
colcon build --continue-on-error
81-
```
82-
83-
> **Note**<br>
84-
> Depending on the amount of RAM available on your machine, you may run out of memory when compiling with `colcon build` directly (which will result in a `GCC killed` error). If this occurs, you can either specify fewer threads for colcon via `MAKEFLAGS="-j2" colcon build --parallel-workers 2` (which builds 2 packages at a time with 2 threads for 4 threads total) or compile certain larger packages directly first by building them specifically.
85-
86-
> :warning: **Warning**</br>
87-
> In the `vcs import` step, GitHub may block too many concurrent requests. If you receive `kex_exchange_identification: read: Connection reset by peer` errors, try running `vcs import . < hydra/install/hydra.rosinstall --workers 1`.
31+
**Acknowledgements:** This work was partially funded by the AIA CRA FA8750-19-2-1000, ARL DCIST CRA W911NF-17-2-0181, and ONR RAIDER N00014-18-1-2828.
8832

89-
### Dataset Setup
33+
**Disclaimer:** Research was sponsored by the United States Air Force Research Laboratory and the United States Air Force Artificial Intelligence Accelerator and was accomplished under Cooperative Agreement Number FA8750-19-2-1000. The views and conclusions contained in this document are those of the authors and should not be interpreted as representing the official policies, either expressed or implied, of the United States Air Force or the U.S. Government. The U.S. Government is authorized to reproduce and distribute reprints for Government purposes notwithstanding any copyright notation herein.
9034

91-
We've switched to the v2 version of uhumans2. Download the ROS1 bag for the office scene [here](https://drive.google.com/file/d/1awAzQ7R1hdS5O1Z2zOcpYjK7F4_APq_p/view?usp=drive_link).
92-
Then install [rosbags](https://pypi.org/project/rosbags/) via pip (i.e., `pip install rosbags` into a virtual environment).
35+
### Getting started
9336

94-
To convert the bag:
95-
```shell
96-
rosbags-convert --src path/to/office.bag --dst path/to/office
97-
```
37+
> :warning: **Warning** <br>
38+
> The ROS2 version of this package is in active development and is not guaranteed to build, run or have documentation. You have been warned!
9839
99-
Make sure to create a override for latching static tf topics:
100-
```shell
101-
echo "/tf_static: {depth: 1, durability: transient_local}" > ~/.tf_overrides.yaml
102-
```
40+
Hydra has been tested on Ubuntu 22.04 and ROS2 Iron. See [here](doc/ros2_setup.md) to get started with Hydra and ROS2. See [here](docker/README.md) for using Hydra with ROS2 in Docker.
10341

10442
### Running Hydra
10543

106-
> **:warning: Warning**<br>
107-
> This guide is written assuming you use `zsh`. If you don't, source the right setup file for your shell
108-
109-
To start Hydra:
110-
```shell
111-
# this will break autocomplete, see group wiki for correct way to do this
112-
source ~/hydra_ws/install/setup.zsh
113-
ros2 launch hydra_ros uhumans2.launch.yaml
114-
```
115-
116-
Then, start the rosbag in a separate terminal:
117-
```shell
118-
ros2 bag play path/to/rosbag --clock --qos-profile-overrides-path ~/.tf_overrides.yaml
119-
```
44+
See our documentation [here](doc/quickstart.md).
12045

121-
#### Running with Semantic Segmentation
122-
123-
See [here](https://github.com/MIT-SPARK/semantic_inference/blob/main/docs/closed_set.md#getting-dependencies) for installation information for `semantic_inference`.
124-
125-
For the uHumans2 office scene, start Hydra via
126-
```
127-
source ~/hydra_ws/install/setup.zsh
128-
ros2 launch hydra_ros uhumans2.launch.yaml use_gt_semantics:=false
129-
```
130-
131-
You may need to wait for about a minute for TensorRT to compile the model the first time you run the launch file. Once Hydra initializes, then run
132-
```
133-
ros2 bag play path/to/rosbag --clock --qos-profile-overrides-path ~/.tf_overrides.yaml
134-
```
135-
136-
## Filing Issues
137-
138-
Please understand that this is research code maintained by busy graduate students, **which comes with some caveats**:
139-
1. We do our best to maintain and keep the code up-to-date, but things may break or change occasionally
140-
2. We do not have bandwidth to help adapt the code to new applications
141-
3. The documentation, code-base and installation instructions are geared towards practitioners familiar with ROS and 3D scene graph research.
142-
143-
> **:warning: Warning**<br>
144-
> We don't support other platforms. Issues requesting support on other platforms (e.g., Ubuntu 18.04, Windows) will be summarily closed.
145-
146-
Depending on the nature of the issue, it may be helpful to browse [this](doc/debugging.md) page about debugging Hydra first.
147-
148-
Thank you in advance for your understanding!
149-
150-
## Additional Resources
46+
### Design Information
15147

15248
We maintain information on the ROS2 interfaces that Hydra uses [here](doc/hydra_ros_interfaces.md) that may be useful if you are trying to understand how to use Hydra with a new dataset.
153-
We also have a preliminary guide to setting up Hydra with the Zed2i camera [here](doc/setting_up_a_new_sensor.md).
15449

155-
## Acknowledgements
50+
### Filing Issues
15651

157-
**Acknowledgements:** This work was partially funded by the AIA CRA FA8750-19-2-1000, ARL DCIST CRA W911NF-17-2-0181, and ONR RAIDER N00014-18-1-2828.
52+
:warning: We don't support other platforms. Issues requesting support on other platforms (e.g. Ubuntu 16.04, Windows) will be summarily closed.
15853

159-
**Disclaimer:** Research was sponsored by the United States Air Force Research Laboratory and the United States Air Force Artificial Intelligence Accelerator and was accomplished under Cooperative Agreement Number FA8750-19-2-1000. The views and conclusions contained in this document are those of the authors and should not be interpreted as representing the official policies, either expressed or implied, of the United States Air Force or the U.S. Government. The U.S. Government is authorized to reproduce and distribute reprints for Government purposes notwithstanding any copyright notation herein.
54+
Depending on the nature of the issue, it may be helpful to browse [this](https://github.com/MIT-SPARK/Hydra/blob/main/doc/debugging.md) page about debugging Hydra first.

docker/Makefile

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
.PHONY: build run up shell stop start down clean profiles check-profile check-env
2+
3+
#list available profiles
4+
profiles:
5+
@echo "Available profiles:"
6+
@find . -maxdepth 1 -type d ! -name "." | while read dir; do \
7+
if [ -f "$$dir/docker-compose.yml" ]; then \
8+
echo " $$(basename $$dir)"; \
9+
fi; \
10+
done
11+
12+
#check profile for selecting docker-compose file
13+
check-profile:
14+
@if [ -z "$(PROFILE)" ]; then \
15+
echo "PROFILE not set."; \
16+
echo "Please specify which Docker profile to use. For example:"; \
17+
echo " make build PROFILE=minimal"; \
18+
exit 1; \
19+
fi
20+
21+
#check if .env file exists and if DATASETS_PATH is set
22+
check-env:
23+
@if [ ! -f .env ]; then \
24+
echo "Warning: .env file not found. Creating one with default DATASETS_PATH."; \
25+
echo "DATASETS_PATH=/root/empty_data" > .env; \
26+
elif ! grep -q '^DATASETS_PATH=' .env; then \
27+
echo "DATASETS_PATH not set in .env. Adding default fallback."; \
28+
echo "DATASETS_PATH=/root/empty_data" >> .env; \
29+
fi
30+
@grep '^DATASETS_PATH=' .env
31+
32+
DOCKER_DIR := $(PROFILE)
33+
SERVICE_NAME := hydra-$(PROFILE)
34+
35+
#build the selected image
36+
build: check-profile check-env
37+
docker compose --env-file .env -f $(DOCKER_DIR)/docker-compose.yml build
38+
39+
#start one-time interactive container, auto-removed when exit
40+
run: check-profile check-env
41+
docker compose --env-file .env -f $(DOCKER_DIR)/docker-compose.yml run --rm $(SERVICE_NAME) bash
42+
43+
#start the container in detached mode to keep container running
44+
up: check-profile check-env
45+
docker compose --env-file .env -f $(DOCKER_DIR)/docker-compose.yml up -d
46+
47+
#attach a shell to the running container (must already be ran via up)
48+
shell: check-profile check-env
49+
docker compose --env-file .env -f $(DOCKER_DIR)/docker-compose.yml exec $(SERVICE_NAME) bash
50+
51+
#stop the running the container
52+
stop: check-profile check-env
53+
docker compose --env-file .env -f $(DOCKER_DIR)/docker-compose.yml stop
54+
55+
#restart a container that was stopped
56+
start: check-profile check-env
57+
docker compose --env-file .env -f $(DOCKER_DIR)/docker-compose.yml start
58+
59+
#stop and remove everything created by up
60+
down: check-profile check-env
61+
docker compose --env-file .env -f $(DOCKER_DIR)/docker-compose.yml down
62+
63+
#remove all unused containers
64+
clean: check-profile check-env
65+
docker container prune -f
66+
docker image prune -f

docker/README.md

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
# Docker Profiles
2+
3+
This directory contains multiple examples to build and run Hydra with different Docker configurations.
4+
5+
## Requirements
6+
You will need `git`, `make`, and `vcstool` as well as [docker](https://docs.docker.com/engine/install/ubuntu/) and the [NVIDIA Container Toolkit](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html) for the profiles with GPU support. You may need to run `sudo usermod -aG docker $USER` + `newgrp docker` after installing docker, and similarly, you may need to run `sudo systemctl restart docker` after installing the toolkit.
7+
8+
## Profiles
9+
10+
- **`minimal`** (no GPU support):
11+
- ROS 2 Jazzy
12+
- Basic ROS dev tools and C++ dependencies
13+
- **`dev`**:
14+
- ROS 2 Jazzy
15+
- Basic ROS dev tools and C++ dependencies
16+
- CUDA 12.8
17+
- TensorRT
18+
- **`zed`**:
19+
- ROS 2 Jazzy
20+
- Basic ROS dev tools and C++ dependencies
21+
- CUDA 12.8
22+
- ZED SDK
23+
- TensorRT
24+
25+
## Commands
26+
27+
The Makefile supports the following commands:
28+
29+
| Command | Description |
30+
|---------------|--------------------------------------------------------|
31+
| `make build` | Builds the selected profile (must set `PROFILE=...`) |
32+
| `make run` | Runs an interactive container (auto-removed) |
33+
| `make up` | Runs container in background |
34+
| `make shell` | Opens a shell inside a running container |
35+
| `make stop` | Stops a running container |
36+
| `make start` | Starts a stopped container |
37+
| `make down` | Stops and removes a container |
38+
| `make clean` | Prunes unused containers and images |
39+
40+
41+
> :grey_exclamation: **Note**</br>
42+
> You must specify the profile you want to use by setting the `PROFILE` variable when running the commands (e.g., `make build PROFILE=minimal`). If you don't want to type `PROFILE=<profile>` every time, you can set the `PROFILE` environment variable in your shell via `export PROFILE=<profile>`. This will make the Makefile use that profile by default.
43+
44+
---
45+
46+
## Quick Start (PROFILE=minimal)
47+
The following instructions will guide you through setting up and running Hydra using Docker with the `minimal` profile. The `minimal` profile does not provide CUDA/TensorRT support.
48+
49+
Before starting, export the `WORKSPACE` environment variable to point to your Hydra workspace directory (e.g., `export WORKSPACE=/path/to/hydra_ws`). This is only needed for copy/pasting the commands in the quick start.
50+
51+
### Host (PROFILE=minimal)
52+
Before using Docker, make sure to:
53+
54+
1. Setup your workspace:
55+
56+
```shell
57+
mkdir -p $WORKSPACE/src
58+
cd $WORKSPACE
59+
echo "build: {cmake-args: [--no-warn-unused-cli, -DCMAKE_BUILD_TYPE=Release, -DCONFIG_UTILS_ENABLE_ROS=OFF]}" > colcon_defaults.yaml
60+
61+
cd src
62+
git clone https://github.com/MIT-SPARK/Hydra-ROS.git hydra_ros
63+
64+
#replace ros2.yaml with ros2_docker.yaml to use https
65+
vcs import . < hydra_ros/install/ros2.yaml
66+
```
67+
68+
> :warning: **Warning**</br>
69+
> In the `vcs import` step, GitHub may block too many concurrent requests. If you receive `kex_exchange_identification: read: Connection reset by peer` errors, try running `vcs import . < hydra/install/hydra.rosinstall --workers 1`.
70+
71+
2. You can skip this step if you do not need to mount a dataset path from the host; otherwise, setup your dataset path (this only needs to be done once):
72+
73+
```shell
74+
cd $WORKSPACE/src/hydra_ros/docker
75+
echo "DATASETS_PATH=/home/jared/datasets" > .env
76+
```
77+
78+
If you want to change the dataset path, you do not need to rebuild the image; you can simply edit the `.env` file in the `docker` directory and restart the container (e.g., `make down` + `make up`). The path will be mounted to `/root/data` inside the container.
79+
80+
3. If running the minimal profile, you can run Hydra on the uhumans2 dataset. Download the ROS 1 bag for the office scene [here](https://drive.google.com/file/d/1awAzQ7R1hdS5O1Z2zOcpYjK7F4_APq_p/view?usp=drive_link). The ROS 1 bag will need to be converted to ROS 2 bag (see below).
81+
82+
### Container (PROFILE=minimal)
83+
1. Build the image and run the container for the `minimal` profile:
84+
85+
```shell
86+
cd $WORKSPACE/src/hydra_ros/docker
87+
make build PROFILE=minimal
88+
make up PROFILE=minimal
89+
make shell PROFILE=minimal
90+
```
91+
92+
Once inside the container, you can build and run Hydra (you should already be in `/root/hydra_ws` when opening the shell):
93+
94+
```bash
95+
colcon build --symlink-install --continue-on-error
96+
source install/setup.bash
97+
ros2 launch hydra_ros uhumans2.launch.yaml
98+
```
99+
100+
101+
> **:warning: Warning**<br>
102+
> If you encounter graphical issues (e.g. rviz not displaying), make sure you run `xhost +local:root` on the host machine and that `DISPLAY` is correctly set.
103+
104+
2. In a separate terminal, open another shell in the container:
105+
106+
```bash
107+
cd $WORKSPACE/src/hydra_ros/docker
108+
make shell PROFILE=minimal
109+
```
110+
111+
Before playing the bag, make sure to create an override for latching static tf topics, then play the bag:
112+
113+
```bash
114+
echo "/tf_static: {depth: 1, durability: transient_local}" > ~/.tf_overrides.yaml
115+
ros2 bag play /root/data/path/to/rosbag --clock --qos-profile-overrides-path ~/.tf_overrides.yaml
116+
```
117+
118+
119+
> **:warning: Warning**<br>
120+
> You must convert the ROS 1 bag to a ROS 2 bag before playing it. The `rosbags-convert` tool is preinstalled in the container, and you can use it to convert the bag using the following command: `rosbags-convert --src path/to/office.bag --dst path/to/office` (in ROS2, you do not need `.bag` since a ROS 2 bag is a directory). You should run this in the container if you don't have `rosbags-convert` installed on your host machine.
121+
122+
## Quick Start (PROFILE=zed)
123+
124+
### Host (PROFILE=zed)
125+
You can repeat the steps above using the `zed` profile instead of `minimal`, but you must complete a few additional steps on the host to run with hardware.
126+
127+
1. Add the `zed-ros2-wrapper` to your workspace, and the dependencies will be installed automatically via the dockerfile (if you forget this step, you must rebuild the image):
128+
129+
```shell
130+
cd $WORKSPACE/src
131+
git clone https://github.com/stereolabs/zed-ros2-wrapper.git
132+
```
133+
134+
2. While the uhumans2 dataset has pre-segmented images, you must run semantic segmentation on the images. You can use [semantic_inference](https://github.com/MIT-SPARK/semantic_inference), which should already be installed via `ros2.yaml`. Download the default [pretrained model](https://drive.google.com/file/d/1XRcsyLSvqqhqNIaOI_vmqpUpmBT6gk9-/view?usp=drive_link) to the directory `$WORKSPACE/.models/`.
135+
136+
3. (optional) To avoid re-optimizing the model when running the container, set the `ZED_CACHE` environment variable to mount a host directory for the zed cache:
137+
138+
```shell
139+
mkdir -p "$WORKSPACE/.zed_cache"
140+
141+
cd $WORKSPACE/src/hydra_ros/docker
142+
grep -q '^ZED_CACHE=' .env || echo "ZED_CACHE=$WORKSPACE/.zed_cache" >> .env
143+
```
144+
### Container (PROFILE=zed)
145+
146+
Once inside the container, you can build and run Hydra for the zed profile (you should already be in `/root/hydra_ws` when opening the shell):
147+
148+
```shell
149+
colcon build --symlink-install --continue-on-error
150+
source install/setup.bash
151+
ros2 launch hydra_ros zed2i.launch.yaml
152+
```
153+
154+
## CUDA/TensorRT Support (PROFILE=dev)
155+
In general, you can start from the `dev` profile for development if you need CUDA and TensorRT support with Hydra (e.g., required to use [semantic_inference](https://github.com/MIT-SPARK/semantic_inference) with Hydra). You can reuse the same steps from the `minimal` profile to setup the host machine adding your software/hardware dependencies.
156+
157+
### Example with D455/T265
158+
Here, we provide another example of running Hydra with a bag recorded with a sensor payload (mounted on an `a1` quadruped) using a D455 for color/depth and T265 for visual odometry (refer to this [launch](../hydra_ros/launch/datasets/a1.launch.yaml) and [config](../hydra_ros/config/datasets/a1.yaml)), which runs with the following commands:
159+
160+
1. Run the `a1` launch script for Hydra:
161+
```bash
162+
ros2 launch hydra_ros a1.launch.yaml use_sim_time:=true
163+
```
164+
165+
2. Run the bag:
166+
```bash
167+
ros2 bag play /path/to/bag --clock --exclude-topics /tf_static
168+
```
169+
> :grey_exclamation: **Note**</br>
170+
> The static tfs are included in the launch script for the `a1`, so you should exclude them when playing the bag.

0 commit comments

Comments
 (0)