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

Unable to lookup tf transform

asked 2017-08-23 09:39:58 -0500

vkee gravatar image

updated 2017-08-23 09:45:28 -0500

gvdhoorn gravatar image

Hi,

I'm unable to lookup tf transforms in my C++ node for some reason, unless the parent and child are the same. I have done this many times before and checked with the tutorials and wikis but am not having any luck. The tf tree displays fine in RVIZ as well as command line with the tf_echo. I've tried multiple different rosbags that worked fine in other ROS nodes but nothing is working with this node.

What is different is that this time I am working with a ROS package where there are no classes, everything is in functions but I don't think that should matter because that is how the tutorial is done.

Here is a code snippet:

void laserCloudHandler(const sensor_msgs::PointCloud2ConstPtr &laserCloudMsg) {
    tf::TransformListener tf_listener;

    if (tf_listener.waitForTransform("world", "velodyne_frame", laserCloudMsg->header.stamp, ros::Duration(0.2))) {

      // Get the tf transform.
      tf::StampedTransform tf_transform;
      tf_listener.lookupTransform(world_frame, velo_frame, laserCloudMsg->header.stamp, tf_transform);
    }

    else
    {
      ROS_FATAL("UNABLE TO LOOKUP INITIAL TRANSFORM!");
    }  
}

Does anyone have any idea what may be wrong?

Thanks!

edit retag flag offensive close merge delete

Comments

@gvdhoorn thanks for fixing that formatting, i couldn't get it to work

vkee gravatar image vkee  ( 2017-08-23 09:50:01 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2017-08-23 09:47:30 -0500

gvdhoorn gravatar image

updated 2017-08-23 09:57:08 -0500

What is different is that this time I am working with a ROS package where there are no classes, everything is in functions but I don't think that should matter because that is how the tutorial is done.

just a guess, but seeing as you only instantiate your listener in your callback: 0.2 seconds is probably not enough time for the tf::TransformListener to see enough of your tree to fill the buffer and be able to retrieve transforms for you. TF needs a buffer, or it can't do anything.

Try instantiating your listener in a scope outside your callbacks (as a global variable fi). I would expect things to improve.


Edit: to avoid globals (and possible leakage) you could also use boost::bind(..) or use C++11 lambdas / closures.

edit flag offensive delete link more

Comments

I tried increased time before but it didn't help. I also tried making it a global variable but I get this error:

Couldn't find an AF_INET address for []

vkee gravatar image vkee  ( 2017-08-23 09:50:49 -0500 )edit

Try doing it after ros::init(..) and after you create your first NodeHandle.

gvdhoorn gravatar image gvdhoorn  ( 2017-08-23 09:52:22 -0500 )edit

Those are in the main so I wouldn't be able to make it global anymore.

vkee gravatar image vkee  ( 2017-08-23 09:53:01 -0500 )edit
1

Yes; use pointers (ie: tf::TransformListener* my_listener_, and then in main(..): my_listener_ = new tf::TransformListener(..) or wrap things in shared_ptrs).

gvdhoorn gravatar image gvdhoorn  ( 2017-08-23 09:55:43 -0500 )edit

Oh right, thanks that fixed it!

vkee gravatar image vkee  ( 2017-08-23 10:24:06 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2017-08-23 09:39:58 -0500

Seen: 1,179 times

Last updated: Aug 23 '17