ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
2

waitForTransform gets slower and slower

asked 2015-06-11 15:11:04 -0500

dinosaur gravatar image

I'm running ros hydro on ubuntu 12.04.

I'm using openni_tracker v0.2.0. I'm trying to write a python script that draws an arrow between the user's head and right hand, using frames published by the skeleton tracker.

The two transforms kinect_link -> head_1 and kinect_link -> right_hand_1 are both getting published consistently at a rate of 30 hz.

Here are two snippets of my code:

  1. tf_listener.waitForTransform('head_1', 'right_hand_1',  rospy.Time(0), rospy.Duration(0.5))
  ...
  2. hand_pose_hand_frame = PoseStamped()
  3. hand_pose_hand_frame.header.frame_id = 'right_hand_1'
  4. hand_pose_hand_frame.pose.orientation = Quaternion(w=1.0, x=0.0, y=0.0, z=0.0)
  5. hand_pose = tf_listener.transformPose('head_1', hand_pose_hand_frame)

I need line 5 because I'm drawing the arrow in the head_1 frame. I've found that if I don't include line 1, then line 5 will often fail because the transform doesn't exist. However, line 1 is problematic. The longer my code runs, the slower line 1 runs, until eventually every call times out. I used python's time.clock() to profile my code's performance over time:

image description

Since the necessary transform information is getting published at 30 hz the whole time, I can't figure out what waitForTransform is actually waiting for.

How can I fix my call to waitForTransform so that it has the same performance at T=25 as it does at T=5?

edit retag flag offensive close merge delete

Comments

How many other frames are being published on your system, and at what rate?

What does rostopic hz tf give you?

jbohren gravatar image jbohren  ( 2015-06-11 18:16:19 -0500 )edit

15 frames are being published at 30 hz and 4 frames are being published at 10 hz

dinosaur gravatar image dinosaur  ( 2015-06-11 20:32:15 -0500 )edit

rostopic hz tf yields lots of lines similar to average rate: 497.771min: 0.000s max: 0.035s std dev: 0.00671s window: 981

dinosaur gravatar image dinosaur  ( 2015-06-11 20:32:59 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
3

answered 2015-06-11 19:31:35 -0500

dinosaur gravatar image

updated 2015-06-11 20:17:03 -0500

I figured it out! I was creating a new TransformListener each iteration of my loop. By only creating one TransformListener and reusing it for every call, I can now run my main loop as fast as I want. (With no forced delay, it runs at 300 hz!)

Just for fun, here's another graph of the problematic version. (yellow and blue use the left y-axis, red uses the right) image description

edit flag offensive delete link more

Comments

Thanks a lot for this quick tip! I was looking for various ways to handle the slow transformation. Thanks to this, I speed up my program. Nevertheless, I should have paid enough attention when creating the instance of TransformListener at every iteration.

asaglam gravatar image asaglam  ( 2021-02-20 00:57:20 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2015-06-11 15:11:04 -0500

Seen: 1,035 times

Last updated: Jun 11 '15