Contenido principal

ROS 2 Network Access in Simulink

R2026b
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 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.

Note

ROS 2 blocks are not supported for usage within subsystem references. This is because ROS Toolbox uses a data dictionary to store model information but subsystem reference does not support portability of data dictionary attached to it. For more information on using subsystem references, see Considerations When Using a Library Dictionary (Simulink).

ROS 2 blocks are not supported for software-in-the-loop (SIL) and processor-in-the-loop (PIL) simulations.

Functions

expand all

ros2deviceConnect to remote ROS 2 device
runNodeStart ROS or ROS 2 node
stopNodeStop ROS or ROS 2 node
isNodeRunningDetermine if ROS or ROS 2 node is running

Blocks

expand all

Publish ROS 2 blockPublishSend messages to ROS 2 network
Subscribe ROS 2 blockSubscribeReceive messages from ROS 2 network by polling at each time step or processing immediately on arrival
Read Data ROS 2Read DataPlay back data from ROS 2 log file
Call Service Block ROS 2Call ServiceCall service in ROS 2 network
Receive Service Request block icon.Receive Service RequestReceive service request from ROS 2 network (Since R2024a)
Send Service Response block icon.Send Service ResponseSend service response to ROS 2 service client (Since R2024a)
ROS 2 Send Action Goal icon.Send Action GoalSend action goal messages to ROS 2 network (Since R2024a)
ROS 2 Cancel Action Goal block iconCancel Action GoalCancel active action goal in ROS 2 network (Since R2024a)
ROS 2 Monitor Action Goal block iconMonitor Action GoalMonitor action goal in ROS 2 network (Since R2024a)
ROS 2 Get Transform IconGet TransformGet transformation between source and target frame from ROS 2 network (Since R2023b)
ROS Apply Transform BlockApply TransformTransform input ROS or ROS 2 message to target frame (Since R2023b)
Blank Message ROS 2 blockBlank MessageCreate blank ROS 2 message using specified message type
Header Assignment ROS 2 block icon.Header AssignmentUpdate fields of ROS 2 message header (Since R2023a)
Read Image ROS 2Read ImageExtract image from ROS 2 Image message
ROS Read Scan BlockRead ScanExtract scan data from ROS or ROS 2 laser scan message (Since R2022a)
Read Point Cloud ROS 2Read Point CloudExtract point cloud from ROS 2 PointCloud2 message
ROS Write Image BlockWrite ImageWrite image data to a ROS or ROS 2 message (Since R2022a)
ROS Write Point Cloud BlockROS Write Point Cloud, ROS 2 Write Point CloudWrite point cloud data to a ROS or ROS 2 message (Since R2022a)
ROS 2 Get Parameter BlockGet ParameterGet ROS 2 parameter value (Since R2022b)
ROS 2 Current TimeCurrent TimeRetrieve current ROS 2 time or system time (Since R2022b)
ROS 2 CAN Transmit Block MaskCAN TransmitTransmit messages to controller area network (CAN) bus from ROS 2 network (Since R2026a)
ROS 2 CAN Receive Block MaskCAN ReceiveReceive messages from controller area network (CAN) bus (Since R2026a)

Topics

ROS 2 Network

ROS 2 Messages

ROS 2 Applications

Model Execution