ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

How to obtain the msg format of a topic on runtime?

asked 2011-04-28 06:31:23 -0500

Poseidonius gravatar image

updated 2014-01-28 17:09:36 -0500

ngrennan gravatar image


I need to implement a dynamic subscription mechanism, that monitors the available topics. Firstly it takes a view to the msg format of new topics and subscribes to this one depending on a special data format. The first step, to know the current available topics works fine with the following code:

def monitor():
   while not rospy.is_shutdown():
      master = rosgraph.masterapi.Master('/rostopic')
      available_topics = master.getPublishedTopics('/') 
      for topic in available_topics:
         if not topic in available_topics_old:
      if new_topics:
          # here I need to know the format(file) of the assigned msg

How can I get the msg format of the topic?

Best wishes from Germany


edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2011-04-28 08:01:41 -0500

kwc gravatar image

These are unofficial/volatile APIs, but you can look at how they introspect on the graph to pull the data out (most of this can be done with the masterapi or filesystem operations):

import roslib.message
import rostopic
import rosmsg

type_name = rostopic.get_topic_type('/rosout', blocking=False)[0]
if type_name:
    message_class = roslib.message.get_message_class(type_name)
    message_text = rosmsg.get_msg_text(type_name)
    full_message_text = message_class._full_text
edit flag offensive delete link more

answered 2011-04-29 04:41:25 -0500

Poseidonius gravatar image

Very nice, that's the commands I looked for!

Thank you very much


edit flag offensive delete link more


@Poseidonius Please mark the best answer by clicking the check mark next to it, so others know the question is answered. I"ve done it for you in this case.
tfoote gravatar image tfoote  ( 2011-04-29 08:49:02 -0500 )edit

Question Tools

1 follower


Asked: 2011-04-28 06:31:23 -0500

Seen: 824 times

Last updated: Apr 29 '11