Main Content

Configure MATLAB Coder for ROS Node Generation

To generate C++ code for ROS Nodes from MATLAB functions, you must configure a MATLAB® Coder™ configuration object. This topic shows you how to configure the properties of the object to customize ROS Node generation.

To create a MATLAB Coder configuration object, use the coder.config (MATLAB Coder) object. For example, this code creates a MATLAB Coder configuration object for generating an executable.

cfg = coder.config("exe");

Specify the Hardware property of the object as a "Robot Operating System (ROS)" hardware configuration object, using the coder.hardware (MATLAB Coder) function.

cfg.Hardware = coder.hardware("Robot Operating System (ROS)");

Then, you can specify these coder.Hardware properties specific to ROS node generation. For remote device deployment, the device parameters automatically save to MATLAB preferences, and are used the next time you set the deployment site to "Remote Device".

PropertyValuesDescription
coder.Hardware.DeployTo

"Remote Device" (default)

"Localhost"

Deployment site for the code, which can be a remote device or the local host device.
coder.Hardware.BuildAction

"None" (default)

"Build and Load"

"Build and Run"

Build action for code generation.
coder.Hardware.RemoteDeviceAddress

"192.168.128.130" (default)

string

Remote IP address or host name of the remote device.
coder.Hardware.RemoteDeviceUsername

" " (default)

string

User name for the remote device.
coder.Hardware.RemoteDevicePassword

" " (default)

string

Password for the remote device.
coder.Hardware.CatkinWorkspace

"~/catkin_ws" (default)

string

Path to the Catkin workspace in the remote device. For Windows devices, the default value replaces "~" with the user path.
coder.Hardware.ROSFolder

"/opt/ros/melodic" (default)

string

Path to the ROS installation folder. Leave it blank to use the MATLAB ROS distribution.
coder.Hardware.PackageMaintainerName

"ROS User" (default)

string

ROS package maintainer name, which is used for package.xml generation.
coder.Hardware.PackageMaintainerEmail

"rosuser@test.com" (default)

string

ROS package maintainer e-mail ID, used for package.xml generation.
coder.Hardware.PackageLicense

"BSD" (default)

string

ROS license information, used for package.xml generation.
coder.Hardware.PackageVersion

"1.0.0" (default)

string

Version number of the ROS package.

For example, the following code specifies that the generated code must be deployed to the remote device and run after build. It also specifies the remote device parameters.

cfg.Hardware.DeployTo = "Remote Device";
cfg.Hardware.BuildAction = "Build and run";
cfg.Hardware.RemoteDeviceAddress = '192.168.243.144';
cfg.Hardware.RemoteDeviceUsername = 'user';
cfg.Hardware.RemoteDevicePassword = 'password';

To specify additional hardware-specific configuration parameters use coder.HardwareImplementation (MATLAB Coder) object. For example, this code specifies the manufacturer and type of the hardware as well as long long data type support for int64 and uint64 values.

cfg.HardwareImplementation.ProdHWDeviceType = "Intel->x86-64 (Linux 64)";
cfg.HardwareImplementation.ProdLongLongMode = "true";

For more information on ROS Node generation, see MATLAB Programming for Code Generation.

Related Topics