Ask Your Question

tf2 ExtrapolationException Error (Python)

asked 2019-05-23 19:42:24 -0600

Tawfiq Chowdhury gravatar image

updated 2019-05-23 20:02:50 -0600

I have a poseStamped in Kinect frame (head_mount_kinect_rgb_optical_frame) and I am converting it to odom_combined 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
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?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2019-05-24 06:24:45 -0600

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.

edit flag offensive delete link more


@PeteBlackerThe3rd Hi, thank you, could you please indicate where in the code that change should take place? Could you please show?

Tawfiq Chowdhury gravatar image Tawfiq Chowdhury  ( 2019-05-24 13:30:38 -0600 )edit

Will this help? : listener.waitf2orTransform("/turtle2", "/carrot1", now, rospy.Duration(1.0)) It is from this tutorial:

Tawfiq Chowdhury gravatar image Tawfiq Chowdhury  ( 2019-05-24 14:05:37 -0600 )edit

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.

PeteBlackerThe3rd gravatar image PeteBlackerThe3rd  ( 2019-05-25 09:39:17 -0600 )edit

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.

Tawfiq Chowdhury gravatar image Tawfiq Chowdhury  ( 2019-05-25 12:17:44 -0600 )edit

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.

PeteBlackerThe3rd gravatar image PeteBlackerThe3rd  ( 2019-05-25 17:47:40 -0600 )edit

Your Answer

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

Add Answer

Question Tools



Asked: 2019-05-23 19:42:24 -0600

Seen: 270 times

Last updated: May 24 '19