Transforming pose with tf listener is not working in Rviz
I have set some fixed position and orientation (pose) values to PR2's head_plate_frame in Rviz, trying to transform pose from head_plate_frame to base_link frame and save the values in position and quaternion arrays. But instead of going to try block, the except block is being executed, anyone can help? What is the bug here?
I have edited my code, so here is the new code:
pose1 = PoseStamped()
pose1.header.stamp = rospy.Time.now()
pose1.header.frame_id = "head_plate_frame"
pose1.pose.position.x = 0.7
pose1.pose.position.y = -0.05
pose1.pose.position.z = 1.1
pose1.pose.orientation.x = 0.3
pose1.pose.orientation.y = 0.3
pose1.pose.orientation.z = 0.2
pose1.pose.orientation.w = 0.2
listener = tf.TransformListener()
while not rospy.is_shutdown():
try:
now = rospy.Time.now()
listener.waitForTransform('/base_link','/head_plate_frame',now, rospy.Duration(10.0))
(position, quaternion) = listener.lookupTransform('/base_link', '/head_plate_frame', now)
except (tf.LookupException, tf.ConnectivityException, tf.ExtrapolationException):
traceback.print_exc()
pose_source = geometry_msgs.msg.Pose()
pose_source.orientation.x = quaternion[0]
pose_source.orientation.y = quaternion[1]
pose_source.orientation.z = quaternion[2]
pose_source.orientation.w = quaternion[3]
pose_source.position.x = position[0]
pose_source.position.y = position[1]
pose_source.position.z = position[2]
Here is the exception message;
Traceback (most recent call last):
File "/home/tawfiq/catkin_ws/src/pr2_moveit_tutorials/src/move_group_python_interface_tutorial.py", line 128, in <module>
move_group_python_interface_tutorial()
File "/home/tawfiq/catkin_ws/src/pr2_moveit_tutorials/src/move_group_python_interface_tutorial.py", line 71, in move_group_python_interface_tutorial
listener.waitForTransform('/base_link','/head_plate_frame',now, rospy.Duration(10.0))
File "/opt/ros/indigo/lib/python2.7/dist-packages/tf/listener.py", line 76, in waitForTransform
raise tf2_ros.TransformException(error_msg or "no such transformation: \"%s\" -> \"%s\"" % (source_frame, target_frame))
tf2.TransformException: Lookup would require extrapolation into the past. Requested time 1548633924.249253988 but the earliest data is at time 1548633924.770589113, when looking up transform from frame [head_plate_frame] to frame [base_link]
It would certainly help if, instead of
print("Not working")
, the except block either printed the full stack trace, or just re-raised the exception so that you can examine the real problem.Right now ..
.. we can do nothing but guess.
@Tawfiq Chowdhury: why did you delete the question and post #q313913? The answer by @PeteBlackerThe3rd is a good one, so please either accept it, or tell us why it still didn't work for you.