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

Bag: how to get relative transform using python

asked 2021-09-26 11:12:14 -0600

ticotico gravatar image

updated 2021-09-26 11:17:59 -0600

I have a bag with a minimal tf tree: Basically one parent and two children. My goal is now to get the tf from child1 to child 2. I followed this tutorial and this question but still it is somehow unclear to me, how I would do that. I am sure that someone already did this and I am wondering what the best way is to achieve this using python. Thx!

What I have so far:

tf_buffer = tf2.BufferCore(rospy.Duration(1000000))

bag = rosbag.Bag(path_to_bag)

for topic, msg, t in bag.read_messages(topics=['/tf', '/tf_static']):
    for msg_tf in msg.transforms:
        if topic == '/tf_static':
            tf_buffer.set_transform_static(msg_tf, "default_authority")
        else:
            tf_buffer.set_transform(msg_tf, "default_authority")

        tf_buffer.lookup_transform("child1", "child2")
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-09-27 15:31:15 -0600

Mike Scheutzow gravatar image

updated 2021-09-28 16:07:01 -0600

I believe that the tf2_ros BufferInterface lookup_transform() call only works in 'one direction', either moving up the TF tree or down the tree. So I'd expect your attempted lookup_transform() line to throw an exception since neither child is a parent of the other.

However, there is a advanced method called lookup_transform_full() where you additionally specify the "common parent node" for two nodes lower in the TF tree, and the call will calculate a -> b -> c for you.

@gvdhoorn is correct in his comment below: the lookup_transform() does handle 'child1' -> 'child2". Assuming you actually assign the returned geometry_msgs/TransformStamped object to a variable, you'll have your answer. You may need to do something with the original msg.header.stamp, because the tf_buffer will discard messages that are too old.

edit flag offensive delete link more

Comments

I believe that the tf2_ros BufferInterface lookup_transform() call only works in 'one direction', either moving up the TF tree or down the tree. So I'd expect your attempted lookup_transform() line to throw an exception since neither child is a parent of the other.

Afaik the full transform tree is always considered for all queries.

How would you know the "common parent node" if you don't know the full tree?

gvdhoorn gravatar image gvdhoorn  ( 2021-09-28 01:46:01 -0600 )edit

thx for the quick response! So what am I doing wrong then in the code above? Really appreciate your insights!

ticotico gravatar image ticotico  ( 2021-09-28 16:12:51 -0600 )edit

Question Tools

3 followers

Stats

Asked: 2021-09-26 11:12:14 -0600

Seen: 353 times

Last updated: Sep 28 '21