ros2genmsg
Generate custom messages from ROS 2 definitions
Description
ros2genmsg(
generates ROS 2
custom messages by reading ROS 2 custom messages and service definitions in the specified
folder path. The function folder must contain one or more ROS 2 package. These packages
contain the message definitions in folderpath
).msg
files, service definitions in
.srv
files, and action definitions in .action
files.
After you generate the custom messages, you can send and receive them in MATLAB® like all the other supported messages. You can create these messages using
ros2message
or
view the list of messages by entering ros2 msg list
at the MATLAB
Command Window.
Note
To generate custom messages for ROS 2, you must build the ROS 2 packages. This process requires you to have a C++ compiler for your platform. For more information, see ROS Toolbox System Requirements.
With every new release of MATLAB, you must regenerate the custom messages from the ROS 2 definitions.
Custom messages that you generate in MATLAB now support 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 arguments.folderpath
,Name=Value
)
Examples
Input Arguments
Name-Value Arguments
Limitations
Restart Nodes
After you generate 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 TGZ archive includes definitions for the custom messages, but not the ROS 2 custom message packages. When the function builds the generated code in the destination, the custom message packages must be available in the colcon workspace. Set this workspace as your current working directory. Install or copy the custom message package to your system before building the generated code.
MATLAB Compiler
MATLAB Compiler™ software do not support ROS custom messages and the
ros2genmsg
function.
Tips
During the Microsoft® Visual Studio® installation, ensure that you select Desktop development with C++ workload. This installs the MSVC compiler and all necessary dependencies required to generate custom messages.
Ensure that the path to the custom message folder does not exceed 64 characters.
Verify that the python environment configuration is correct. For more information, see ROS Toolbox System Requirements.
The custom message libraries generated for ROS 2 are user-created files that integrate into the internal ROS workflow. To safeguard these files from unauthorized access and maintain system integrity, set appropriate directory permissions to restrict access to only intended user accounts.