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. ROS Toolbox only supports the executable build type for
the MATLAB Coder configuration object.
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'
.
Property | Values | Description |
---|---|---|
coder.Hardware.DeployTo |
| Deployment site for the code, which can be a remote device or the local host device. |
coder.Hardware.BuildAction |
| Build action for code generation. |
coder.Hardware.RemoteDeviceAddress |
character vector | Remote IP address or host name of the remote device. |
coder.Hardware.RemoteDeviceUsername |
character vector | User name for the remote device. |
coder.Hardware.RemoteDevicePassword |
character vector | Password for the remote device. |
coder.Hardware.CatkinWorkspace |
character vector | Path to the Catkin workspace in the remote device. For Windows
devices, the default value replaces '~' with the user
path. |
coder.Hardware.ROSFolder |
character vector | Path to the ROS installation folder. Leave it blank to use the MATLAB ROS distribution. |
coder.Hardware.PackageMaintainerName |
character vector | ROS package maintainer name, which is used for
package.xml generation. |
coder.Hardware.PackageMaintainerEmail |
character vector | ROS package maintainer e-mail ID, used for
package.xml generation. |
coder.Hardware.PackageLicense |
character vector | ROS license information, used for package.xml
generation. |
coder.Hardware.PackageVersion |
character vector | 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;
To specify external ROS packages as dependencies for the generated ROS node, specify appropriate custom toolchain options in the coder configuration object.
cfg.BuildConfiguration = 'Specify'; cfg.CustomToolchainOptions{4} = '"ROS_PKG1","ROS_PKG2"'; % Add ROS Required Packages cfg.CustomToolchainOptions{6} = '/usr/include/opencv'; % Add Include Directories cfg.CustomToolchainOptions{8} = '"-lopencv_core","-lopencv_shape"'; % Add Link Libraries cfg.CustomToolchainOptions{10} = '/usr/lib/opencv'; % Add Library Paths cfg.CustomToolchainOptions{12} = '-DMYVAR=1'; % Add Defines
For more information on ROS Node generation, see MATLAB Programming for Code Generation.