-
Notifications
You must be signed in to change notification settings - Fork 301
docs: add ROS2 + Gazebo Docker bridge setup guide for harmonic, ionic… #682
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
9a91fd6
cff2d60
9a0f984
3cb72f6
6fc1d56
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,174 @@ | ||||||||||
| # ROS2 + Gazebo Docker Bridge | ||||||||||
|
|
||||||||||
| A two-container Docker setup for running Gazebo and ROS2 as separate services connected over a custom Docker network, with the ros_gz_bridge handling topic communication between them | ||||||||||
|
|
||||||||||
| --- | ||||||||||
|
|
||||||||||
| ## Compatibility | ||||||||||
|
|
||||||||||
| | ROS2 | Gazebo | | ||||||||||
| |---|---| | ||||||||||
| | Rolling | Jetty | | ||||||||||
| | Kilted | Ionic | | ||||||||||
| | Jazzy | Harmonic | | ||||||||||
| | Iron | Harmonic | | ||||||||||
| | Humble | Fortress | | ||||||||||
|
|
||||||||||
| --- | ||||||||||
|
|
||||||||||
| ## Prerequisites | ||||||||||
|
|
||||||||||
| - Docker installed and running | ||||||||||
| - Both images built: | ||||||||||
| - `gazebo` — from `dockerfile.gazebo` | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes docker image for gazebo i have specified as docker.gazebo same for ros as docker.ros
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||||||||||
| - `ros2` — from your ROS2 Dockerfile | ||||||||||
| - `ros-gz-bridge` installed | ||||||||||
|
|
||||||||||
| --- | ||||||||||
|
|
||||||||||
| ## Setup | ||||||||||
|
|
||||||||||
| ### 1. Create the Docker Network | ||||||||||
|
|
||||||||||
| ```bash | ||||||||||
| docker network create ros-link | ||||||||||
| ``` | ||||||||||
|
|
||||||||||
| ### 2. Start Containers | ||||||||||
|
|
||||||||||
| ```bash | ||||||||||
| docker run -it -d --name gazebo-container --network ros-link gazebo sleep infinity | ||||||||||
| docker run -it -d --name ros2-container --network ros-link ros2 sleep infinity | ||||||||||
| ``` | ||||||||||
|
|
||||||||||
| ### 3. Check Container IPs | ||||||||||
|
|
||||||||||
|
|
||||||||||
| ```bash | ||||||||||
| docker network inspect ros-link | ||||||||||
| ``` | ||||||||||
|
|
||||||||||
| Example output: | ||||||||||
| ```json | ||||||||||
| [ | ||||||||||
| { | ||||||||||
| "Name": "ros-link", | ||||||||||
| "Driver": "bridge", | ||||||||||
| "IPAM": { | ||||||||||
| "Config": [{ "Subnet": "172.21.0.0/16", "Gateway": "172.21.0.1" }] | ||||||||||
| }, | ||||||||||
| "Containers": { | ||||||||||
| "281b3cbfba6a...": { | ||||||||||
| "Name": "ros2-container", | ||||||||||
| "IPv4Address": "172.21.0.3/16" //<ros-ip> | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The subnet mask ( |
||||||||||
| }, | ||||||||||
| "c2410d610249...": { | ||||||||||
| "Name": "gazebo-container", | ||||||||||
| "IPv4Address": "172.21.0.2/16" //<gz-ip> | ||||||||||
| } | ||||||||||
| } | ||||||||||
| } | ||||||||||
| ] | ||||||||||
| ``` | ||||||||||
|
|
||||||||||
| --- | ||||||||||
|
|
||||||||||
| ### 4. Configure Environment Variables | ||||||||||
|
|
||||||||||
| **In `gazebo-container`:** | ||||||||||
| ```bash | ||||||||||
| export GZ_IP=<gz-ip> | ||||||||||
| export GZ_PARTITION=gazebo-container | ||||||||||
| ``` | ||||||||||
|
|
||||||||||
| **In `ros2-container`:** | ||||||||||
| ```bash | ||||||||||
| export GZ_IP=<ros-ip> | ||||||||||
| export GZ_PARTITION=gazebo-container | ||||||||||
| source /opt/ros/<ros-distro>/setup.bash | ||||||||||
| ``` | ||||||||||
|
|
||||||||||
| > Add these to `~/.bashrc` in each container to be available across sessions. | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you emphasize this more since the commands below won't work without it? You can use an admonition like so
Suggested change
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok ill make the changes |
||||||||||
|
|
||||||||||
| --- | ||||||||||
|
|
||||||||||
| ### 5. Install the Bridge | ||||||||||
|
|
||||||||||
| ```bash | ||||||||||
| apt-get update && apt-get install -y ros-<ros-distro>-ros-gz-bridge | ||||||||||
| ``` | ||||||||||
|
|
||||||||||
| --- | ||||||||||
|
|
||||||||||
| ## Using a Config File (optional) | ||||||||||
|
|
||||||||||
| if you have a `bridge.yaml` config file, you can use it instead of passing topics as arguments: | ||||||||||
|
|
||||||||||
| ```bash | ||||||||||
| ros2 run ros_gz_bridge parameter_bridge --ros-args -p config_file:=/path/to/bridge.yaml | ||||||||||
| ``` | ||||||||||
|
|
||||||||||
| a typical `bridge.yaml` looks like this: | ||||||||||
|
|
||||||||||
| ```yaml | ||||||||||
| - ros_topic_name: /clock | ||||||||||
| gz_topic_name: /clock | ||||||||||
| ros_type_name: rosgraph_msgs/msg/Clock | ||||||||||
| gz_type_name: gz.msgs.Clock | ||||||||||
| direction: GZ_TO_ROS | ||||||||||
| ``` | ||||||||||
|
|
||||||||||
| --- | ||||||||||
|
|
||||||||||
| ## Running the Bridge | ||||||||||
|
|
||||||||||
| ### Terminal 1 — Start Gazebo sim | ||||||||||
|
|
||||||||||
| ```bash | ||||||||||
| docker exec -it gazebo-container bash | ||||||||||
| gz sim shapes.sdf | ||||||||||
| ``` | ||||||||||
|
|
||||||||||
| ### Terminal 2 — Start the bridge | ||||||||||
|
|
||||||||||
| ```bash | ||||||||||
| docker exec -it ros2-container bash | ||||||||||
| source /opt/ros/<ros-distro>/setup.bash | ||||||||||
| ros2 run ros_gz_bridge parameter_bridge \ | ||||||||||
| /clock@rosgraph_msgs/msg/Clock@gz.msgs.Clock | ||||||||||
| ``` | ||||||||||
|
Comment on lines
+138
to
+147
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should clarify that this step is not needed if using the yaml method mentioned above.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok |
||||||||||
|
|
||||||||||
| ### Terminal 3 — Verify | ||||||||||
|
|
||||||||||
| ```bash | ||||||||||
| docker exec -it ros2-container bash | ||||||||||
| source /opt/ros/<ros-distro>/setup.bash | ||||||||||
| ros2 topic echo /clock | ||||||||||
| ``` | ||||||||||
| if you see something like this :- | ||||||||||
| ```bash | ||||||||||
| clock: | ||||||||||
| sec: 0 | ||||||||||
| nanosec: 0 | ||||||||||
| --- | ||||||||||
| clock: | ||||||||||
| sec: 0 | ||||||||||
| nanosec: 0 | ||||||||||
| --- | ||||||||||
| clock: | ||||||||||
| sec: 0 | ||||||||||
| nanosec: 0 | ||||||||||
| --- | ||||||||||
| ``` | ||||||||||
| then the connection between the two docker containers is succesfull | ||||||||||
|
|
||||||||||
| --- | ||||||||||
|
|
||||||||||
| ## Final Network Info | ||||||||||
|
|
||||||||||
| | Container | IP | Role | | ||||||||||
| |---|---|---| | ||||||||||
| | `gazebo-container` | `<gz-ip>` | Runs Gazebo simulation | | ||||||||||
| | `ros2-container` | `<ros-ip>` | Runs ROS2 + bridge | | ||||||||||
|
|
||||||||||
| Network name: `ros-link` | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this is necessary |
||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,7 @@ These tutorials cover general concepts to help get you started with Gazebo. | |
| * [ROS 2 Integration](ros2_integration) | ||
| * [ROS 2 Interoperability](ros2_interop) | ||
| * [ROS 2 Integration Template](ros_gz_project_template_guide) | ||
| * [ROS 2 Docker Bridge Setup](ros2_gz_docker_bridge) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is specifically addressing cross-container communuication, the title should indicate that. |
||
|
|
||
| ## Per-library tutorials | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,174 @@ | ||
| # ROS2 + Gazebo Docker Bridge | ||
|
|
||
| A two-container Docker setup for running Gazebo and ROS2 as separate services connected over a custom Docker network, with the ros_gz_bridge handling topic communication between them | ||
|
|
||
| --- | ||
|
|
||
| ## Compatibility | ||
|
|
||
| | ROS2 | Gazebo | | ||
| |---|---| | ||
| | Rolling | Jetty | | ||
| | Kilted | Ionic | | ||
| | Jazzy | Harmonic | | ||
| | Iron | Harmonic | | ||
| | Humble | Fortress | | ||
|
|
||
| --- | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - Docker installed and running | ||
| - Both images built: | ||
| - `gazebo` — from `dockerfile.gazebo` | ||
| - `ros2` — from your ROS2 Dockerfile | ||
| - `ros-gz-bridge` installed | ||
|
|
||
| --- | ||
|
|
||
| ## Setup | ||
|
|
||
| ### 1. Create the Docker Network | ||
|
|
||
| ```bash | ||
| docker network create ros-link | ||
| ``` | ||
|
|
||
| ### 2. Start Containers | ||
|
|
||
| ```bash | ||
| docker run -it -d --name gazebo-container --network ros-link gazebo sleep infinity | ||
| docker run -it -d --name ros2-container --network ros-link ros2 sleep infinity | ||
| ``` | ||
|
|
||
| ### 3. Check Container IPs | ||
|
|
||
|
|
||
| ```bash | ||
| docker network inspect ros-link | ||
| ``` | ||
|
|
||
| Example output: | ||
| ```json | ||
| [ | ||
| { | ||
| "Name": "ros-link", | ||
| "Driver": "bridge", | ||
| "IPAM": { | ||
| "Config": [{ "Subnet": "172.21.0.0/16", "Gateway": "172.21.0.1" }] | ||
| }, | ||
| "Containers": { | ||
| "281b3cbfba6a...": { | ||
| "Name": "ros2-container", | ||
| "IPv4Address": "172.21.0.3/16" //<ros-ip> | ||
| }, | ||
| "c2410d610249...": { | ||
| "Name": "gazebo-container", | ||
| "IPv4Address": "172.21.0.2/16" //<gz-ip> | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ### 4. Configure Environment Variables | ||
|
|
||
| **In `gazebo-container`:** | ||
| ```bash | ||
| export GZ_IP=<gz-ip> | ||
| export GZ_PARTITION=gazebo-container | ||
| ``` | ||
|
|
||
| **In `ros2-container`:** | ||
| ```bash | ||
| export GZ_IP=<ros-ip> | ||
| export GZ_PARTITION=gazebo-container | ||
| source /opt/ros/<ros-distro>/setup.bash | ||
| ``` | ||
|
|
||
| > Add these to `~/.bashrc` in each container to be available across sessions. | ||
|
|
||
| --- | ||
|
|
||
| ### 5. Install the Bridge | ||
|
|
||
| ```bash | ||
| apt-get update && apt-get install -y ros-<ros-distro>-ros-gz-bridge | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Using a Config File (optional) | ||
|
|
||
| if you have a `bridge.yaml` config file, you can use it instead of passing topics as arguments: | ||
|
|
||
| ```bash | ||
| ros2 run ros_gz_bridge parameter_bridge --ros-args -p config_file:=/path/to/bridge.yaml | ||
| ``` | ||
|
|
||
| a typical `bridge.yaml` looks like this: | ||
|
|
||
| ```yaml | ||
| - ros_topic_name: /clock | ||
| gz_topic_name: /clock | ||
| ros_type_name: rosgraph_msgs/msg/Clock | ||
| gz_type_name: gz.msgs.Clock | ||
| direction: GZ_TO_ROS | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Running the Bridge | ||
|
|
||
| ### Terminal 1 — Start Gazebo sim | ||
|
|
||
| ```bash | ||
| docker exec -it gazebo-container bash | ||
| gz sim shapes.sdf | ||
| ``` | ||
|
|
||
| ### Terminal 2 — Start the bridge | ||
|
|
||
| ```bash | ||
| docker exec -it ros2-container bash | ||
| source /opt/ros/<ros-distro>/setup.bash | ||
| ros2 run ros_gz_bridge parameter_bridge \ | ||
| /clock@rosgraph_msgs/msg/Clock@gz.msgs.Clock | ||
| ``` | ||
|
|
||
| ### Terminal 3 — Verify | ||
|
|
||
| ```bash | ||
| docker exec -it ros2-container bash | ||
| source /opt/ros/<ros-distro>/setup.bash | ||
| ros2 topic echo /clock | ||
| ``` | ||
| if you see something like this :- | ||
| ```bash | ||
| clock: | ||
| sec: 0 | ||
| nanosec: 0 | ||
| --- | ||
| clock: | ||
| sec: 0 | ||
| nanosec: 0 | ||
| --- | ||
| clock: | ||
| sec: 0 | ||
| nanosec: 0 | ||
| --- | ||
| ``` | ||
| then the connection between the two docker containers is succesfull | ||
|
|
||
| --- | ||
|
|
||
| ## Final Network Info | ||
|
|
||
| | Container | IP | Role | | ||
| |---|---|---| | ||
| | `gazebo-container` | `<gz-ip>` | Runs Gazebo simulation | | ||
| | `ros2-container` | `<ros-ip>` | Runs ROS2 + bridge | | ||
|
|
||
| Network name: `ros-link` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: "ROS 2" (with a space), here and elsewhere.