Main Content

ros2device

Connect to remote ROS 2 device

Description

The ros2device object creates a connection with a ROS 2 device. The object contains the necessary login information and other parameters of the ROS 2 distribution. Once you have made a connection using ros2device, you can run and stop ROS 2 nodes.

You can deploy ROS 2 nodes to a ROS 2 device using Simulink® models. For an example, see Generate a Standalone ROS 2 Node from Simulink®.

Note

To connect to a ROS 2 device, an SSH server must be installed on the device.

Creation

Description

example

device = ros2device(deviceAddress,username,password) creates a ros2device object connected to the ROS 2 device at the specified address and with the specified user name and password.

device = ros2device creates a ros2device object connected to a ROS 2 device using the saved values for deviceAddress, username, and password.

Properties

expand all

This property is read-only.

Host name or IP address of ROS 2 device, specified as a character vector.

Example: '192.168.1.10'

Example: 'samplehost.foo.com'

This property is read-only.

User name used to connect to ROS 2 device, specified as a character vector.

Example: 'user'

Location of the ROS 2 installation, specified as a character vector. If you do not specify a folder, MATLAB® tries to determine the correct folder for you. When you deploy a ROS 2 node, set this value from Simulink in the Configuration Parameters dialog box, under Hardware Implementation.

Example: '/opt/ros/dashing'

ROS 2 project folder where models are deployed on device, specified as a character vector. When you deploy a ROS 2 node, set this value from Simulink in the Configuration Parameters dialog box, under Hardware Implementation.

Example: '~/ros2_ws_test'

This property is read-only.

Nodes available to run on a ROS 2 device, returned as a cell array of character vectors. Nodes are only listed if they are part of the ROS2Workspace and have been deployed to the device using Simulink.

Example: {'robotcontroller','publishernode'}

Object Functions

runNodeStart ROS or ROS 2 node
stopNodeStop ROS or ROS 2 node
isNodeRunningDetermine if ROS or ROS 2 node is running
systemExecute system command on device
putFileCopy file to device
getFileGet file from device
deleteFileDelete file from device
dirList folder contents on device
openShellOpen interactive command shell to device

Examples

collapse all

Connect to a remote device and start a ROS 2 node using a ros2device object. Create a ros2device object by specifying the address, user name, and password of the remote device.

ipaddress = '192.168.203.131';
device = ros2device(ipaddress,'user','password');
device.ROS2Folder = '/opt/ros/dashing';
device.ROS2Workspace = '~/ros2_ws_test';

The ros2device object also contains information about the available ROS nodes. Check the available ROS 2 nodes on the connected device.

device.AvailableNodes

Use the runNode object function to run a ROS 2 node on the remote device, and then check that if the node is running.

runNode(device,'ros2FeedbackControlExample')
isNodeRunning(device,'ros2FeedbackControlExample')

Stop the ROS 2 node.

stopNode(device,'ros2FeedbackControlExample')
Introduced in R2021a