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

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 { 
    listener.lookupTransform("/odom",
    "/map",       
    ros::Time(0), 
    tfTransform);
}
catch(tf::TransformException &exception) { 
    ROS_ERROR("%s", exception.what());
}

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

2 Answers

Sort by ยป oldest newest most voted
2

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

Comments

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 image mdm  ( 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 image ayush_dewan  ( 2013-02-28 04:32:50 -0500 )edit

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

mdm gravatar image mdm  ( 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 defined..map should exist as u said ur getting transformation wen you use tf_echo..

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

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;
    try{
        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());
    rate.sleep();

}

edit flag offensive delete link more

Question Tools

Stats

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

Seen: 866 times

Last updated: Feb 28 '13