Robotics StackExchange | Archived questions

transform listener can not look up /map frame

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

I have tried the following two code, one with lookup baselink to odom and one to look up baselink 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 viewframes and the /map frame does exist and is connected with baselink. And I have also tried another method from costmap2dros 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

Asked by dalishi on 2014-10-02 05:04:33 UTC

Comments

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

Asked by bvbdort on 2014-10-02 06:56:05 UTC

@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.

Asked by dalishi on 2014-10-02 20:47:00 UTC

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

Asked by bvbdort on 2014-10-03 01:54:51 UTC

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

Asked by dalishi on 2014-10-03 04:52:11 UTC

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

Asked by bvbdort on 2014-10-03 06:49:51 UTC

@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.

Asked by dalishi on 2014-10-08 21:04:44 UTC

Did waitForTransform return true or false?

Asked by Sebastian Kasperski on 2014-10-09 02:03:09 UTC

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

Asked by bvbdort on 2014-10-09 03:47:26 UTC

@Sebastian Kasperski waitForTransform returned 0. The weird thing is I can use this to look up the base_link to odom, but with the same code can not extract base_link to map.

Asked by dalishi on 2014-10-09 07:28:23 UTC

@bvbdort I did not use bag file. I was running ros navigation stack with stage simulator.

Asked by dalishi on 2014-10-09 07:29:39 UTC

@Sebastian Kasperski using the costmap_2D::getRobotPose() I can successfully look up from base_link to map and get the robot pose. I guess there must be something missing in my code.

Asked by dalishi on 2014-10-09 07:31:41 UTC

Have you set "use_sim_time" parameter to true in your launch file? (Just guessing around here ...)

Asked by Sebastian Kasperski on 2014-10-09 07:33:12 UTC

@Sebastian Kasperski yes, /use_sim_time true. I am now using the costmap_2D::getRobotPose() to get the robot pose instead of my own tf lookup code. It is working. But still have not figured out whats wrong with my code. : (

Asked by dalishi on 2014-10-11 06:13:53 UTC

Answers