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

TransformListener Question [closed]

asked 2012-11-11 10:11:27 -0500

updated 2014-01-28 17:14:13 -0500

ngrennan gravatar image

I think that this must be some sort of silly mistake on my part but.... I'm trying to use the following code. My transform tree (verified with command line tf and rviz) has /map -> /odom -> /base_link in it. But when I try to run the following C++ I end up getting a transform error claiming:

Frame id /map does not exist! Frames (1):

The simulation in gazebo is up and running for plenty of time before I even try to run this code so I don't think it's an issue of the transforms not being published yet. Also, it's not complaining about extrapolation so I don't think it's a timestamping issue?

ros::init(argc, argv, "transform test");
ros::NodeHandle n;

tf::TransformListener tfListener;

geometry_msgs::PointStamped baseLinkPoint;
geometry_msgs::PointStamped mapPoint;

baseLinkPoint.header.frame_id = "/base_link";
baseLinkPoint.header.stamp = ros::Time::now();

baseLinkPoint.point.x = 0.0;
baseLinkPoint.point.y = 0.0;
baseLinkPoint.point.z = 0.0;

try { tfListener.transformPoint("/map", baseLinkPoint, mapPoint); }
catch (tf::TransformException ex) { ROS_ERROR("%s",ex.what()); }

Any insight is greatly appreciated!

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by skiesel
close date 2013-10-11 04:39:59


What happens if you put the try catch in a loop with a 1 second sleep in it?

jbohren gravatar image jbohren  ( 2012-11-12 06:34:40 -0500 )edit

First of all, thanks so much for helping out. If I let it loop I get the same error for a while and the tree tf tree fleshes out (after the error it lists the frames) and then finally it says taht the transform because the cache is empty when looking up transform from /base_link to /map.

skiesel gravatar image skiesel  ( 2012-11-12 07:17:29 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2012-11-12 08:35:42 -0500

Okay so it looks like what is happening here is that I need to use waitForTransform. The TransformListener is sluggish to aggregate data in my case, maybe the frames I'm interesting in aren't being published all that frequently. That's not the subtle point here though.

Notice that I'm trying to transform the point with the stamp ros::Time::now(). It appears to be the case that when I get the timestamp from ros::Time is BEFORE the listener can get anything into its buffer. Meaning that this will report and extrapolation error into the past! So to combat this I needed to wait for the transform to be published, ie, the buffer fills a little (which is normal), but also update the timestamp carefully so that it can eventually succeed.

edit flag offensive delete link more

Question Tools


Asked: 2012-11-11 10:11:27 -0500

Seen: 419 times

Last updated: Nov 12 '12