3. ROS2 Discovery Server Example¶
In the following snippet we see a yaml file to configure a DDS Router to create a
Simple Participant in domain 0
and a
Local Discovery Server with ROS 2 configuration.
##################################
# CONFIGURATION VERSION
version: v5.0 # 0
##################################
# ALLOWED TOPICS
# Allowing ROS2 HelloWorld demo_nodes topic
allowlist:
- name: rt/chatter # 1
type: std_msgs::msg::dds_::String_ # 1
##################################
# PARTICIPANTS
participants:
##################################
# SIMPLE PARTICIPANT
# This participant will subscribe to topics in allowlist in domain 0 and listen every message published there
- name: SimpleROS2 # 2
kind: local # 3
domain: 0 # 4
##################################
# ROS DISCOVERY SERVER
# This participant will subscribe to topics in allowlist using Discovery Server protocol as Server
- name: ServerROS2 # 5
kind: local-discovery-server # 6
discovery-server-guid:
ros-discovery-server: true # 7
id: 1 # 8
listening-addresses: # 9
- domain: localhost # 10
port: 11888 # 11
3.1. Configuration¶
3.1.1. Allowed Topics¶
In this section are the Topics that the DDS Router will route from
one Participant to the other.
Topic HelloWorldTopic
with datatype HelloWorld
,
and ROS 2 topic rt/chatter
with datatype std_msgs::msg::dds_::String_
will be forwarded from
one domain to the other, allowing different DDS domains to interact to each other.
allowlist:
- name: rt/chatter # 1
type: std_msgs::msg::dds_::String_ # 1
3.1.2. Simple Participant¶
This Participant is configured by a name, a kind and the Domain Id, in this case 0
.
- name: SimpleROS2 # 2
kind: local # 3
domain: 0 # 4
3.1.3. Discovery Server Participant¶
This Participant is configured by a name, a kind and a listening addresses where Discovery Server will expect metatraffic data from clients.
- name: ServerROS2 # 5
kind: local-discovery-server # 6
discovery-server-guid:
ros-discovery-server: true # 7
id: 1 # 8
listening-addresses: # 9
- domain: localhost # 10
port: 11888 # 11
3.2. Execute example¶
For a detailed explanation on how to execute the DDS Router, refer to this section.
Execute a ROS 2 demo_nodes_cpp
talker in domain 0
:
ROS_DOMAIN_ID=0 ros2 run demo_nodes_cpp talker
Execute a ROS 2 demo_nodes_cpp
listener using Discovery Server as Discovery Protocol:
ROS_DISCOVERY_SERVER=";127.0.0.1:11888" ros2 run demo_nodes_cpp listener
Execute DDS Router with this configuration file (available in
<path/to/ddsrouter_tool>/share/resources/configurations/examples/ros_discovery_server.yaml
).
Once the DDS Router is running, messages from talker in domain 0 will be forwarded by the Router
to the listener using Discovery Server, that will print them in stdout
.