How to use transformPose in Python with Time(0) (most recent common time)?
I want to use TF to transform a PoseStamped into a frame, perform some operations, and then transform it back to its original frame. The frame is not published to TF, so I set it as a TransformStamped in the TfListener:
m = geometry_msgs.msg.TransformStamped()
m.header.frame_id = surface_origin.header.frame_id
m.header.stamp = rospy.Time.now()-rospy.Duration(0.1)
m.child_frame_id = "tmp_frame__"
m.transform.translation.x = surface_origin.pose.position.x
m.transform.translation.y = surface_origin.pose.position.y
m.transform.translation.z = surface_origin.pose.position.z
m.transform.rotation.x = surface_origin.pose.orientation.x
m.transform.rotation.y = surface_origin.pose.orientation.y
m.transform.rotation.z = surface_origin.pose.orientation.z
m.transform.rotation.w = surface_origin.pose.orientation.w
tf_listener.setTransform(m)
in_pose_in_tmp_frame = tf_listener.transformPose("tmp_frame__", in_pose)
# [...] Do operations here
new_pose_in_original_frame = tf_listener.transformPose(in_pose.header.frame_id, in_pose)
Sadly, I get an ExtrapolationException on the second transformPose because the operations take too long:
tf2.ExtrapolationException: Lookup would require extrapolation at time 1617082915.398905516, but only time 1617082913.271360636 is in the buffe, when looking up transform from frame [tmp_frame__] to frame [surface_frame]
I tried adding rospy.Time(0), since "Time(0) gives you the latest common time". However, it looks the Python API doesn't offer that. Looking at the source code seems to confirm this.
I cannot find documentation for the TF2 Python API. The TF Python documentation is only generated up until Melodic(?), so the link in the wiki is broken. The TF2 source code is not human-readable unless you know how Python bindings are generated from C++.
I also tried using setTransform
again before the second transformPose
call, to update the transform, but then TF complains about extrapolation into the negative future, which is excessively strange:
tf2.ExtrapolationException: Lookup would require extrapolation -0.099048138s into the future. Requested time 1617083034.013916254 but the latest data is at time 1617083033.914868116, when looking up transform from frame [tmp_frame__] to frame [surface_frame]
I know I should port to TF2, but I didn't have a pressing reason yet. I only need to use the TF tree here, no extrapolation or time lookup. Is there a "please don't bother me about time" setting in Python? Where is the TF2 Python documentation? How else could I solve this issue without much hassle?
edit:
The tf2 Python API is the C++ documentation, and the tf2_ros API is available here and here for Melodic. It looks like this is not as visible as it should be, but I'm not sure what to do about that.
The extrapolation error about a lookup at -0.099s into the future
(although a negative time in the future should be in the past) might be because I did not set the seq
of the header.