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.

##################################
# ALLOWED TOPICS
# Allowing ROS2 HelloWorld demo_nodes topic

allowlist:
  [
    {name: "rt/chatter", type: "std_msgs::msg::dds_::String_"},  # 1
  ]

##################################
# SIMPLE PARTICIPANT
# This participant will subscribe to topics in allowlist in domain 0 and listen every message published there

SimpleROS2:                       # 2
  type: local                     # 3
  domain: 0                       # 4

##################################
# ROS DISCOVERY SERVER
# This participant will subscribe to topics in allowlist using Discovery Server protocol as Server

ServerROS2:                         # 5
  type: local-discovery-server      # 6
  ros-discovery-server: true        # 7
  id: 1                             # 8
  listening-addresses:              # 9
  [
    {
      ip: "127.0.0.1",              # 10
      port: 11888                   # 11
    },                              # 12
  ]

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", type: "std_msgs::msg::dds_::String_"},  # 1
  ]

3.1.2. Simple Participant

This Participant is configured by a name, a type and the Domain Id, in this case 0.

SimpleROS2:                       # 2
  type: local                     # 3
  domain: 0                       # 4

3.1.3. Discovery Server Participant

This Participant is configured by a name, a type and a listening addresses where Discovery Server will expect metatraffic data from clients.

ServerROS2:                         # 5
  type: local-discovery-server      # 6
  ros-discovery-server: true        # 7
  id: 1                             # 8
  listening-addresses:              # 9
  [
    {
      ip: "127.0.0.1",              # 10
      port: 11888                   # 11
    },                              # 12
  ]

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>/src/ddsrouter/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.