Ask Your Question
2

Mapping in slam_toolbox using bag files (ros2)

asked 2021-09-28 08:39:09 -0500

joesherman gravatar image

I am using slam_toolbox (in ROS Foxy) to generate a map of an environment using bag files of recorded laserScan and odometry data. The map is successfully generated, however, while running the node and visualising the sensor data (in frame 'cluod') on rviz, I get the following error,

Transform
No transform to fixed frame [map]. TF error: [Lookup would require extrapolation into the future. Requested time 1632836191.729568 but the latest data is at time 1631538428.177000, when looking up transform from frame [cloud] to frame [map]]

The fixed frame is set to 'map'.

Here is the tf_tree view from the tf2_tools view_frames.py program, image description

I interpret from the above image, that slam_toolbox is publishing the map->odom transformation with the current system timestamp, while the odom->base_link and base_link->cloud transforms have a past timestamp (from the time the bag was recorded) on them and it may be the cause of my issue.

I could not find any help on how to use slam_toolbox with recorded bag files and have also checked all the possible launch files in the slam-toolbox (e.g. offline, async, sync, etc). There was not much help to be found in the official documentation of slam_toolbox as well. Would be nice if anyone who's worked on a similar problem before, could help out with this.

edit retag flag offensive close merge delete

Comments

1

I interpret from the above image, that slam_toolbox is publishing the map->odom transformation with the current system timestamp, while the odom->base_link and base_link->cloud transforms have a past timestamp (from the time the bag was recorded) on them and it may be the cause of my issue.

Your statement here is true. Try setting the use_sim_time parameter to true for the slam_toolbox node. Currently, rosbag2 for Foxy doesn't support publishing the clock (available from Galactic onwards) so I am not sure if this would have any effect. This github issue has some workarounds.

3473f gravatar image 3473f  ( 2021-11-21 20:51:14 -0500 )edit
1

Hey, you are right. rosbag2 in foxy does not publish the clock. But even if you publish the clock, the foxy-devel distribution (one that gets downloaded with the package manager install) of slam_toolbox will not use it.

My workaround was to get the source code of the foxy-devel branch and then cherry-pick the "fixed timestamps input&output not synchronized  (#377)" commit from the 'ros-2' branch of slam_toolbox. The fix in this commit is to synchronize the i/p & o/p timestamps, i.e., it uses the timestamps of scan topic to publish the map->odom transform. This fixed my issue and I got some nice maps made out of it! No clock publishing is needed!

joesherman gravatar image joesherman  ( 2021-11-22 02:26:45 -0500 )edit
1

The fact that slam_toolbox wouldn't integrate this functionality as it is useless totally flew over my head. Glad you managed to find a workaround and thank you for documenting it here.

3473f gravatar image 3473f  ( 2021-11-22 03:41:41 -0500 )edit

2 Answers

Sort by ¬Ľ oldest newest most voted
0

answered 2021-11-22 02:33:36 -0500

joesherman gravatar image

The documentation everywhere suggest using the use_sim_time parameter to synchronize the output of the slam_toolbox to that of the bagged topics, but on a deeper look, firstly rosbag2 in foxy doesn't yet have the clock topic (available from Galactic onwards), which can be solved by publishing manually to this topic from the timestamps of the sensor/Odom data in the bags. Secondly, and more importantly, even that won't solve our problems as the foxy-devel branch of slam_toolbox (the one that gets downloaded with apt install ros-foxy-slam-toolbox) doesn't make use of the use_sim_time parameter anyway.

So, my workaround was to get the source code of the foxy-devel branch and then cherry-pick the "fixed timestamps input&output not synchronized (#377)" commit from the 'ros-2' branch of slam_toolbox. The fix in this commit is to synchronize the i/p & o/p timestamps, i.e., it uses the timestamps of scan topic to publish the map->odom transform. This fixed my issue and I got some nice maps made out of it! No clock publishing is needed!

edit flag offensive delete link more
0

answered 2021-11-21 07:39:00 -0500

JehanJay gravatar image

Are the timestamps of /odom messages and the TF messages the same? That could be what's causing it if you're running a script to do manual publishing of /odom messages to /tf without having the complete TF tree in your rosbag file.

edit flag offensive delete link more

Comments

Yes, the timestamps are the same!

joesherman gravatar image joesherman  ( 2021-11-22 02:27:53 -0500 )edit

Your Answer

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

Add Answer

Question Tools

1 follower

Stats

Asked: 2021-09-28 08:39:09 -0500

Seen: 219 times

Last updated: Nov 22 '21