Skip to main content

Connecting ROS 2 Nodes with the FASTRTPS_DEFAULT_PROFILES_FILE env

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

You can create a custom DDS configuration file and load it using the FASTRTPS_DEFAULT_PROFILES_FILE environment variable. This file needs to be updated whenever you add a new host to the Husarnet group.

There are many configuration options available, as described in the FastDDS manual.

Examples

Host Setup

A basic Husarnet configuration for the Discovery Server and for Simple Discovery (default for DDS) might look like this:

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/fastdds-simple.xml
<?xml version="1.0" encoding="UTF-8" ?>
<dds>
<profiles xmlns="http://www.eprosima.com/XMLSchemas/fastRTPS_Profiles">
<transport_descriptors>
<transport_descriptor>
<transport_id>husarnet_transport</transport_id>
<type>UDPv6</type>
</transport_descriptor>
</transport_descriptors>

<participant profile_name="husarnet_simple_profile" is_default_profile="true">
<rtps>
<userTransports>
<transport_id>husarnet_transport</transport_id>
</userTransports>
<useBuiltinTransports>true</useBuiltinTransports>
<defaultUnicastLocatorList>
<locator>
<udpv6>
<address>husarnet-local</address>
</udpv6>
</locator>
</defaultUnicastLocatorList>
<builtin>
<initialPeersList>
<!-- Paste Husarnet Peers here... Start -->
<locator>
<udpv6>
<address>listener-host</address> <!-- or <address>fc94:a67f:2b47:756c:6e1c:7c05:7361:7378</address> -->
</udpv6>
</locator>
<locator>
<udpv6>
<address>talker-host</address> <!-- or <address>fc94:6260:26e:e057:9bc:8786:4f8a:c7a6</address> -->
</udpv6>
</locator>
<!-- End -->
</initialPeersList>
<metatrafficUnicastLocatorList>
<locator>
<udpv6>
<address>husarnet-local</address>
</udpv6>
</locator>
</metatrafficUnicastLocatorList>
</builtin>
</rtps>
</participant>
</profiles>
</dds>

Execute the following commands in the terminal:

joe@talker-host
export RMW_IMPLEMENTATION=rmw_fastrtps_cpp
export FASTRTPS_DEFAULT_PROFILES_FILE=/var/tmp/fastdds-simple.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 fastrtps-default-profiles-file (Simple Discovery) example here.

👉 See the full fastrtps-default-profiles-file (Discovery Server) example here.