3.4. Configuring ROS 2 Router’s Topic QoS

3.4.1. Background

eProsima ROS 2 Router, a.k.a DDS Router, is an end-user software application that enables the connection of distributed ROS 2 networks (see the ROS 2 Router documentation here). That is, ROS 2 nodes such as publishers and subscriptions, or clients and services, deployed in one geographic location and using a dedicated local network will be able to communicate with other ROS 2 nodes deployed in different geographic locations on their own dedicated local networks as if they were all on the same network through the ROS 2 Router.

This tutorial explains how to apply some configurations to individual DDS Topics forwarded by the ROS 2 Router. In particular, we will configure two participants in different domains and communicate them with a ROS 2 Router. The ROS 2 Router will configure a specific Topic for one of the participants using this new topic settings option. In particular, in this tutorial, we will fix the maximum transmission rate (max-tx-rate) of one of the topics for a specific participant, so that only this participant will apply this maximum publication rate only to this topic.

Note

This tutorial is similar to the Change ROS 2 Domain Id tutorial, since we will launch a talker and a listener on different domains and connect them with a ROS 2 Router. The difference between both tutorials is that, in this one, we will limit the transmission rate for a participant on a topic to avoid clogging the connection.

The DDS protocol defines the Domain Id as a parameter for every DomainParticipant. Different entities in different Domain Ids will never discover each other, and thus they will not communicate with each other. The ROS 2 Router can be used as a bridge between ROS 2 Domains, so that every node in a domain can communicate with every other node on another domain, as illustrated in the following figure:

../../../../_images/change_domain_topic_qos.png

This tutorial will use the demo_nodes_cpp package, available in the Vulcanexus Desktop distribution. Two ROS 2 nodes, a talker and a listener, will be launched on different ROS 2 Domains, so that they cannot communicate between each other. Then, the ROS 2 Router will be used as a bridge between the two Domains, allowing the listener to receive the messages from the talker.

3.4.2. Prerequisites

To proceed, please install Vulcanexus with one of the following installation methods:

3.4.3. Deploy ROS 2 nodes

Let us start by running the ROS 2 talker and listener nodes.

3.4.3.1. Environment setup

To run the nodes, we need to set up the Vulcanexus environment so that the demo_nodes_cpp package is available. There are two ways to achieve this:

  1. Running the Vulcanexus Docker image.

    Run the Vulcanexus Docker image by executing:

    docker run -it ubuntu-vulcanexus:iron-desktop
    

    The Docker container will automatically setup the Vulcanexus environment on start up, but in case you installed Vulcanexus from binaries please do not forget to source the Vulcanexus installation first by executing:

    source /opt/vulcanexus/iron/setup.bash
    
  2. Setting up a development environment on the local host.

    To do this, the vucanexus-iron-desktop package is needed, since it includes all the simulation tools, demos, and tutorials.

    Set up the Vulcanexus environment by executing:

    source /opt/vulcanexus/iron/setup.bash
    

3.4.3.2. Running ROS 2 nodes

3.4.3.2.1. Publish in domain 0 and subscribe in domain 1

First, run the talker and listener to communicate using the default topic of the demo_nodes_cpp ROS 2 package, that is, the chatter topic.

Run a ROS 2 demo_nodes_cpp talker on domain 0:

ROS_DOMAIN_ID=0 ros2 run demo_nodes_cpp talker

Run a ROS 2 demo_nodes_cpp listener on domain 1:

ROS_DOMAIN_ID=1 ros2 run demo_nodes_cpp listener

So far, the listener will not receive anything as the ROS 2 publisher and the ROS 2 subscription are deployed on different ROS 2 Domains.

3.4.4. Deploying a ROS 2 Router

To deploy the ROS 2 Router, we need to create its configuration file.

3.4.4.1. Configuration

The following YAML configuration file configures a ROS 2 Router with two Simple Participants in domains 0 and 1, and a topic configuration to limit the transmission rate on one of the participants for a specific topic.

Note

This configuration enables listeners in domain 1 to subscribe to messages published in domain 0, at a frequency of 1 Hz on topic secret, and at an unlimited frequency on any other topic. It also enables listeners in domain 0 to subscribe to messages published in domain 1 at an unlimited frequency on any topic.

version: v4.0

topics:
  - name: rt/secret
    qos:
      max-tx-rate: 1
    participant:
      - Ros_2_Domain_1

participants:
  - name: ROS_2_Domain_0
    kind: local
    domain: 0

  - name: ROS_2_Domain_1
    kind: local
    domain: 1

3.4.4.1.1. Simple Participants

The Simple Participants are configured with a name, a kind (local), and a domain id (0 and 1).

participants:
  - name: ROS_2_Domain_0
    kind: local
    domain: 0

  - name: ROS_2_Domain_1
    kind: local
    domain: 1

3.4.4.1.2. Topic Configuration

We define the topic under the tag topics. This topic is configured so that ROS_2_Domain_1 will publish at a maximum frequency of 1 Hz on topic secret, and at an unlimited frequency on any other topic.

topics:
  - name: rt/secret
    qos:
      max-tx-rate: 1
    participant:
      - Ros_2_Domain_1

3.4.4.2. Running the ROS 2 Router

Run the DDS Router with the configuration file available at <path/to/file>/ros_2_router_with_manual_topics.yaml.

ddsrouter -c <path/to/file>/ros_2_router_with_manual_topics.yaml

The output from the ROS 2 Router should be something like:

Starting DDS Router Tool execution.
DDS Router running.

If so, the ROS 2 Router has started correctly and it is currently running. In order to close the execution, press ^C or send a signal (SIGINT 2 or SIGTERM 15) to close it.

The listener should now receive the messages sent by the talker at an unlimited rate as they are communicating through the chatter topic.

3.4.5. Deploy ROS 2 nodes on topic secret

Let us now run the ROS 2 talker and listener nodes on the topic secret.

3.4.5.1. Running ROS 2 nodes

3.4.5.1.1. Publish in domain 0 and subscribe in domain 1 on topic secret

Run a ROS 2 demo_nodes_cpp talker on domain 0:

ROS_DOMAIN_ID=0 ros2 run demo_nodes_cpp talker --ros-args -r chatter:=secret

Run a ROS 2 demo_nodes_cpp listener on domain 1:

ROS_DOMAIN_ID=1 ros2 run demo_nodes_cpp listener --ros-args -r chatter:=secret

Since the ROS 2 Router has configured the secret topic with a max-tx-rate for the ROS_2_Domain_1 participant, the listener will receive messages at most at 1 Hz and it will print them in stdout.

3.4.5.1.2. Publish in domain 1 and subscribe in domain 0 on topic secret

Run a ROS 2 demo_nodes_cpp talker on domain 1:

ROS_DOMAIN_ID=1 ros2 run demo_nodes_cpp talker --ros-args -r chatter:=secret

Run a ROS 2 demo_nodes_cpp listener on domain 0:

ROS_DOMAIN_ID=0 ros2 run demo_nodes_cpp listener --ros-args -r chatter:=secret

Since the ROS 2 Router does not have a specific topic configuration for the topic secret on the ROS_2_Domain_0 participant, the listener will receive messages at an unlimited rate and it will print them in stdout.

3.4.6. Next steps

For all possible configurations that can be applied to the ROS 2 Router topics please refer to the Topic QoS section of the DDS Router documentation.