rmw_cyclonedds

repository·rolling·Indexed 41 days ago

https://github.com/ros2/rmw_cyclonedds

The ROS 2 middleware implementation (RMW) for Eclipse Cyclone DDS, providing a high-performance, reliable, and lightweight communication layer. Includes documentation on installation for Eloquent and Dashing, configuration via the RMW_IMPLEMENTATION environment variable, Linux network buffer optimization, and debugging tools like ddsperf and CycloneDDS Insight. The rmw_cyclonedds_cpp package is Quality Level 2 and supports Tier 1 ROS platforms.

Tokens
1.8K
Snippets
6
Records
12
Agent score
52%

What's inside rmw_cyclonedds

  1. Understand the API and stability of rmw_cyclonedds_cpp

    rolling

    The rmw_cyclonedds_cpp package is classified as Quality Level 2.

    Public API

    The public API is declared through the rmw package. Documentation for the public API is generated using Doxygen and is hosted alongside the feature documentation in the official ROS 2 API docs.

    Stability Guarantees

    • API Stability: The package guarantees that it will not break the public API within a released ROS distribution (no major releases once a distribution is released).
    • ABI Stability: The package maintains ABI stability within a ROS distribution for both its C and C++ code.
  2. Use CycloneDDS Insight for graphical debugging

    rolling

    CycloneDDS Insight is a graphical tool used to:

    • Inspect participants, topics, publishers, and subscribers.
    • Diagnose discovery issues.
    • Verify communication architectures.
    • Monitor DDS traffic statistics (received bytes, sent bytes, and retransmitted bytes).
  3. Install and use rmw_cyclonedds_cpp

    rolling

    To use Eclipse Cyclone DDS as your ROS 2 middleware, install the appropriate package for your ROS 2 distribution and set the RMW_IMPLEMENTATION environment variable.

    1. Installation

    Install via apt depending on your ROS 2 version:

    • For Eloquent: apt install ros-eloquent-rmw-cyclonedds-cpp
    • For Dashing: apt install ros-dashing-rmw-cyclonedds-cpp

    2. Activation

    Set the environment variable in your terminal before running ROS 2 applications:

    export RMW_IMPLEMENTATION=rmw_cyclonedds_cpp

    3. Verification

    To confirm which RMW implementation is currently active, use the ROS 2 doctor tool:

    ros2 doctor --report
    export RMW_IMPLEMENTATION=rmw_cyclonedds_cpp
  4. Debug Cyclone DDS communication and discovery

    rolling

    If you encounter discovery issues or performance problems, use the following methods to diagnose the system:

    Circumvent Multicast Discovery

    If multicast is unavailable on your network, you can manually specify peers using the CYCLONEDDS_URI environment variable:

    export CYCLONEDDS_URI='<Discovery><Peers><Peer Address='myroshost.local' /><Peer Address='myroshost2.local' /></></>'

    Enable Verbose Tracing

    To generate richer debugging output, set the CYCLONEDDS_URI to enable trace verbosity.

    Output to stderr:

    export CYCLONEDDS_URI='<Tracing><Verbosity>trace</><Out>stderr</></>'

    Output to a log file in /var/log/:

    export CYCLONEDDS_URI='<Tracing><Verbosity>trace</><Out>/var/log/cyclonedds.${CYCLONEDDS_PID}.log</></>'

    Network Capture

    Use Wireshark to capture traffic for deep packet inspection:

    wireshark -k -w wireshark.pcap.gz
    export CYCLONEDDS_URI='<Discovery><Peers><Peer Address='myroshost.local' /><Peer Address='myroshost2.local' /></></>'
  5. Optimize Linux network buffers for large samples

    rolling

    When working with large samples (hundreds of kilobytes), you may experience excessive latency due to OS-level receive buffer exhaustion. On Linux, increase the net.core.rmem_max and net.core.rmem_default values.

    Temporary change (until reboot):

    sudo sysctl -w net.core.rmem_max=8388608 net.core.rmem_default=8388608

    Permanent change: Create a configuration file in /etc/sysctl.d/:

    echo "net.core.rmem_max=8388608\nnet.core.rmem_default=8388608\n" | sudo tee /etc/sysctl.d/60-cyclonedds.conf
    sudo sysctl -w net.core.rmem_max=8388608 net.core.rmem_default=8388608
  6. Verify DDS communication with ddsperf

    rolling

    The ddsperf tool (distributed with Cyclone DDS) allows you to verify that the DDS layer is functioning correctly independently of ROS 2.

    Run the following command on two different machines:

    ddsperf sanity

    Interpretation: If the reported "mean" value is greater than 100000us, there are likely underlying network issues.

    ddsperf sanity
  7. Use BaseCDRWriter methods for serialization

    rolling

    The BaseCDRWriter interface provides the following methods for managing serialization:

    • get_serialized_size(const void * data, SampleOrKey what): Returns the exact size required to serialize the data.
    • get_serialized_size_estimate(const void * data, SampleOrKey what): Returns an estimated size for serialization.
    • get_min_serialized_size(SampleOrKey what): Returns the minimum size, including a 4-byte encoding header.
    • get_max_serialized_size(SampleOrKey what): Returns the maximum size, including a 4-byte encoding header (returns SIZE_MAX if the type is unbounded).
    • serialize(void * dest, const void * data, SampleOrKey what): Performs the actual serialization of data into the dest buffer.
  8. Create a CDR reader with make_cdr_reader

    rolling

    Use make_cdr_reader to instantiate a BaseCDRReader for a specific type. This reader allows you to deserialize CDR-encoded data back into a destination structure, extract keys, or print the contents of the CDR buffer for debugging.

    // Example usage pattern
    std::unique_ptr<BaseCDRReader> reader = make_cdr_reader(value_type, SampleOrRequest::Sample);
    
    reader->deserialize(dest, cdr_buffer, cdr_size, SampleOrKey::Sample);
  9. Create a CDR writer with make_cdr_writer

    rolling

    Use make_cdr_writer to instantiate a BaseCDRWriter for a specific type. This writer provides methods to calculate the required buffer size and perform the actual serialization of data into Common Data Representation (CDR) format.

    Supported variants for the variant parameter include:

    • SampleOrRequest::Sample
    • SampleOrRequest::Request
    // Example usage pattern
    std::unique_ptr<BaseCDRWriter> writer = make_cdr_writer(value_type, SampleOrRequest::Sample);
    
    size_t size = writer->get_serialized_size(data, SampleOrKey::Sample);
    // ... allocate buffer ...
    writer->serialize(buffer, data, SampleOrKey::Sample);
  10. Use BaseCDRReader methods for deserialization

    rolling

    The BaseCDRReader interface provides the following methods for handling CDR data:

    • deserialize(void * dest, const void * cdr, size_t cdrsize, SampleOrKey what): Deserializes the CDR buffer into the dest pointer.
    • extractkey(std::vector<byte> & dest, const void * cdr, size_t cdrsize, SampleOrKey what): Extracts the key from the CDR buffer into a byte vector.
    • extractkey_be(std::vector<byte> & dst, const void * cdr, size_t cdrsize, SampleOrKey what): Extracts the key from the CDR buffer using Big Endian format.
    • print(char * dst, size_t dstsize, const void * cdr, size_t cdrsize, SampleOrKey what): Formats the CDR content as a string into dst for debugging purposes.