ROS 2 in Simulink
Access ROS 2 networks and messages using Simulink®
ROS Toolbox enables you to connect to ROS and ROS 2 in Simulink and send messages over the network. See Get Started with ROS 2 in Simulink®.
You can also generate and deploy code to a target system. For an advanced example on creating a standalone ROS 2 node, see Generate a Standalone ROS 2 Node from Simulink.
To run, stop, or check the status of deployed ROS 2 nodes available on a ROS 2
device, use the MATLAB® functions listed. Create a connection to a ROS device using ros2device
.
Functions
Blocks
Blank Message | Create blank ROS 2 message using specified message type |
Call Service | Call service in ROS 2 network |
Current Time | Retrieve current ROS 2 time or system time |
Get Parameter | Get ROS 2 parameter value |
Publish | Send messages to ROS 2 network |
Read Data | Play back data from ROS 2 log file |
Read Image | Extract image from ROS 2 Image message |
Read Scan | Extract scan data from ROS or ROS 2 laser scan message |
Read Point Cloud | Extract point cloud from ROS 2 PointCloud2 message |
Subscribe | Receive messages from ROS 2 network |
Write Image | Write image data to a ROS or ROS 2 message |
Write Point Cloud | Write point cloud data to a ROS or ROS 2 message |
Topics
ROS 2 Network
- Get Started with ROS 2 in Simulink®
This example shows how to use Simulink blocks for ROS 2 to send and receive messages from a local ROS 2 network. - Publish and Subscribe to ROS 2 Messages in Simulink
This model shows how to publish and subscribe to a ROS 2 topic using Simulink®. - Connect to a ROS-Enabled Robot from Simulink® over ROS 2
This example shows you how to configure a Simulink model to send and receive information from a separate ROS-based simulator such as Gazebo® over ROS 2.
ROS 2 Messages
- Work with ROS 2 Messages in Simulink
This example illustrates how to work with complex ROS 2 messages in Simulink®, such as messages with nested sub-messages and variable-length arrays. - Manage Array Sizes for ROS Messages in Simulink
Description of dialog box for managing array sizes in Simulink ROS
ROS 2 Applications
- Generate a Standalone ROS 2 Node from Simulink
This example shows you how to generate and build a standalone ROS 2 node from a Simulink® model. - Feedback Control of a ROS-Enabled Robot Over ROS 2
This example shows you how to use Simulink® to control a simulated robot running in a Gazebo® robot simulator over ROS 2 network. - Sign Following Robot with ROS 2 in Simulink
Use Simulink® to control a simulated robot running on a separate ROS-based simulator over ROS 2 network. - Automated Parking Valet with ROS 2 in Simulink
This example shows how to distribute the Automated Parking Valet application among various nodes in a ROS 2 network in Simulink® and deploy them as standalone ROS 2 nodes. - Generate Code to Manually Deploy a ROS 2 Node from Simulink
This example shows you how to generate C++ code from a Simulink® model to deploy as a standalone ROS 2 node.
Model Execution
- Enable ROS 2 Time Model Stepping for Deployed Nodes
You can enable a deployed ROS 2 node to execute based on the time published on the/clock
topic on a ROS 2 network.