tf2 ExtrapolationException Error (Python)
I have a poseStamped in Kinect frame (headmountkinectrgbopticalframe) and I am converting it to odomcombined or Base_Link frame of the PR2 robot, the robot is publishing the transformation.
Here is the code:
quat_pose_message = PoseStamped()
quat_pose_message.header.seq = 1
quat_pose_message.header.frame_id = "head_mount_kinect_rgb_optical_frame"
quat_pose_message.pose.position.x = self.base_point[0]
quat_pose_message.pose.position.y = self.base_point[1]
quat_pose_message.pose.position.z = self.base_point[2]
quat_pose_message.pose.orientation.x = self.quat_tf[0]
quat_pose_message.pose.orientation.y = self.quat_tf[1]
quat_pose_message.pose.orientation.z = self.quat_tf[2]
quat_pose_message.pose.orientation.w = self.quat_tf[3]
tf_buffer = tf2_ros.Buffer(rospy.Duration(1.0)) #tf buffer length
tf_listener = tf2_ros.TransformListener(tf_buffer)
transform = tf_buffer.lookup_transform("odom_combined",
quat_pose_message.header.frame_id, #source frame
rospy.Time(0), #get the tf at first available time
rospy.Duration(1.0))
pose_transformed = tf2_geometry_msgs.do_transform_pose(quat_pose_message, transform)
This give me the error after running the code for few seconds:
tf2.ExtrapolationException: Lookup would require extrapolation into the past. Requested time 1558658272.748801947 but the earliest data is at time 1558658274.165434361, when looking up transform from frame [head_mount_kinect_rgb_optical_frame] to frame [odom_combined]
I understand that the transformation is timing out but how to solve it?
Asked by Tawfiq Chowdhury on 2019-05-23 19:42:24 UTC
Answers
This problem is caused because of where you have created your TransformListener
object in your code.
You cannot create a TransformListener
then query it straight away, it works by listening for TF messages and accumulating an internal buffer which it then uses to resolve queries. It is recommended than you create one listener when your node is created then use that same listener for all TF queries for the duration of your node.
Hope this helps.
Asked by PeteBlackerThe3rd on 2019-05-24 06:24:45 UTC
Comments
@PeteBlackerThe3rd Hi, thank you, could you please indicate where in the code that change should take place? Could you please show?
Asked by Tawfiq Chowdhury on 2019-05-24 13:30:38 UTC
Will this help? : listener.waitf2orTransform("/turtle2", "/carrot1", now, rospy.Duration(1.0)) It is from this tutorial: http://library.isr.ist.utl.pt/docs/roswiki/tf2(2f)Tutorials(2f)Time(20)travel(20)with(20)tf2(2028)Python(29).html
Asked by Tawfiq Chowdhury on 2019-05-24 14:05:37 UTC
The tutorial above will work, but is not an ideal solution because your code will run much slower having you wait for a new listener to build up a buffer every time you're doing a Transform.
It's much better to create a TFlistener at the same time as initializing your node, then using that object. If you can show me more of your code, then I can point out the bits that need to change.
Asked by PeteBlackerThe3rd on 2019-05-25 09:39:17 UTC
The issue seems to be resolved after I put things in a try catch block, so even if exception occurs, it is caught and the execution of the code does not stop. After the exception, I get the next available transformation. Thank you.
Asked by Tawfiq Chowdhury on 2019-05-25 12:17:44 UTC
It will work, but it's not an ideal solution as I've said. Coding it this way will run significantly slower than using a single global listener.
Asked by PeteBlackerThe3rd on 2019-05-25 17:47:40 UTC
Comments