Connecting ROS 2 Nodes with the FASTRTPS_DEFAULT_PROFILES_FILE
env
- 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:
- Simple
- Discovery Server
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:
<?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:
- "talker" host
- "listener" host
export RMW_IMPLEMENTATION=rmw_fastrtps_cpp
export FASTRTPS_DEFAULT_PROFILES_FILE=/var/tmp/fastdds-simple.xml
ros2 run demo_nodes_cpp talker
export RMW_IMPLEMENTATION=rmw_fastrtps_cpp
export FASTRTPS_DEFAULT_PROFILES_FILE=/var/tmp/fastdds-simple.xml
ros2 run demo_nodes_cpp listener
Below is a demonstration using a talker-listener ROS 2 demo. Assume that ds-host
, talker-host
and listener-host
are Husarnet hostnames of the three devices in the same Husarnet group:
Create the following two files on all hosts in the same Husarnet group that you wish to connect.
You will need separate DDS configuration files for the Server and the Client:
- Server
- Client
<?xml version="1.0" encoding="UTF-8" ?>
<dds>
<profiles xmlns="http://www.eprosima.com/XMLSchemas/fastRTPS_Profiles">
<transport_descriptors>
<transport_descriptor>
<transport_id>HusarnetTransport</transport_id>
<type>UDPv6</type>
</transport_descriptor>
</transport_descriptors>
<participant profile_name="server_profile" is_default_profile="true">
<rtps>
<userTransports>
<transport_id>HusarnetTransport</transport_id>
</userTransports>
<useBuiltinTransports>true</useBuiltinTransports>
<!--
Change the id in XX field:
<prefix>44.53.XX.5f.45.50.52.4f.53.49.4d.41</prefix>
-->
<prefix>44.53.00.5f.45.50.52.4f.53.49.4d.41</prefix>
<builtin>
<discovery_config>
<discoveryProtocol>SERVER</discoveryProtocol>
</discovery_config>
<metatrafficUnicastLocatorList>
<locator>
<udpv6>
<!-- No modifications are necessary — this configuration should be run directly on the discovery server host, so the Husarnet local hostname will suffice. -->
<address>husarnet-local</address>
<port>11811</port>
</udpv6>
</locator>
</metatrafficUnicastLocatorList>
</builtin>
</rtps>
</participant>
</profiles>
</dds>
<?xml version="1.0" encoding="UTF-8" ?>
<dds>
<profiles xmlns="http://www.eprosima.com/XMLSchemas/fastRTPS_Profiles">
<transport_descriptors>
<transport_descriptor>
<transport_id>HusarnetTransport</transport_id>
<type>UDPv6</type>
</transport_descriptor>
</transport_descriptors>
<participant profile_name="client_profile" is_default_profile="true">
<rtps>
<userTransports>
<transport_id>HusarnetTransport</transport_id>
</userTransports>
<useBuiltinTransports>true</useBuiltinTransports>
<defaultUnicastLocatorList>
<locator>
<udpv6>
<address>husarnet-local</address>
</udpv6>
</locator>
</defaultUnicastLocatorList>
<builtin>
<discovery_config>
<discoveryProtocol>SUPER_CLIENT</discoveryProtocol>
<discoveryServersList>
<RemoteServer prefix="44.53.00.5f.45.50.52.4f.53.49.4d.41">
<metatrafficUnicastLocatorList>
<locator>
<udpv6>
<!-- Pasthe Discovery Server Husarnet hostname here -->
<address>ds-host</address>
<port>11811</port>
</udpv6>
</locator>
</metatrafficUnicastLocatorList>
</RemoteServer>
</discoveryServersList>
</discovery_config>
<metatrafficUnicastLocatorList>
<locator>
<udpv6>
<address>husarnet-local</address>
</udpv6>
</locator>
</metatrafficUnicastLocatorList>
</builtin>
</rtps>
</participant>
</profiles>
</dds>
Execute the following commands in the terminal:
- "Discovery Server" host
- "talker" host
- "listener" host
Let the ds-host
peer act as a Discovery Server device:
fastdds discovery -i 0 -x /var/tmp/fastdds-server.xml
The host on which you run the Discovery Server can also run ROS 2 nodes:
export RMW_IMPLEMENTATION=rmw_fastrtps_cpp
export FASTRTPS_DEFAULT_PROFILES_FILE=/var/tmp/fastdds-client.xml
ros2 run demo_nodes_cpp listener
export RMW_IMPLEMENTATION=rmw_fastrtps_cpp
export FASTRTPS_DEFAULT_PROFILES_FILE=/var/tmp/fastdds-client.xml
ros2 run demo_nodes_cpp talker
export RMW_IMPLEMENTATION=rmw_fastrtps_cpp
export FASTRTPS_DEFAULT_PROFILES_FILE=/var/tmp/fastdds-client.xml
ros2 run demo_nodes_cpp listener
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.