Skip to main content

Connecting ROS 2 Nodes with the ROS_DISCOVERY_SERVER env

info
  • Level: 🌴 easy
  • Compatible ROS distributions: ROS 2 Jazzy, ROS 2 Iron
  • Compatible RMW implementations: rmw_fastrtps_cpp

Fast DDS provides an alternative discovery mechanism based on Discovery Server. In addition to its performance benefits, it offers an easy way to connect ROS 2 nodes running on different Husarnet-connected hosts.

This approach is superior to using the ROS_STATIC_PEERS environment variable because it allows new hosts to join the ROS 2 network dynamically without requiring the nodes on all peers to be restarted with an updated ROS_STATIC_PEERS. In its minimal configuration, ROS_DISCOVERY_SERVER requires only one peer to act as a Discovery Server; however, you can add multiple such peers as a backup option.

The ROS_SUPER_CLIENT environment variable, as used in the example, can launch a DDS entity as a Super Client with more discovery information (without setting the ROS_SUPER_CLIENT environment variable to TRUE, you will not see all ROS 2 topics with ros2 topic list).

Examples

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

Host Setup

This FastDDS CLI command runs the Discovery Server on an arbitrarily chosen host within the Husarnet group. You can execute it on any host, such as your laptop, a random Husarnet-connected server, or directly on the robot with the following command in the terminal:

joe@ds-host
fastdds discovery -i 0 -l husarnet-local -p 11811

This command starts the Discovery Server with id=0, listening for connections on the IPv6 address provided by Husarnet (husarnet-local is an alternative hostname to ds-host in this example) on port 11811.

tip

The host running the Discovery Server can simultaneously run ROS 2 nodes:

joe@ds-host
export RMW_IMPLEMENTATION=rmw_fastrtps_cpp
export ROS_SUPER_CLIENT=TRUE
export ROS_DISCOVERY_SERVER=ds-host:11811

ros2 run demo_nodes_cpp listener

Docker Setup

Create the following file:

compose.yaml
services:
ds:
image: ros:jazzy-ros-core
network_mode: host
command: fastdds discovery -i 0 -l husarnet-local -p 11811

Then, execute the following command:

joe@ds-host
docker compose up
tip

You can also run the Docker-based demo on the same host, by running Husarnet within the container:

👉 See the full ros-discovery-server example here.