Main Content

rostopic

Retrieve information about ROS topics

Description

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

example

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

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.

example

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.

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.

example

Examples

collapse all

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

rosinit('192.168.17.129',11311)
Initializing global node /matlab_global_node_01393 with NodeURI http://192.168.17.1:49865/

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             
/fibonacci/cancel                                      
/fibonacci/feedback                                    
/fibonacci/goal                                        
/fibonacci/result                                      
/fibonacci/status                                      
/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                                                    
/tf_static                                             

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

rosinit('192.168.17.129',11311)
Initializing global node /matlab_global_node_29625 with NodeURI http://192.168.17.1:50079/

Show information on a specific ROS topic.

rostopic info camera/depth/points
Type: sensor_msgs/PointCloud2
 
Publishers:
* /gazebo (http://192.168.17.129:33044/)
 
Subscribers:

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

rosinit('192.168.17.129',11311)
Initializing global node /matlab_global_node_19218 with NodeURI http://192.168.17.1:55966/

Get the 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 that rostopic("list") outputs.

Output Arguments

collapse all

List of topics from the 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. The topicinfo syntax includes the message type, publishers, and subscribers associated with that topic.

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

Version History

Introduced in R2019b