In this example, you create ROS 2 custom messages in MATLAB® to share them on another machine. This other machine must run on the same platform and same version of MATLAB®. You must have a ROS 2 package that contains the required msg
file, as this figure shows.
Open a new MATLAB session and create a custom message package folder in a local folder. Specify a short folder path when you generate custom messages on a Windows machine to avoid limitations on the number of characters in the folder path. For example,
genDir = fullfile('C:/Work/ros2CustomMessages')
.
Create a folder named msg
inside the custom message package folder.
Create a file named .msg
inside the msg
folder.
Create a folder named srv
inside the custom message package folder.
Create a file named .srv
inside the srv
folder.
Create a folder named action
inside the custom message package folder.
Create a file named .action
inside the action
folder.
Generate the custom messages from the ROS 2 definitions in .msg
, .srv
and .action
files as a shareable ZIP archive.
Identifying message files in folder 'C:/Work/ros2CustomMessages'.Done.
Validating message files in folder 'C:/Work/ros2CustomMessages'.Done.
[1/1] Generating MATLAB interfaces for custom message packages... Done.
Running colcon build in folder 'C:/Work/ros2CustomMessages/matlab_msg_gen/win64'.
Build in progress. This may take several minutes...
Build succeeded.build log
Generating zip file in the folder 'C:/Work/ros2CustomMessages'.Done.
Copy the generated custom messages in the ZIP archive to the target computer and register it using the ros2RegisterMessages
function.
Run ros2 msg list
on the target computer to view the custom messages for using in the workflow.