参考网址

(144条消息) 2D激光slam数据集的下载与测试_快乐飞奔的小菜鸡的博客-CSDN博客_2d slam数据集

(144条消息) 二维激光雷达SLAM数据集_哈哈哈的嘎嘎嘎的博客-CSDN博客_二维激光雷达

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# convert.py
#!/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
import logging
logging.basicConfig()

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.readlines():
line = line.strip()
tokens = line.split(' ')
if len(tokens) <= 2:
continue
if tokens[0] == 'FLASER':
msg = LaserScan()
num_scans = int(tokens[1])

if num_scans != 180 or len(tokens) < num_scans + 9:
#rospy.logwarn("unsupported scan format")
continue

msg.header.frame_id = 'base_laser_link'
t = rospy.Time(float(tokens[(num_scans + 8)]))
msg.header.stamp = t
msg.header.seq = i
i += 1
msg.angle_min = -90.0 / 180.0 * pi
msg.angle_max = 90.0 / 180.0 * pi
msg.angle_increment = pi / num_scans
msg.time_increment = 0.2 / 360.0
msg.scan_time = 0.2
msg.range_min = 0.001
msg.range_max = 50.0
msg.ranges = [float(r) for r in tokens[2:(num_scans + 2)]]
msg.ranges.append(float('inf')) #我修改了这

bag.write('scan', msg, t)

odom_x, odom_y, odom_theta = [float(r) for r in tokens[(num_scans + 2):(num_scans + 5)]]
tf_msg = make_tf_msg(odom_x, odom_y, odom_theta, t,'odom','base_link')
bag.write('tf', tf_msg, t)

elif tokens[0] == 'ODOM':
odom_x, odom_y, odom_theta = [float(t) for t in tokens[1:4]]
t = rospy.Time(float(tokens[7]))
tf_msg = make_tf_msg(0, 0, 0, t,'base_link','base_laser_link')
bag.write('tf', tf_msg, t)


使用

1
2
cd script  //进入文件夹
python convert.py ../clf/ACES.clf ../clf/ACES.bag //可修改路径调整自己的文件位置