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
custommsgin the resources folder. Removecustommsgfolder from the MATLAB path and save the current path by executingsavepathcommand in the MATLAB command window.Restart MATLAB.
Verify that output of the MATLAB command
rosmsg listdoes not contain any ROS messages from theur_dashboard_msgsgroup.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,
rosgenmsgexpects custom message files (.msg files) present under the foldermsgand custom service files (.srv files) under the foldersrv. Hence before proceeding further, ensure themsgandsrvfolder does not have any subfolder.Generating custom ROS message definitions using
rosgenmsgon 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
rosgenmsgin 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 listfor the messages from the groupur_dashboard_msgsor the name of your custom ROS package.