Ask Your Question
0

Transforming pose with tf listener is not working in Rviz

asked 2019-01-26 23:31:39 -0500

Tawfiq Chowdhury gravatar image

updated 2019-01-27 18:12:47 -0500

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]
edit retag flag offensive close merge delete

Comments

1

But instead of going to try block, the except block is being executed, anyone can help?

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

gvdhoorn gravatar imagegvdhoorn ( 2019-01-27 03:35:51 -0500 )edit
1

.. we can do nothing but guess.

gvdhoorn gravatar imagegvdhoorn ( 2019-01-27 03:37:29 -0500 )edit

@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.

gvdhoorn gravatar imagegvdhoorn ( 2019-01-28 03:04:30 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2019-01-27 05:24:34 -0500

It is true that a more specific error message would help, although I can see the problem from looking at your source code.

You're creating the transform listener object immediately before querying it for a transform, this will never work. The transform listener object needs time to collect a buffer full of transform messages before it will be able to respond to requests. It is recommended that a single tf.TransformListener is created for each node when they start up, and that object is used for all transform requests. A structure like this can be seen in the python tutorial.

Hope this helps.

edit flag offensive delete link more

Comments

My point was more general than "we cannot help you". Printing "it doesn't work" in an exception handler isn't exactly helpful or good practice.

re: problem: that is indeed most likely the issue.

gvdhoorn gravatar imagegvdhoorn ( 2019-01-27 10:35:49 -0500 )edit

There seems to be no buffer in tf, it is tf2, are you referring to rate = rospy.Rate(10.0) ?

Tawfiq Chowdhury gravatar imageTawfiq Chowdhury ( 2019-01-27 17:12:38 -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

1 follower

Stats

Asked: 2019-01-26 23:31:39 -0500

Seen: 162 times

Last updated: Jan 27