Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
186 changes: 186 additions & 0 deletions garden/ros2_gz_docker_bridge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
# ROS 2 + Gazebo Docker Bridge

A two-container Docker setup for running Gazebo and ROS 2 as separate services connected over a custom Docker network, with the ros_gz_bridge handling topic communication between them

---

## Compatibility

| ROS 2 | Gazebo |
|---|---|
| Rolling | Jetty |
| Kilted | Ionic |
| Jazzy | Harmonic |
| Iron | Harmonic |
| Humble | Fortress |

---

## Prerequisites

- Docker installed and running
- Both images built:
- `gazebo` — from your Gazebo Dockerfile
- `ros2` — from your ROS 2 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>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The subnet mask (/16) would need to be removed before setting GZ_IP. Can you add a statement or example about that?

},
"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
```

:::{important}
Add these to `~/.bashrc` in each container to be available across sessions.
:::

:::{note}
When setting `GZ_IP`, use only the IP address without the subnet mask. For example:

```bash
export GZ_IP=172.21.0.3
```

Do not include `/16`.
:::

---

### 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
```

See the [ros_gz_bridge examples](https://github.com/gazebosim/ros_gz/tree/ros2/ros_gz_bridge/examples) for sample configuration files.

---

## 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
```

#### Option 1: Single topic (basic)
```bash
ros2 run ros_gz_bridge parameter_bridge \
/clock@rosgraph_msgs/msg/Clock@gz.msgs.Clock
```
Comment on lines +138 to +147
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok


#### Option 2: Multiple topics
```bash
ros2 run ros_gz_bridge parameter_bridge \
/clock@rosgraph_msgs/msg/Clock@gz.msgs.Clock \
/world/default/model/vehicle/cmd_vel@geometry_msgs/msg/Twist@gz.msgs.Twist \
/world/default/model/vehicle/odometry@nav_msgs/msg/Odometry@gz.msgs.Odometry
```

#### Option 3: Using config file
```bash
ros2 run ros_gz_bridge parameter_bridge --ros-args -p config_file:=/path/to/bridge.yaml
```
See the [ros_gz_bridge examples](https://github.com/gazebosim/ros_gz/tree/ros2/ros_gz_bridge/examples) for sample configuration files.

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

50 changes: 50 additions & 0 deletions garden/tutorials.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Gazebo Tutorials

These tutorials cover general concepts to help get you started with Gazebo.

## Basics tutorials

* [Building Your Own Robot](building_robot)
* [Moving the Robot](moving_robot)
* [SDF Worlds](sdf_worlds)
* [Sensors](sensors)
* [Actors](actors)

## GUI tutorials

* [Understanding the GUI](gui)
* [Manipulating Models](manipulating_models)
* [Model Insertion from Fuel](fuel_insert)
* [Keyboard Shortcuts](hotkeys)

## ROS integration

* [Spawn URDF](spawn_urdf)
* [ROS 2 Integration](ros2_integration)
* [ROS 2 Interoperability](ros2_interop)
* [ROS 2 Integration Template](ros_gz_project_template_guide)
* [ROS 2 Cross Docker Bridge Setup](ros2_gz_docker_bridge)

## Per-library tutorials

See the *API & Tutorials* sections on the [Libraries page](/libs){.external} page for more specific content correlating to each Gazebo library.

The entrypoint library is Sim.
- [Sim](/api/sim/7/tutorials.html){.external}

Other libraries:
- [Cmake](/api/cmake/3/tutorials.html){.external}
- [Common](/api/common/5/tutorials.html){.external}
- [Fuel_tools](/api/fuel_tools/8/tutorials.html){.external}
- [Gui](/api/gui/7/tutorials.html){.external}
- [Launch](/api/launch/6/tutorials.html){.external}
- [Math](/api/math/7/tutorials.html){.external}
- [Msgs](/api/msgs/9/tutorials.html){.external}
- [Physics](/api/physics/6/tutorials.html){.external}
- [Plugin](/api/plugin/2/tutorials.html){.external}
- [Rendering](/api/rendering/7/tutorials.html){.external}
- [Sensors](/api/sensors/7/tutorials.html){.external}
- [Tools](/api/tools/2/tutorials.html){.external}
- [Transport](/api/transport/12/tutorials.html){.external}
- [Utils](/api/utils/2/tutorials.html){.external}
- [Sdformat](/api/sdformat/13/){.external}
Loading
Loading