How to get topic from a message
I'm trying to write a custom bagging node for my ROS installation. The node's requirements are to only bag topics that are published on the local machine (my ROS installation runs on a 3-computer setup), to throttle the bagging rate based on system load and free disk space, and to only bag topics specific to the state of the robot. This means that subscriptions are being created and destroyed on-the-fly, and therein lies my problem.
For creating and destroying the subscriptions, I have these 2 lines of code:
map(lambda x: x.unregister(), SUBSCRIPTIONS)
SUBSCRIPTIONS = map(lambda topic: rospy.Subscriber(topic, AnyMsg, bag), TOPICS)
The top line unsubscribes everything and the bottom one makes all new ones. As you can see, each subscription has a callback method of bag
. In that method, I was hoping to just be able to write the message to a bag, independent of the topic. I didn't realize until now that rosbag.Bag.write()
requires both the message _and_ the topic.
So, what's the easiest way of getting the message publisher's topic type? In addition, is there any easier way of doing what I've described?
Thanks for your help!
-lourd
Duplicate of http://answers.ros.org/question/68434/get-topic-name-in-callback/ ??