Skip to main content

Connecting ROS 2 Nodes with the CYCLONEDDS_URI env

info
  • Level: 🏜️ medium
  • Compatible ROS distributions: ROS 2 Jazzy, ROS 2 Humble, ROS 2 Foxy
  • Compatible RMW implementations: rmw_cyclonedds_cpp

You can create a custom DDS configuration file and load it using the CYCLONEDDS_URI environment variable. This file must be kept updated whenever a new host is added to the network. For advanced setups, you can find all available options here.

Examples

Host Setup

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

Create the following file on all hosts in the same Husarnet group you wish to connect:

/var/tmp/cyclonedds.xml
<?xml version="1.0" encoding="UTF-8" ?>
<CycloneDDS xmlns="https://cdds.io/config" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://cdds.io/config https://raw.githubusercontent.com/eclipse-cyclonedds/cyclonedds/master/etc/cyclonedds.xsd">
<Domain Id="any">
<General>
<Interfaces>
<NetworkInterface name="hnet0"/>
</Interfaces>
<AllowMulticast>false</AllowMulticast>
<FragmentSize>1194B</FragmentSize><!-- default: 1344 B minus Husarnet metadata (~150 B) -->
<Transport>udp6</Transport>
</General>
<Discovery>
<Peers>
<Peer Address="talker-host" /> <!-- or <Peer address="fc94:a67f:2b47:756c:6e1c:7c05:7361:7378"/> -->
<Peer Address="listener-host" /> <!-- or <Peer address="fc94:6260:26e:e057:9bc:8786:4f8a:c7a6"/> -->
</Peers>
<ParticipantIndex>auto</ParticipantIndex>
<MaxAutoParticipantIndex>40</MaxAutoParticipantIndex>
</Discovery>
</Domain>
</CycloneDDS>

Execute the following commands in the terminal:

joe@talker-host
export RMW_IMPLEMENTATION=rmw_cyclonedds_cpp
export CYCLONEDDS_URI=file:///var/tmp/cyclonedds.xml

ros2 run demo_nodes_cpp talker

Docker Setup

You can also run the Docker-based demo (both on the same host and different hosts), by running Husarnet within the container:

👉 See the full cyclonedds-uri example here.