Ask Your Question
8

using tf data from bag files

asked 2011-10-08 12:58:29 -0500

mkillpack gravatar image

updated 2014-01-28 17:10:32 -0500

ngrennan gravatar image

I'm wondering if there is a good way to get transforms (rotation and translation) from tf data recorded in bag files. I'm working in python and I don't want to replay the bag file as part of the solution. Instead I want to be able to get other messages from the bag file and use tf to find the euclidean distance between two frames on the robot at the same time instant as my message of interest. Any thoughts?

I could look at parent-child relationships in a single tf message and string the transforms together, but then I'd be recreating the functionality of tf. Is there a utility or tool for getting a transformation from a single tf message (i.e. not using ROS to wait for transform or having to replay the bag file). Thanks a lot for any ideas.

edit retag flag offensive close merge delete

4 Answers

Sort by » oldest newest most voted
3

answered 2011-10-17 06:43:23 -0500

updated 2011-10-17 19:26:00 -0500

The main problem is that playing a bag files in conjunction with tf is problematic. Tf messages arent't synchronized with the current rosTime. Several alternatives has been proposed but apparently they don't work (at least not for me in python). See http://answers.ros.org/question/1114/waitfortransform-use_sim_time-python and see also http://ros-users.122217.n3.nabble.com/tf-use-sim-time-clock-and-bag-files-td1305066.html

AFAIK this problem is still not solved for tf in python. I think it would be possible if the TransformListener::subscription_callback were public. Am I right? tf::tfMessage's could be retrieved from bag and pushed manually using this method and the Bag API (see below a pythonic code - pytf.cpp modifications also needed):

bag = rosbag.Bag(bag_file)
listener = tf.TransformListener()
for topic, msg, t in bag.read_messages(topics=['/tf']):
     listener.subscription_callback(msg)

To reproduce bags with tf messages are very interesting specially in geometric learning problems where bags files with transform information can be used as training database (this is my case).

Until now I'm using this solution to simulate tf in a bag messages at the current time(though I don't like it so much):

import roslib
roslib.load_manifest('tf')
import rospy
import tf

rospy.init_node("tf_restamper")
tfpublisher= rospy.Publisher("tf",tf.msg.tfMessage)

def tfcallback(tfmessage):
    for transf in tfmessage.transforms:
        transf.header.stamp=rospy.Time.now()
    tfpublisher.publish(tfmessage)

tfproxy = rospy.Subscriber("tf_old",tf.msg.tfMessage,tfcallback)
rospy.spin()
edit flag offensive delete link more

Comments

1

It seems like some of the timing issues can be dealt with by setting the /use_sim_time parameter to true (use --clock option for rosbag play). However, this doesn't work to play/look at more than one bag file in a single process. When the time starts over for the 2nd bag file, tf freaks out.

mkillpack gravatar imagemkillpack ( 2012-02-25 03:58:42 -0500 )edit
4

answered 2011-10-09 14:24:53 -0500

tfoote gravatar image

Any single tf message is only a part of the state of the system. To know the state of the system you need to aggregate tf messages over time. You can do this on a bag file without playing back the messages by using the rosbag code API. But it is likely that you will still want to use the tf libraries which are designed to accumulate the messages and be queryable.

edit flag offensive delete link more

Comments

1
I figured that was the only solution, but all the tf information should be available from a single tf message. Technically I shouldn't need to aggregate it over time. It's good to know my use case just wasn't in the design of tf. Thanks.
mkillpack gravatar imagemkillpack ( 2011-10-09 20:58:41 -0500 )edit
2

answered 2017-09-12 08:05:19 -0500

marcoesposito1988 gravatar image

I also ran into this problem and this question many times, so I eventually created a python package called tf_bag.

I hope this can be helpful to anybody finds this topic.

edit flag offensive delete link more
1

answered 2011-10-09 22:01:53 -0500

mkillpack gravatar image

It looks like the easiest way will be to replay the bag file and use tf libraries to get this transform and record it with a time stamp to a separate file. Then I can at least interpolate between transforms for the time I'm interested in for my other messages. Not as nice as using tf directly or ROS tools directly, but it will allow me to access a transform at a given time without playing a bag file online.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2011-10-08 12:58:29 -0500

Seen: 6,737 times

Last updated: Sep 12 '17