Skip to main content

Connecting ROS 2 Nodes with the husarnet/ros2router Docker Image

info
  • Level: 🏜️ medium
  • Compatible ROS distributions: ROS 2 Humble, ROS 2 Jazzy, ROS 2 Foxy
  • Compatible RMW implementations: rmw_fastrtps_cpp, rmw_cyclonedds_cpp

Previous setups required a custom DDS configuration or the use of ROS 2 environment variables only available in the latest ROS 2 distribution.

To enable connecting already running ROS 2 nodes over Husarnet without altering their setup, we've created the husarnet/ros2router Docker Image. This image is based on the DDSRouter project by eProsima.

The husarnet/ros2router acts as a bridge between locally running ROS 2 networks and remote ROS 2 networks connected over Husarnet.

Before running husarnet/ros2router on your hosts, create the following file on each host:

compose.yaml
services:
ros2router:
image: husarnet/ros2router:1.9.2
restart: always
network_mode: host
ipc: host
volumes:
- ./filter.yaml:/filter.yaml
environment:
- PARTICIPANTS=husarnet,lo
- ROS_DISCOVERY_SERVER=;;;talker-host
- USER

Please note that the Discovery Server will run on the talker-host with id=3 (indicated by three semicolons before the hostname/address).

Also, note that we are bind-mounting the filter.yaml file, which allows you to select which ROS 2 topics or services will be forwarded by husarnet/ros2router. Other topics will be filtered out. For this example, use the following filter file:

filter.yaml
---
allowlist:
- name: "rt/chatter"
type: "std_msgs::msg::dds_::String_"

blocklist: []

Examples

Below is a demonstration using a talker-listener ROS 2 demo. Assume that talker-host and listener-host are Husarnet hostnames of the two devices in the same Husarnet group:

Host Setup

Run the chatter node with:

joe@talker-host
export ROS_LOCALHOST_ONLY=1 # if your hosts are in the same LAN network - to make sure the traffic goes through Husarnet
ros2 run demo_nodes_cpp talker

Next, open a new terminal and launch the husarnet/ros2router:

docker compose up

Docker Setup

You can also run the full demo on the same host by running Husarnet within Docker containers:

👉 See the full ros2router/basic example here.

👉 See the full ros2router/discovery-server example here.