ros2genmsg
Generate custom messages from ROS 2 definitions
Description
ros2genmsg( generates ROS 2
custom messages by reading ROS 2 custom message, service, action, and ROS 2 IDL
definitions in the specified folder path. ROS 2 supports a subset of the OMG IDL 4.2 Specification. The
function folder must contain one or more ROS 2 packages. These packages contain the
message definitions in folderpath).msg files, service definitions in
.srv files, and action definitions in .action
files. You can also generate custom message, service, and action definitions directly from
.idl files, which you must place under respective
/msg, /srv, and /action
folders.
For details on mapping between ROS interface types and IDL types, see Mapping between ROS interface types and DDS IDL types.
After you generate custom messages, you can send and receive them in MATLAB® like all 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
You can use custom message and service types with ROS 2 functionality for generating C++ code for a standalone ROS 2 node. The generated code (TGZ archive) includes the custom message definitions and the ROS 2 custom message packages. When you build the generated code in the destination Linux® system, the custom message packages are automatically available in the
colconworkspace. 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 does not support ROS custom messages and the
ros2genmsgfunction.
Build Path Length Limitation
On Windows®, long build paths may cause custom message generation to fail. Move the custom message folder to a location with a shorter path or use the
BuildRootname-value argument to specify an alternate build path.When the custom message folder is in a directory without write access, message generation fails. Relocate the folder to a writable directory or specify a different build path using the
BuildRootargument.
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 260 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.



