Main Content

Configure MATLAB Coder for ROS 2 Node Generation

To generate C++ code for ROS 2 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 2 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 2 (ROS 2)" hardware configuration object using the coder.hardware (MATLAB Coder) function.

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

You can then specify these coder.Hardware properties, specific to ROS 2 node generation. For remote device deployment, the device parameters automatically save to your 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 scalar

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

" " (default)

string scalar

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

" " (default)

string scalar

Password for the remote device.
coder.Hardware.ROS2Workspace

"~/ros2_ws" (default)

string scalar

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

"/opt/ros/dashing" (default)

string scalar

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

"ROS User" (default)

string scalar

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

"rosuser@test.com" (default)

string scalar

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

"BSD" (default)

string scalar

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

"1.0.0" (default)

string scalar

Version number of the ROS package.

For example, this code specifies that, once built, the generated code deploys to the remote device and runs. 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 the 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";

See Also

| | |