transform listener can not look up /map frame

asked 2014-10-02 05:04:33 -0600

dalishi gravatar image

updated 2014-10-08 21:02:54 -0600

Dear All, I am asking a weired question about the transform listener.

I have tried the following two code, one with lookup base_link to odom and one to look up base_link to map. The result is I can get the transform to odom but can not get the transform to map with error:

Unable to lookup transform, cache is empty, when looking up transform from frame [/base_link] to frame [/map]

For base_link to odom:

try {

    listener.waitForTransform("odom", "base_link", ros::Time(0), ros::Duration(10.0) );
    listener.lookupTransform("odom", "base_link", ros::Time(0), transform);  
    } catch (tf::TransformException ex) {
      ROS_ERROR("%s",ex.what()); 
    }

For base_link to map:

try {

    listener.waitForTransform("map", "base_link", ros::Time(0), ros::Duration(10.0) );
    listener.lookupTransform("map", "base_link", ros::Time(0), transform);  
    } catch (tf::TransformException ex) {
      ROS_ERROR("%s",ex.what()); 
    }

I have checked using the tf view_frames and the /map frame does exist and is connected with base_link. And I have also tried another method from costmap_2d_ros which can successfully loop up the map frame. See below the getRobotPose function actually did the same thing as above only without the waitForTransform, but I don't think this is the issue.

tf::Stamped<tf::Pose> robot_pose;

tf::TransformListener tf;

costmap_2d::Costmap2DROS lcr("costmap", tf);

lcr.**getRobotPose**(robot_pose);

Can anyone help advise on this why I can not use my code to look up the transformation to /map frame? I am using Groovy under Ubuntu 12.04.4 64bit

Thanks.

Edit: Attached code and tf tree

image description image description

edit retag flag offensive close merge delete

Comments

What error did you get for base_link to map and where did you define listner

bvbdort gravatar image bvbdort  ( 2014-10-02 06:56:05 -0600 )edit

@bvbdort Hi, the error is Unable to lookup transform, cache is empty, when looking up transform from frame [/base_link] to frame [/map]. I define the tf::TransformListener tf as my class member variable. Nothing else. The above try-catch block is inside one member function. Thanks.

dalishi gravatar image dalishi  ( 2014-10-02 20:47:00 -0600 )edit

does tf::TransformListener defined inside callback ? then move it to your class constructor.

bvbdort gravatar image bvbdort  ( 2014-10-03 01:54:51 -0600 )edit

@bvbdort No, it is just a one line member variable declaration in my class tf::TransformListener tf; nothing else.

dalishi gravatar image dalishi  ( 2014-10-03 04:52:11 -0600 )edit

i mean tf should be in loop , can you share related code

bvbdort gravatar image bvbdort  ( 2014-10-03 06:49:51 -0600 )edit

@bvbdort Hi I edit my question and added the test code and tf tree for your information. For the tf, I actually ran one launch file in navigation_stage. Thanks.

dalishi gravatar image dalishi  ( 2014-10-08 21:04:44 -0600 )edit

Did waitForTransform return true or false?

Sebastian Kasperski gravatar image Sebastian Kasperski  ( 2014-10-09 02:03:09 -0600 )edit

@dalishi looks you are using bag file. Did you play rosbag with "--clock " ?

bvbdort gravatar image bvbdort  ( 2014-10-09 03:47:26 -0600 )edit