ros2genmsg
Generate custom messages from ROS 2 definitions
Description
ros2genmsg(
generates ROS 2
custom messages in MATLAB® by reading ROS 2 custom messages and service definitions in the specified
folder path. The function expects one or more ROS 2 package folders inside the folder
path. These packages contain the message definitions in folderpath
).msg
files and
the service definitions in .srv
files.
After calling this function, you can send and receive your custom messages in
MATLAB like all other supported messages. You can create these messages using
ros2message
or
view the list of messages by calling ros2 msg list
.
Note
When generating custom messages for ROS 2, you must build the ROS 2 packages. This requires you to have CMake and a C++ compiler for your platform. For more information, see ROS System Requirements
The custom messages from the ROS 2 definitions have to be regenerated for every new release.
The Custom messages generated by MATLAB now supports both eProsima Fast DDS and Eclipse Cyclone DDS middleware. For more information on ROS middleware implementations see Switching Between ROS Middleware Implementations.
ros2genmsg(
specifies additional options using one or more name-value pair arguments.folderpath
,Name,Value
)
Examples
Input Arguments
Limitations
Restart Nodes
After generating custom messages, restart any existing ROS 2 nodes.
Code Generation with custom messages:
Custom message and service types can be used with ROS 2 functionality for generating C++ code for a standalone ROS 2 node. The generated code (.tgz archive) will include definitions for the custom messages, but it will not include the ROS 2 custom message packages. When the generated code is built in the destination, it expects the custom message packages to be available in the colcon workspace which should be your current working directory. Please ensure that you either install or copy the custom message package to your system before building the generated code.
MATLAB Compiler
ROS 2 custom messages and the
ros2genmsg
function are not supported with MATLAB Compiler™.