Ask Your Question
0

tf2 ExtrapolationException Error (Python)

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

Tawfiq Chowdhury gravatar image

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

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
                    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?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

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

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

Comments

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

Tawfiq Chowdhury gravatar imageTawfiq Chowdhury ( 2019-05-24 13:30:38 -0500 )edit

Will this help? : listener.waitf2orTransform("/turtle2", "/carrot1", now, rospy.Duration(1.0)) It is from this tutorial: http://library.isr.ist.utl.pt/docs/ro...

Tawfiq Chowdhury gravatar imageTawfiq Chowdhury ( 2019-05-24 14:05:37 -0500 )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 imagePeteBlackerThe3rd ( 2019-05-25 09:39:17 -0500 )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 imageTawfiq Chowdhury ( 2019-05-25 12:17:44 -0500 )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 imagePeteBlackerThe3rd ( 2019-05-25 17:47:40 -0500 )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

2 followers

Stats

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

Seen: 78 times

Last updated: May 24