Custom Message Creation Workflow
Once you have your custom message structure set up as described in the previous
section, you can create the code needed to use these custom messages. First, you call
rosgenmsg with your known path to the custom
message files to create MATLAB code.
The rosgenmsg function takes your custom message files
(.msg and .srv) and converts each message type
to working MATLAB code. The rosgenmsg function looks for
.msg files in the msg folder and for
.srv files in the srv folder. This code is a
group of classes that define the message properties when you create new custom messages.
The function then creates the required MATLAB M-files for the different message classes.
After the rosgenmsg function creates these files, you
must add the class files to the MATLAB path. These steps are given as prompts in the MATLAB Command Window.
Add location of class files to MATLAB path: Use addpath to add new locations of
files with the .m extension to the MATLAB path and use savepath to save these
changes.
Refresh all message class definitions, which requires
clearing the
workspace:
clear classes
rehash toolboxcache
Verify messages are available: Use
rosmessage function to check that
the new custom messages are available.
For an example of this procedure, see Create Custom Messages from ROS Package. This
example uses sample custom message files to create custom messages in MATLAB.
You need to complete this procedure only once for a specific set of custom messages.
After that, you can use the new custom messages like any other ROS message in
MATLAB and take advantage of the full ROS functionality that ROS Toolbox provides. Repeat this generation procedure when you would like to update
or create new message types.
You must maintain the MATLAB path that contain the files directories. Make sure that the MATLAB path has only one folder at a time that contains custom message
artifacts.Code Generation with Custom messages
Custom message and service types can be used with ROS Simulink blocks for generating C++ code for a standalone ROS node. The
generated code (.tgz archive) will include Simulink definitions for the custom messages, but it will not include the ROS
custom message packages. When the generated code is built in the destination Linux
System, it expects the custom message packages to be available in the catkin
workspace or on the ROS_PACKAGE_PATH. Ensure that you either
install or copy the custom message package to your Linux system before building the
generated code.