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

Revision history [back]

I assume there isn't a dependence on changing tf frames and you are transforming into a frame that is fixed relative to the scanner. It sounds like the root of your problem is that the LaserScan header timestamps in your bag are much different than the bag timestamps of the messages (perhaps your csv had timestamps in it that were blindly put into the headers by the third party tool).

In that case you should be able to overwrite the timestamp of the replayed data with the current ros time. You could either re-record that into a new bag or do it live as it is about to be transformed into a point cloud, just set the scan->header.stamp = ros::Time::now() - fraction of a second offset, or do a tf lookup to see the most recent time the transform is available and use that timestamp. (unless setExtrapolationLimit() works? The example code in your link is old)

The re-recording is sort of the reverse of http://wiki.ros.org/rosbag/Cookbook#Rewrite_bag_with_header_timestamps - rewrite the header stamps with the bag stamps instead.

It could look like this (untested):

import rosbag
with rosbag.Bag('output.bag', 'w') as outbag:
    for topic, msg, t in rosbag.Bag('input.bag').read_messages():
        if msg._has_header:
            msg.header.stamp = t
        outbag.write(topic, msg, t)

sim time should then work with the output bag.