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

How to listen to tf inside a callback loop?

asked 2013-11-26 20:23:22 -0500

I am converting laser Scan points from laser frame to map frame(occupancy grid).The tf between them changes as the robot moves so I need to listen to TF every time the laser callback is called. But the tf doesn't get called every time.It is only listened to once.the code is here. the waitforTransform doesnt get called at all.

edit retag flag offensive close merge delete


Do the transforms get published? Check the output of rostopic echo /tf

BennyRe gravatar image BennyRe  ( 2013-11-26 21:59:30 -0500 )edit

Tf gets published. The problem is as the mobile robot moves, the tf changes and hence during very laser callback, the tf must be listened to get the current tf. The code is using the tf which was present at the launch of the program and tf doesnt listen to it after that.

balakumar-s gravatar image balakumar-s  ( 2013-11-26 22:11:15 -0500 )edit

tf is used all the time on mobile robots. Please provide the error outputs and what you are expecting. As well as a way to reproduce the problem so we can help you.

tfoote gravatar image tfoote  ( 2013-11-27 05:36:07 -0500 )edit

I just had to put the tf listener inside the callback and it works. But it caches for sometime and then uses that cached tf to convert the laserscan to map. Is there a way to listen to tf in realtime? I am attaching the text file here:

balakumar-s gravatar image balakumar-s  ( 2013-11-27 05:45:39 -0500 )edit

I found a solution and the problem is solved. @tfoote I am new to this, so should I close this question or type the solution as an answer and tick it?

balakumar-s gravatar image balakumar-s  ( 2013-11-27 06:13:22 -0500 )edit

You can put the answer below if you've solved it yourself. However your linked solution with the TransformListener constructed inside the callback function is very fragile and likely not to generalize. It forces the cache to rebuild in every callback. And the incoming data is in a different thead in either implementation. You will need to debug deeper to understand what is actually your problem. You're just masking it with this solution.

tfoote gravatar image tfoote  ( 2013-11-27 06:19:14 -0500 )edit

I forgot the basics of tf of using stamped time from laserscan. i fixed it. I will post it as an answer. Thanks !

balakumar-s gravatar image balakumar-s  ( 2013-11-27 06:20:55 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2013-11-27 06:23:41 -0500

I fixed the problems. Using this code realtime tf between laser and map is obtained.

edit flag offensive delete link more


@tfoote my karma is 15 so not able to accept my own answer.

balakumar-s gravatar image balakumar-s  ( 2013-11-27 06:24:48 -0500 )edit

I voted up your question. You should now have enough karma.

tfoote gravatar image tfoote  ( 2013-11-27 10:28:29 -0500 )edit

Question Tools

1 follower


Asked: 2013-11-26 20:23:22 -0500

Seen: 3,389 times

Last updated: Nov 27 '13