Ask Your Question

Slam_gmapping tutorial problem with time sync on rosbag

asked 2013-02-27 05:56:59 -0500

mdm gravatar image

updated 2013-02-27 05:58:59 -0500

Hello. I finished gmapping tutorial and started rosbag play and slam_gmapping (rosrun gmapping slam_gmapping scan:=base_scan). I needed to read tf from that gmapping, lets say between odom->map.

Once started rosbag and slam_gmapping time wasn't right, solved it with 'param set /use_sim_time true' before starting rosbag. With the code bellow I was reading tf and got this values:

x = 1134749241 y = -1078897170 z = -1255994495

x = 1134749241 y = -1078897170 z = -1255994495

x = 1134749241 y = -1078897170 z = -1255994495

x = 1134749241 y = -1078897170 z = -1255994495

  • not same every time, only in this example <- not an issue

Those values are too big to be real tf, so i need help with correct reading of tf from rosbag AND slam_gmapping.

Code to read tf:

tf::TransformListener listener;

ros::Rate rate(1.0);
while (nh.ok()){
tf::StampedTransform tfTransform;

try { 
catch(tf::TransformException &exception) { 
    ROS_ERROR("%s", exception.what());

ROS_INFO("%d %d %d", tfTransform.getOrigin().x(), tfTransform.getOrigin().y(), tfTransform.getOrigin().z());
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2013-02-28 00:01:13 -0500

updated 2013-02-28 01:41:55 -0500

Hey have u published clock while playing bag file using --clock parameter?? Also try tf_echo for getting transformation between map and odom. Once u plat bag file just run following command in new terminal

rosrun tf tf_echo /map /odom

If u get correct tf then there is a bug in ur code but if this command is also publishing same tf as u have mentioned in ur question then there is a problem with the way you are playing bag file.

Try using this code: tf::StampedTransform transform; try{

listener.waitForTransform("map", "/robot1/odom",ros::Time(0), ros::Duration(0.1)); listener.lookupTransform("map", "/robot1/odom", ros::Time(0), transform); } catch (tf::TransformException ex){ ROS_ERROR("Error looking up transformation\n%s",ex.what()); return; }

This works fine for me..

edit flag offensive delete link more


now i totally lost you. there is no frame "/robot1/odom" anywhere. i did tf monitor and there isn't any with that name/id

mdm gravatar imagemdm ( 2013-02-28 04:18:12 -0500 )edit

Sorry i just copied it from my own code which looks for tf between "/robot1/odom" and map. Replace that with odom and test it.

ayush_dewan gravatar imageayush_dewan ( 2013-02-28 04:32:50 -0500 )edit

did that and i says "frame /map doesn't exist"

mdm gravatar imagemdm ( 2013-02-28 04:38:41 -0500 )edit

ok do one thing play rosbag file with clock and see the complete tf tree and check where odom is should exist as u said ur getting transformation wen you use tf_echo..

ayush_dewan gravatar imageayush_dewan ( 2013-02-28 05:02:55 -0500 )edit

answered 2013-02-28 01:13:02 -0500

mdm gravatar image

first of all, thank you for answering.

i did try it all you said even before posting the question.

still haven't found any solution to my problem with reading that tf. Tf with command tf tf_echo /map /odom looks alright: "Traslation: (-0.336 , 0.318, 0.000)" , and still I can't get it right.

lets add things up on my question:

  • rosbag play --clock basic_localization_stage.bag is command I start the .bag

  • rosrun gmapping slam_gmapping scan:=base_scan

  • rosparam set /use_sim_time true in CLI

  • then start my node to read tf

and this is what i get: "Lookup would require extrapolation into the past. Requested the time 38.9583

but the earliest data is at time 39.1473, when looking up transform

from frame /map to /odom"

I place new code to it: (now it has waiting for tf, and still wrong one)

tf::TransformListener listener;
ros::Rate rate(1.0);
while (nh.ok()){
    tf::StampedTransform tfTransform;
        ros::Time now = ros::Time::now();
        listener.waitForTransform("/odom", "/map",
                                  now, ros::Duration(5.0));
        listener.lookupTransform("/odom", "/map",
                                 now, tfTransform);
    catch(tf::TransformException &exception) { 
        ROS_ERROR("%s", exception.what());

    ROS_INFO("%f %f %f", tfTransform.getOrigin().x(), tfTransform.getOrigin().y(), tfTransform.getOrigin().z());


edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2013-02-27 05:56:59 -0500

Seen: 748 times

Last updated: Feb 28 '13