Main Content

ros2

Retrieve information about ROS 2 network

Description

example

ros2 msg list returns a list of all available ROS 2 message types that can be used in MATLAB.

example

ros2 msg show msgType provides the definition of the ROS 2 message, msgType.

example

ros2 node list lists nodes on the ROS 2 network.

example

ros2 topic list lists topic names with registered publishers or subscribers on the ROS 2 network.

ros2 bag info folderpath displays the information about the contents of the ros2bag at folderpath in the MATLAB® Command Window. The information include the contents of the bag2info structure.

Note

If the ROS 2 bag log file contains custom messages, generate MATLAB interfaces to ROS 2 custom messages using ros2genmsg function before using this command.

example

msgList = ros2("msg","list") returns a list of all available ROS 2 message types that can be used in MATLAB.

example

msgInfo = ros2("msg","show",msgType) provides the definition of the ROS 2 message, msgType.

example

nodeList = ros2("node","list") lists nodes on the ROS 2 network.

example

topicList = ros2("topic","list") lists topic names with registered publishers or subscribers on the ROS 2 network.

nodeList = ros2("node","list","DomainID",ID) lists nodes on the ROS 2 network for the specified network domain ID. By default, the value of "DomainID" is 0 unless otherwise specified by the ROS_DOMAIN_ID environment variable.

topicList = ros2("topic","list","DomainID",ID) lists topic names with registered publishers or subscribers on the ROS 2 network for the specified network domain ID.

Note

The "DomainID" name-value pair applies only to information gathered from the active network, such as the node and topic list, and not to static ROS 2 data such as message information.

The first time ros2 is called for a specific domain ID not all information on the network may be immediately available. If incomplete network information is returned from ros2, wait for a short time before trying again.

bag2info = ros2("bag","info",folderpath) returns information about the contents of the ros2bag as a structure, bag2info at folderpath.

Note

If the ROS 2 bag log file contains custom messages, generate MATLAB interfaces to ROS 2 custom messages using ros2genmsg function before using this function.

Examples

collapse all

Show the definition of the geometry_msgs/Accel message.

ros2 msg show geometry_msgs/Accel
# This expresses acceleration in free space broken into its linear and angular parts.
Vector3  linear
Vector3  angular

Show the definition of the geometry_msgs/Accel message.

ros2 msg show geometry_msgs/Accel
# This expresses acceleration in free space broken into its linear and angular parts.
Vector3  linear
Vector3  angular

Create sample node, myNode, on the ROS 2 network.

node = ros2node("myNode");

Lists the nodes on the network.

ros2 node list
/myNode

Remove myNode from the network.

delete(node)

List the available ROS 2 topics.

ros2 topic list
/parameter_events

Input Arguments

collapse all

Message type, specified as a string scalar or character vector. The string is case-sensitive and no partial matches are allowed. It must match a message on the list given by calling ros2("msg","list").

Function syntax:

Example: ros2("msg","show","sensor_msgs/LaserScan")

Command syntax:

Example: ros2 msg show sensor_msgs/LaserScan

Data Types: char | string

Path to the ros2bag files, specified as a string scalar or character vector.

Note

folderpath location must contain ROS 2 bag file (.db3) and metadata.yaml, which holds the meta information about the bag file. The folder name must be same as the ROS 2 bag file name.

Function syntax:

Example: ros2("bag","info","C:\Users\Jack\MATLAB\EM\alltopics")

Command syntax:

Example: ros2 bag info C:\Users\Jack\MATLAB\EM\alltopics

Data Types: char | string

The domain identification of the ROS 2 network, specified as a non-negative scalar integer between 0 and 232.

Example: 2

Data Types: double

Output Arguments

collapse all

List of all message types available in MATLAB, returned as a cell array of character vectors.

Details of the information inside the ROS message definition, returned as a character vector.

List of topics from ROS master, returned as a cell array of character vectors.

List of node names available, returned as a cell array of character vectors.

Information about contents of the ros2bag, returned as a structure. This structure contains fields related to the ros2bag log file and its contents. A sample output for a ros2bag as a structure is:

         Path: 'C:\Users\Jack\MATLAB\EM\alltopics\alltopics.db3'
      Version: '1'
    StorageId: 'sqlite3'
     Duration: 102.396644003
        Start: [1×1 struct]
          End: [1×1 struct]
         Size: 4965433
     Messages: 36503
        Types: [5×1 struct]
       Topics: [5×1 struct]

Data Types: struct

Introduced in R2019b