Ask Your Question

How to listen to tf inside a callback loop?

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

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 imageBennyRe ( 2013-11-26 21:59:30 -0600 )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 imagebalakumar-s ( 2013-11-26 22:11:15 -0600 )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 imagetfoote ( 2013-11-27 05:36:07 -0600 )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 imagebalakumar-s ( 2013-11-27 05:45:39 -0600 )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 imagebalakumar-s ( 2013-11-27 06:13:22 -0600 )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 imagetfoote ( 2013-11-27 06:19:14 -0600 )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 imagebalakumar-s ( 2013-11-27 06:20:55 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

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

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 imagebalakumar-s ( 2013-11-27 06:24:48 -0600 )edit

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

tfoote gravatar imagetfoote ( 2013-11-27 10:28:29 -0600 )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


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

Seen: 2,255 times

Last updated: Nov 27 '13