流程和跑gmapping是类似的,只不过hector_slam不需要里程计数据,所以,只要数据集中有 /scan 和 /tf 就可以。
1 数据集预处理
这里我用slam benchmark 数据集,网址:
http://ais.informatik.uni-freiburg.de/slamevaluation/datasets.php
这个数据集非常小,里面真的是只有 /scan 和 /tf ,但是这个数据集的格式为.clf,需要把它转换成.bag文件才能在ros中使用。网上已经有人做了这件事情,那我就直接用了,python文件如下:
#!/usr/bin/env python
#coding=utf8
'''This is a converter for the Intel Research Lab SLAM dataset
( http://kaspar.informatik.uni-freiburg.de/~slamEvaluation/datasets/intel.clf )
to rosbag'''
import rospy
import rosbag
from sensor_msgs.msg import LaserScan
from nav_msgs.msg import Odometry
from math import pi
from tf2_msgs.msg import TFMessage
from geometry_msgs.msg import TransformStamped
import tf
import sys
def make_tf_msg(x, y, theta, t,base,base0):
trans = TransformStamped()
trans.header.stamp = t
trans.header.frame_id = base
trans.child_frame_id = base0
trans.transform.translation.x = x
trans.transform.translation.y = y
q = tf.transformations.quaternion_from_euler(0, 0, theta)
trans.transform.rotation.x = q[0]
trans.transform.rotation.y = q[1]
trans.transform.rotation.z = q[2]
trans.transform.rotation.w = q[3]
msg = TFMessage()
msg.transforms.append(trans)
return msg
if __name__ == "__main__":
if len(sys.argv) < 3:
print("请输入dataset文件名。")
exit()
print("正在处理" + sys.argv[1] + "...")
with open(sys.argv[1]) as dataset:
with rosbag.Bag(sys.argv[2], 'w') as bag:
i = 1
for line in dataset.readline