Generate custom messages from ROS definitions



rosgenmsg(folderpath) generates ROS custom messages in MATLAB® by reading ROS custom message and service definitions in the specified folder path. The function expects ROS package folders inside the folder path. These packages contain the message definitions in .msg files and the service definitions in .srv files.

After calling this function, you can send and receive your custom messages in MATLAB like all other supported messages. You can create these messages using rosmessage or view the list of messages by calling rosmsg list.


When generating custom messages for ROS, you must build the ROS packages. This requires you to have CMake and a C++ compiler for your platform. For more information, see ROS System Requirements

rosgenmsg(folderpath,Name,Value) specifies additional options using one or more name-value pair arguments.


collapse all

After you install the support package and prepare your custom message package folder, specify the path to the parent folder and call rosgenmsg.


You must set the folderpath based on your ROS package setup.

folderpath = "C:/Users/user1/Documents/robot_custom_msg/";

Input Arguments

collapse all

Path to the parent folder of ROS message packages, specified as a string scalar or character vector. The parent folder should contain package folders. These folders contain message definitions in .msg files and the service definitions in .srv files.

Example: "/opt/ros/melodic/share"

Data Types: char | string

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: 'BuildConfiguration','fasterruns'

Build configuration, specified as the comma-separated pair consisting of 'BuildConfiguration' and a character vector or string scalar containing 'fasterbuilds' or 'fasterruns'.

  • 'fasterbuilds' — Build the message libraries with compiler optimizations for shorter build times.

  • 'fasterruns' — Build the message libraries with compiler optimizations for faster execution.

Example: rosgenmsg("/opt/ros/melodic/share",'BuildConfiguration','fasterruns')

Data Types: char | string

Introduced in R2019b