Bag: how to get relative transform using python
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")
Asked by ticotico on 2021-09-26 11:12:14 UTC
Answers
@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.
Asked by Mike Scheutzow on 2021-09-27 15:31:15 UTC
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 attemptedlookup_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?
Asked by gvdhoorn on 2021-09-28 01:46:01 UTC
thx for the quick response! So what am I doing wrong then in the code above? Really appreciate your insights!
Asked by ticotico on 2021-09-28 16:12:51 UTC
Comments