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

Revision history [back]

click to hide/show revision 1
initial version

I see two issues.

The first is that you appear to be constructing the Listener immediately before trying to query transforms from it. But you're not giving it any time to populate before trying to query the buffer. Without that your lookup will likey be unable to get lucky enough to get exactly the right transform data during the timeout for your canTransform call.

It makes sense to have the TransformListener initialized in a constructor, but it should be persistent and continue in the background not be on the stack. Otherwise it will stop listening when your constructor is completed. And secondly your queries for the value should be done in a way that it will retry, or fail and try again the next time around.

If you do get lucky enough for the canTransform call to succeed you most likely won't be able to execute the lookup transform because you're querying it with a different timestamp. If you want to use this construct you should compute the time at which you want to run your query and then use that same timestamp in the subsequent lookup.

However I'll suggest that you use the lookupTransform method with the timeout integrated to avoid this issue all together.