Add Custom ROS Message Definitions to MATLAB
A set of standard messages are included in the default ROS message catalog of ROS
toolbox. However, you can create your own ROS custom messages and use them in
MATLAB® and Simulink® with ROS networks to transmit information. For this,
rosgenmsg
function is used. For more information on this,
refer to ROS Custom
Message Support and rosgenmsg.
The ur_dashboard_msgs
ROS package from Universal Robots contains
several custom ROS messages and services. In order to control UR Series robots using
ROS, these message definitions need to be added to the MATLAB ROS message catalog. One option to do this is to use rosgenmsg.
As mentioned in the ROS System Requirements,
generating custom messages for ROS, you must build the ROS packages. This requires you
to have Python®, CMake, and a C++ compiler for your platform.
To make the process of adding custom ROS message definitions to MATLAB easy, the definitions for UR Series Robots are included in the support
package and the hardware setup process consists of a step to register these
pre-generated message definitions with MATLAB. This workflow is ideal for the use-cases where the custom messages and
services from ur_dashboard_msgs
package are not modified.
The custom ROS message definitions have to be regenerated in anyone of these cases:
If the ROS messages from Universal Robots are modified and are used to communicate with and control the robot
A new ROS package is being created, which is dependent on the ROS packages supplied by Universal Robots, to communicate with and control the robot.
A new message definition for Windows® needs to be added to the existing set of definitions supplied with the support package.
Generate Custom ROS Message Definitions
To generate Custom ROS message definitions:
Navigate to the custom messages folder by executing the following command in the MATLAB command window.
fullfile(codertarget.urseries.internal.getSpPkgRootDir,'resources','ROSMsgs')
Based on the operating system platform, there should be a folder with a name starting with
custommsg
in the resources folder. Removecustommsg
folder from the MATLAB path and save the current path by executingsavepath
command in the MATLAB command window.Restart MATLAB.
Verify that output of the MATLAB command
rosmsg list
does not contain any ROS messages from theur_dashboard_msgs
group.Refer the ROS Custom Message Support to know more about the requirement to generate custom ROS message definitions using rosgenmsg. Also refer to ROS System Requirements to know more about the prerequisite additional software.
As mentioned in the ROS Custom Message Support,
rosgenmsg
expects custom message files (.msg files) present under the foldermsg
and custom service files (.srv files) under the foldersrv
. Hence before proceeding further, ensure themsg
andsrv
folder does not have any subfolder.Generating custom ROS message definitions using
rosgenmsg
on Windows OS has limitation on maximum number of custom messages. Hence, limit the number of custom messages and services to a minimum required. If you want to just add few ROS messages to the set of custom message / service definitions, then ensure that you first copy .msg and .srv files for the default message set and then additional files for the ROS messages which you want to add.Navigate to the folder which contains the custom ROS package and execute
rosgenmsg
in MATLAB command window.Wait for the process to complete, and once it is completed, execute the commands to modify MATLAB path, clear classes and rehash toolboxcache.
Check the output of MATLAB command
rosmsg list
for the messages from the groupur_dashboard_msgs
or the name of your custom ROS package.