Main Content

Switching Between ROS Middleware Implementations

ROS 2 is based on Data Distribution Service (DDS) standard, which is an end-to-end middleware that provides features such as discovery, serialization, and transportation. ROS 2 supports multiple ROS middleware (RMW) implementations because there are many factors you might consider while choosing a middleware implementation: platform availability, performance characteristics, computation footprint, dependencies, or license.

ROS Toolbox enables you to switch between various RMW implementations for using DDS, while working with ROS 2 in MATLAB® and Simulink®. The RMW implementations available in ROS Toolbox are,

  • rmw_fastrtps_cpp — eProsima Fast DDS (Version 2.1.1). This is the default RMW implementation.

  • rmw_fastrtps_dynamic_cpp — eProsima Fast DDS.

  • rmw_cyclonedds_cpp — Eclipse Cyclone DDS (Version 0.7.0).

Change RMW Implementation in MATLAB

To switch between different RMW implementations, set the RMW_IMPLEMENTATION environment variable to one of the available implementations using setenv. Set the RMW_IMPLEMENTATION environment variable before creating the ros2node object.


Use getenv to see the current value of the RMW_IMPLEMENTATION environment variable.

ans = 

Change RMW Implementation in Simulink

To switch between different RMW implementations while simulating a model in Simulink, modify the RMW Implementation parameter in the Configure ROS Network Addresses dialog box.

Follow the steps below to configure the RMW implementation:

  1. Create a Simulink model.

  2. In the Apps Tab, under Control Systems, select Robot Operating System (ROS).

  3. In the dialog box, select Robot Operating System 2 (ROS 2) as the ROS Network and click Finish.

  4. From the Simulation tab, in the Prepare section, under ROS Toolbox, select ROS Network.

  5. In the Configure ROS Network Addresses dialog box, specify an available RMW implementation.

The Configure ROS Network Addresses dialog box can also be accessed through ROS 2 Publish, Subscribe, and Call Service blocks. Open the block mask and click Configure ROS 2 Domain ID and ROS Middleware (RMW).

For local and remote code generation in Simulink, set the RMW_IMPLEMENTATION environment variable in MATLAB using setenv. Follow the steps in Change RMW Implementation in MATLAB.