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 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
What error did you get for base_link to map and where did you define listner
@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.
does tf::TransformListener defined inside callback ? then move it to your class constructor.
@bvbdort No, it is just a one line member variable declaration in my class tf::TransformListener tf; nothing else.
i mean tf should be in loop , can you share related code
@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.
Did waitForTransform return true or false?
@dalishi looks you are using bag file. Did you play rosbag with "--clock " ?