Main Content

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 access the POLYSCOPE GUI using dashboard server and 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 Universal Robots are included in the support package and the hardware setup process consists of a step to register these pre-generated message definitions with the 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:

  1. Navigate to the custom messages folder by executing the following command in the MATLAB command window.

    fullfile(codertarget.robotmanipulator.internal.getSpPkgRootDir,'resources','ROSMsgs') 
  2. Based on the operating system platform, there should be a folder with a name starting with custommsg in the resources folder. Remove custommsg folder from the MATLAB path and save the current path by executing savepath command in the MATLAB command window.

  3. Restart MATLAB.

  4. Verify that output of the MATLAB command rosmsg list does not contain any ROS messages from the ur_dashboard_msgs group.

  5. 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.

  6. Navigate to the folder which contains the custom ROS package and execute rosgenmsg in MATLAB command window.

  7. Wait for the process to complete, and once it is completed, execute the commands to modify MATLAB path, clear classes and rehash toolboxcache.

  8. Check the output of MATLAB command rosmsg list for the messages from the group ur_dashboard_msgs or the name of your custom ROS package.