Main Content

Troubleshoot ROS 2 Cross-Subnet Discovery Issues Using DDS Profiles

R2026b

This topic shows how to configure Data Distribution Service (DDS) discovery profiles so that MATLAB can connect with ROS 2 nodes running on a different subnet. You create an XML profile that lists the IP addresses of remote peers and apply it using environment variables on both systems. The instructions cover the two middleware implementations supported by ROS Toolbox, which are eProsima Fast DDS (DEFAULT_FASTRTPS_PROFILE.xml) and Eclipse Cyclone DDS (CYCLONEDDS.xml), including the XML structure, peer address entries, and environment variable setup in both MATLAB® and the remote system.

Problem

ROS 2 uses DDS middleware for node discovery and message transport. By default, DDS discovery uses multicast, which operates only within the local subnet. When MATLAB and an external ROS 2 system are on different subnets, for example, when communicating across physical network segments, VPN boundaries, or cloud instances, nodes cannot discover each other and no messages are exchanged.

To enable cross-subnet communication, you must create a custom DDS XML profile that explicitly lists the IP addresses of remote peers. The specific XML format depends on the DDS middleware implementation in use.

Note

For bidirectional communication, both systems must specify the other system's IP address in their respective XML configuration files.

Possible Solutions

Configure Fast DDS for Cross-Subnet Discovery

  1. Collect the IP addresses of all systems outside your local subnet with which you need to communicate.

  2. Create a DEFAULT_FASTRTPS_PROFILE.xml file using the following XML template.

    Remove existing <locator> entries and add the list of IP addresses of systems outside the subnet in the <address> elements, with which you want to establish communication.

    <?xml version="1.0" encoding="UTF-8" ?>
    <profiles>
        <participant profile_name="participant_win" is_default_profile="true">
            <rtps>
                <builtin>
                    <metatrafficUnicastLocatorList>
                         <locator/>
                    </metatrafficUnicastLocatorList>
                     <initialPeersList>
                         <locator>
                             <udpv4>
                             <address>192.34.17.36</address>
                             </udpv4>
                         </locator>
                         <locator>
                             <udpv4>
                             <address>182.30.45.12</address>
                             </udpv4>
                         </locator>
                         <locator>
                             <udpv4>
                             <address>194.158.78.29</address>
                             </udpv4>
                         </locator>
                     </initialPeersList>
                 </builtin>
             </rtps>
         </participant>
    </profiles> 
  3. Place the XML file in the MATLAB current working folder. On remote systems running ROS 2 outside MATLAB, place the file in the folder from which the ROS 2 application is started.

  4. Set the environment variable on both systems.

    In the system running MATLAB, run the following command in the command window.

    setenv("DEFAULT_FASTRTPS_PROFILE","<path-to-DEFAULT_FASTRTPS_PROFILE.xml>")
    

    In the remote target that will run the ROS 2 nodes, run either of the following commands, based on the operating system.

    # For Unix, and Mac
    export DEFAULT_FASTRTPS_PROFILE="<path-to-DEFAULT_FASTRTPS_PROFILE.xml>"
    # For Windows
    set DEFAULT_FASTRTPS_PROFILE="<path-to-DEFAULT_FASTRTPS_PROFILE.xml>"
  5. Verify communication by repeating the publisher-subscriber diagnostic test described in the Clean Communication Environment and Verify Two-Way Communication section.

Configure Cyclone DDS for Cross-Subnet Discovery

  1. Collect the IP addresses of all systems outside your local subnet with which you need to communicate.

  2. Create a CYCLONEDDS.xml file to configure this specific DDS implementation in MATLAB using the following XML template.

    Remove existing <Peer> entries and add the list of IP addresses of systems outside the subnet in the <address> elements, with which you want to establish communication.

    <?xml version="1.0" encoding="UTF-8" ?>
    <CycloneDDS xmlns="https://www.eclipse.org/cyclonedds" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://www.eclipse.org/cyclonedds https://www.eclipse.org/cyclonedds/schema/CycloneDDS.xsd">
        <Domain>
            <Discovery>
                <Peers>
                    <Peer address="192.168.1.100"/>
                    <Peer address="192.168.1.101:7401"/> <!-- Specify port if needed -->
                    <Peer address="hostname_of_peer"/>
                </Peers>
            </Discovery>
        </Domain>
    </CycloneDDS>
  3. Ensure both systems specify each other's address in their respective CYCLONEDDS.xml files for bidirectional communication.

  4. Set the environment variable on both systems.

    In the system running MATLAB, run the following command in the command window.

    The CYCLONEDDS_URI environment variable must point to the full file path of the CYCLONEDDS.xml file created in step 2.

    setenv('CYCLONEDDS_URI', '<path-to-CYCLONEDDS.xml>');
    

    In the remote target that will run the ROS 2 nodes, run either of the following commands, based on the operating system.

    # For Unix, and Mac
    export CYCLONEDDS_URI="<path-to-CYCLONEDDS.xml>"
    
    # For Windows
    set CYCLONEDDS_URI="<path-to-CYCLONEDDS.xml>"
    
  5. Verify communication by repeating the publisher-subscriber diagnostic test described in the Clean Communication Environment and Verify Two-Way Communication section.

If communication still fails after configuring DDS profiles, the Windows firewall may be blocking ROS 2 multicast traffic. For more information, see Troubleshoot ROS 2 Firewall, QoS, and Network Compatibility Issues.

See Also

Topics