解决rosbag时间戳未对齐的解决方法
Reference:
ROS.org: rosbag/Cookbook :
http://wiki.ros.org/rosbag/Cookbook.
rosbag在存储时间时,接收消息的时间和生成消息的时间可能会有很大的差别。例如:程序处理速度慢导致的消息延后; 消息在慢速播放时被记录;Synchronizer的msg传入过晚…
因此,使用每个topic内的header时间作为播放时的时间戳(rosbag record时间使用的是当前的电脑时间)不失为一种比较奈斯的方法:
import rospy
import rosbag
import sys
if sys.getdefaultencoding() != 'utf-8':
reload(sys)
sys.setdefaultencoding('utf-8')
bag_name = '2020-08-12-12-48-42.bag'
out_bag_name = 'out_2020-08-12-12-48-42.bag'
dst_dir = '/home/yinji/sda/bag_2020/'
with rosbag.Bag(dst_dir+out_bag_name, 'w') as outbag:
stamp = None
for topic, msg, t in rosbag.Bag(dst_dir+bag_name).read_messages():
if topic == '/gps':
stamp = msg.header.stamp
elif topic == '/image_stamp' and stamp is not None:
outbag.write(topic, msg, stamp)
continue
elif topic == '/image_time':
outbag.write(topic, msg, msg.stamp)
continue
outbag.write(topic, msg, msg.header.stamp)
print("finished")
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)