You're reading the documentation for a development version. For the latest released version, please have a look at Jazzy.
Improved Dynamic Discovery
Goal: This tutorial will show how to use the improved dynamic discovery configuration.
Tutorial level: Advanced
Time: 15 minutes
Overview
By default, ROS 2 will attempt to find all nodes on all hosts on the same subnet automatically. However, the following options are available to control the ROS 2 discovery range.
Configuration Parameters
ROS_AUTOMATIC_DISCOVERY_RANGE
: controls how far ROS nodes will try to discover each other.Valid options are:
SUBNET
is the default, and for DDS based middleware it means it will discover any node reachable via multicast.LOCALHOST
means a node will only try to discover other nodes on the same machine.OFF
means the node won’t discover any other nodes, even on the same machine.SYSTEM_DEFAULT
means “don’t change any discovery settings”.
ROS_STATIC_PEERS
: is a semicolon (;
) separated list of addresses that ROS should try to discover nodes on. This allows connecting to nodes on specific machines (as long as their discovery range is not set toOFF
).
The combination of these two environment variables for local and remote nodes will enable and control the ROS 2 communication discovery range. The following tables highlight the discovery range behavior for possible combination.
A X
indicates that nodes A and B will not discover each other and communicate.
A O
indicates that nodes A and B will discover each other and communicate.
Same host |
Node B setting |
|||||||
---|---|---|---|---|---|---|---|---|
No static peer |
With static peer |
|||||||
Off |
Localhost |
Subnet |
Off |
Localhost |
Subnet |
|||
Node A setting |
No static peer |
Off |
|
|
|
|
|
|
Localhost |
|
|
|
|
|
|
||
Subnet |
|
|
|
|
|
|
||
With static peer |
Off |
|
|
|
|
|
|
|
Localhost |
|
|
|
|
|
|
||
Subnet |
|
|
|
|
|
|
Different hosts |
Node B setting |
|||||||
---|---|---|---|---|---|---|---|---|
No static peer |
With static peer |
|||||||
Off |
Localhost |
Subnet |
Off |
Localhost |
Subnet |
|||
Node A setting |
No static peer |
Off |
|
|
|
|
|
|
Localhost |
|
|
|
|
|
|
||
Subnet |
|
|
|
|
|
|
||
With static peer |
Off |
|
|
|
|
|
|
|
Localhost |
|
|
|
|
|
|
||
Subnet |
|
|
|
|
|
|
Examples
For example, the following commands will limit the ROS 2 communication only with localhost and specific peers:
export ROS_AUTOMATIC_DISCOVERY_RANGE=LOCALHOST
export ROS_STATIC_PEERS=192.168.0.1;remote.com
To maintain this setting between shell sessions, you can add the command to your shell startup script:
echo "export ROS_AUTOMATIC_DISCOVERY_RANGE=LOCALHOST" >> ~/.bashrc
echo "export ROS_STATIC_PEERS=192.168.0.1;remote.com" >> ~/.bashrc
export ROS_AUTOMATIC_DISCOVERY_RANGE=LOCALHOST
export ROS_STATIC_PEERS=192.168.0.1;remote.com
To maintain this setting between shell sessions, you can add the command to your shell startup script:
echo "export ROS_AUTOMATIC_DISCOVERY_RANGE=LOCALHOST" >> ~/.bash_profile
echo "export ROS_STATIC_PEERS=192.168.0.1;remote.com" >> ~/.bash_profile
set ROS_AUTOMATIC_DISCOVERY_RANGE=LOCALHOST
set ROS_STATIC_PEERS=192.168.0.1;remote.com
If you want to make this permanent between shell sessions, also run:
setx ROS_AUTOMATIC_DISCOVERY_RANGE LOCALHOST
setx ROS_STATIC_PEERS 192.168.0.1;remote.com