Using Husarnet & ROS 2
ROS 2 and DDS Implementation
Both ROS and ROS 2 allows you to run nodes on different physical machines as long as they are in the same LAN network. Therefore to run ROS on robotic system distributed among multiple networks VPN is needed.
Husarnet is a peer-to-peer, low-latency and lightweight VPN dedicated for robotics applications. In this short guide we will show you how to configure ROS 2 to make it work with Husarnet VPN client.
info
Basically "configure ROS 2" means "configure DDS" that is an abstraction layer ROS 2 is based on. To use Husarnet with DDS some preconfiguration is needed. The specific configuration depends on which DDS implementation is used, but generally peers from Husarnet should be added to an XML configuration file.
In the next sections we will present how to configure two most popular DDS implementations on system running ROS 2: Eclipse Cyclone DDS and eProsima Fast DDS. They both just work with Husarnet so the choice is yours.
Let's start with creating a VPN network for your devices...
Install Husarnet VPN client
Execute this command on each physical device you need to connect.
curl https://install.husarnet.com/install.sh | sudo bash
Remember to run:
sudo systemctl restart husarnet
after installation process is finished.
Creating Husarnet network
Add your physical devices to the same Husarnet network, by executing following commands on each of them:
husarnet join <your-join-code> <device-hostname>
More information at: Getting Started Guide for Linux
Using Cyclone DDS
Install
Default DDS implementation used in ROS 2 Dashing is RMW FastRTPS. We will replace that by Eclipse Cyclone DDS. There are two options: install from sources or from apt package.
1# from sources
When using ROS 2 Foxy and later you can skip this step and install as a binary package
cd ros2_ws/src
git clone -b dashing-eloquent https://github.com/ros2/rmw_cyclonedds.git
git clone https://github.com/eclipse-cyclonedds/cyclonedds
cd ..
rosdep install --from src -i
colcon build
export RMW_IMPLEMENTATION=rmw_cyclonedds_cpp
2# from apk
In ROS 2 later than Dashing you can install as apt package
apt install ros-eloquent-rmw-cyclonedds-cpp
or
apt install ros-foxy-rmw-cyclonedds-cpp
Configure
Create communication settings file under this path ~/ros2_ws/src/cyclonedds/cyclonedds.xml
To make communication work you have to set some params as follows:
You can provide Peer as IPv6 address or hostname from Husarnet.
IMPORTANT: Provide all peers <hostnames/IPv6 address>, (chose one) in every machine remember to use [] .
<?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>
<NetworkInterfaceAddress>auto</NetworkInterfaceAddress>
<AllowMulticast>false</AllowMulticast>
<MaxMessageSize>65500B</MaxMessageSize>
<FragmentSize>4000B</FragmentSize>
<Transport>udp6</Transport>
</General>
<Discovery>
<Peers>
<Peer address="[IPV6-address]"/> <!-- example: <Peer address="[fc94:dd2c:a2e6:d645:1a36:****:****:****]"/> -->
<Peer address="[hostname]"/> <!-- example: <Peer address="[my-laptop]"/> -->
</Peers>
<ParticipantIndex>auto</ParticipantIndex>
</Discovery>
<Internal>
<Watermarks>
<WhcHigh>500kB</WhcHigh>
</Watermarks>
</Internal>
<Tracing>
<Verbosity>severe</Verbosity>
<OutputFile>stdout</OutputFile>
</Tracing>
</Domain>
</CycloneDDS>
Important fields:
Multicast
<AllowMulticast>false</AllowMulticast>
. At the time of writing this file multicast is not supported by Husarnet so it's necessary to disable this. Multicast feature will be added soon.Transport Protocol
<Transport>udp6</Transport>
. It's necessary to use IPv6 but Cyclone doesn't allow to mix IPv4 with IPv6 so every node must communicate over IPv6.IPV6-address
<Peers><Peer address="[IPV6-address]"/></Peers>
. Here appropriate IP addresses should be filled, you can take this address form Husarnet WebUI. Safe method is to provide address of local IPv6 and remote machines.
If you need information about params check cyclonedds-manual
Auto-start
Add changes to .bashrc file to use that configuration every time you boot your system. Open a new terminal and execute:
echo "export RMW_IMPLEMENTATION=rmw_cyclonedds_cpp" >> ~/.bashrc
echo "export CYCLONEDDS_URI=file:///home/$USER/ros2_ws/src/cyclonedds/cyclonedds.xml" >> ~/.bashrc
. ~/.bashrc
Test
Run demo publisher and subscriber:
At the first physical machine execute in the terminal:
ros2 run demo_nodes_cpp talker`
And this command at the second:
ros2 topic echo /chatter
Using Fast DDS
Configure
Create a Fast DDS configuration file in your ROS 2 workspace: ~/ros2_ws/fastdds_husarnet.xml
To make the communication work, you have to set some parameters as shown in the following template.
IMPORTANT: Provide all peers under initialPeersList
tag.
<?xml version="1.0" encoding="UTF-8" ?>
<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="CustomHusarnetParticipant" is_default_profile="true">
<rtps>
<userTransports>
<transport_id>HusarnetTransport</transport_id>
</userTransports>
<builtin>
<initialPeersList>
<!-- Repeat this part for each husernet peer -->
<locator>
<udpv6>
<address>[IPV6-address]</address>
<port>7412</port>
</udpv6>
</locator>
<!-- End repeat -->
</initialPeersList>
</builtin>
</rtps>
</participant>
</profiles>
Auto-start
Set this file as default profile in your .bashrc
file, so as to use this configuration every time you boot your system. Open a new terminal and execute:
echo "export FASTRTPS_DEFAULT_PROFILES_FILE=/home/$USER/ros2_ws/fastdds_husarnet.xml" >> ~/.bashrc
. ~/.bashrc
Test
Now you will be able to use your default ROS 2 tools with Husarnet:
# On one node:
ros2 topic pub /test_topic std_msgs/Int32 '{data: 1}'
# On the other node:
ros2 topic echo /test_topic
Summary
As you can see using Husarnet with ROS 2 and Cyclone DDS or Fast DDS is very easy.
In case of any questions related to this article please contact us using Husarnet Community Forum or via email at support@husarnet.com.