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

programatically create subscribers

asked 2013-04-17 03:26:57 -0500

makokal gravatar image

I am trying to make a simple logger that given a list of topics via a service or an action, subscribes to and logs the data from these topics. This requires me to initiate subscribers on the fly and the callback data handlers are proving not easy to get around. Any ideas?

edit retag flag offensive close merge delete


Have you looked at rosbag?

joq gravatar image joq  ( 2013-04-17 16:36:05 -0500 )edit

Yes, but what we need goes beyond rosbag, we need to be able to process the data independent of ROS

makokal gravatar image makokal  ( 2013-04-21 23:56:43 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2013-12-12 17:00:52 -0500

Chengarda gravatar image

updated 2013-12-12 17:01:10 -0500

I'm doing a similar thing at the moment. So far, it only seems possible in rospy, not roscpp. I'm using the services:


to get a full list of topics and msg types, then a little (lots) of dodgy string manipulation getting the correct format of topic to use with:


(this dynamically creates a from pkg import topictype C++ doesn't seem to have an equivalent)

once you have the topic name and type, it's easy to subscribe to it. You can filter the full list by comparing against your provided list to only subscribe to topics you are interested in.

edit flag offensive delete link more



_type_name = __import__('std_msgs.msg', globals(), locals(), ['String'], -1) and then rospy.Subscriber("/some_topic", _type_name.String, callback) works for me. However is there a way to eliminate having to type String? I want to invoke the above import and be able to use _type_name directly.

McMurdo gravatar image McMurdo  ( 2014-05-31 08:33:08 -0500 )edit

Question Tools

1 follower


Asked: 2013-04-17 03:26:57 -0500

Seen: 800 times

Last updated: Dec 12 '13