rostopic

Retrieve information about ROS topics

Syntax

rostopic list
rostopic echo topicname
rostopic info topicname
rostopic type topicname
topiclist = rostopic("list")
msg = rostopic("echo", topicname)
topicinfo = rostopic("info", topicname)
msgtype = rostopic("type", topicname)

Description

example

rostopic list returns a list of ROS topics from the ROS master.

rostopic echo topicname returns the messages being sent from the ROS master about a specific topic, topicname. To stop returning messages, press Ctrl+C.

example

rostopic info topicname returns the message type, publishers, and subscribers for a specific topic, topicname.

example

rostopic type topicname returns the message type for a specific topic.

example

topiclist = rostopic("list") returns a cell array containing the ROS topics from the ROS master. If you do not define the output argument, the list is returned in the MATLAB® Command Window.

msg = rostopic("echo", topicname) returns the messages being sent from the ROS master about a specific topic, topicname. To stop returning messages, press Ctrl+C. If the output argument is defined, then rostopic returns the first message that arrives on that topic.

example

topicinfo = rostopic("info", topicname) returns a structure containing the message type, publishers, and subscribers for a specific topic, topicname.

example

msgtype = rostopic("type", topicname) returns a character vector containing the message type for the specified topic, topicname.

Examples

collapse all

Connect to ROS network. Specify the IP address of the ROS device.

rosinit('192.168.154.131')
Initializing global node /matlab_global_node_23844 with NodeURI http://192.168.154.1:56317/

List the ROS topic available on the ROS master.

rostopic list
/camera/depth/camera_info                              
/camera/depth/image_raw                                
/camera/depth/points                                   
/camera/parameter_descriptions                         
/camera/parameter_updates                              
/camera/rgb/camera_info                                
/camera/rgb/image_raw                                  
/camera/rgb/image_raw/compressed                       
/camera/rgb/image_raw/compressed/parameter_descriptions
/camera/rgb/image_raw/compressed/parameter_updates     
/clock                                                 
/cmd_vel_mux/active                                    
/cmd_vel_mux/input/navi                                
/cmd_vel_mux/input/safety_controller                   
/cmd_vel_mux/input/teleop                              
/cmd_vel_mux/parameter_descriptions                    
/cmd_vel_mux/parameter_updates                         
/depthimage_to_laserscan/parameter_descriptions        
/depthimage_to_laserscan/parameter_updates             
/gazebo/link_states                                    
/gazebo/model_states                                   
/gazebo/parameter_descriptions                         
/gazebo/parameter_updates                              
/gazebo/set_link_state                                 
/gazebo/set_model_state                                
/joint_states                                          
/laserscan_nodelet_manager/bond                        
/mobile_base/commands/motor_power                      
/mobile_base/commands/reset_odometry                   
/mobile_base/commands/velocity                         
/mobile_base/events/bumper                             
/mobile_base/events/cliff                              
/mobile_base/sensors/bumper_pointcloud                 
/mobile_base/sensors/core                              
/mobile_base/sensors/imu_data                          
/mobile_base_nodelet_manager/bond                      
/odom                                                  
/rosout                                                
/rosout_agg                                            
/scan                                                  
/tf                                                    

Connect to ROS network. Specify the IP address of the ROS device.

rosinit('192.168.154.131')
Initializing global node /matlab_global_node_28473 with NodeURI http://192.168.154.1:57251/

Show info on a specific ROS topic.

rostopic info camera/depth/points
Type: sensor_msgs/PointCloud2
 
Publishers:
* /gazebo  http://192.168.154.131:46957/ 
 
Subscribers:

Connect to ROS network. Specify the IP address of the ROS device.

rosinit('192.168.154.131')
Initializing global node /matlab_global_node_70141 with NodeURI http://192.168.154.1:58138/

Get message type for a specific topic. Create a message from the message type to publish to the topic.

msgtype = rostopic('type','camera/depth/points');
msg = rosmessage(msgtype);

Input Arguments

collapse all

ROS topic name, specified as a string scalar or character vector. The topic name must match one of the topics thatrostopic("list") outputs.

Output Arguments

collapse all

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

ROS message for a given topic, returned as an object handle.

Information about a ROS topic, returned as a structure. topicinfo included the message type, publishers, and subscribers associated with that topic.

Message type for a ROS topic, returned as a character vector.

Introduced in R2015a