Karto跑下载的数据集
程序员文章站
2024-03-25 09:13:52
...
Karto 安装跑数据集
安装前首先在home下建立karto文件夹,建立src文件夹
返回到karto中在终端输入 catkin_make
输入 gedit ~/.bashrc
在文件中添加 source ~/karto/devel/setup.bash
在 export ROS_PACKAGE_PATH 中添加 /home/lisiman/karto/src 点击保存 然后返回到karto 在终端输入catkin_make
进行以下步骤
1.安装
cd karto/src
git clone https://github.com/ros-perception/open_karto.git
git clone https://github.com/ros-perception/slam_karto.git
cd ..
catkin_make
然后在两个终端分别输入
```cpp
roscore
rosrun slam_karto slam_karto
2.数据集下载及转换
查看Python版本指令
python2 --version #查看python2安装版本
python3 --version #查看python3安装版本
数据集链接
点进去之后download log file,然后全选复制,建一个文档 如data.clf,存之.注意是.clf.
注意! 这里复制的数据不能有空行,否则转换会出错。
转换格式
1、在你slam_karto下创建一个script文件夹,与launch文件夹同级目录.
2、把下面代码创建成一个.py文件如convert.py,然后放到script中.
3、因为他要用到ros库所以必须保存到某个parkage的script中.
4、cd这个script下,然后python convert.py path/data.clf path/data.bag 转化成功.(注意这里的path路径为自己具体的路径)
以下为py文件夹内容
#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.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(0)) #我修改了这
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)
3、跑数剧集
运行以下指令
roscore
rosrun slam_karto slam_karto
rosbag play data.bag
rosrun rviz rviz
上一篇: 对数据的归一化