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

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

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

Poseidonius gravatar image

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

ngrennan gravatar image

Hi,

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:

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

How can I get the msg format of the topic?

Best wishes from Germany

Poseidonius

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
5

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

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
0

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

Poseidonius gravatar image

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

Thank you very much

Poseidonius

edit flag offensive delete link more

Comments

@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 -0600 )edit

Question Tools

1 follower

Stats

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

Seen: 865 times

Last updated: Apr 29 '11