自己记录一下学习cartographer过程
1.编译好cartographer,不能出现报错
catkin_make_isolated --install --use-ninja
source install_isolated/setup.bash
2.运行官方提供的数据包
# Launch the 2D backpack demo.
roslaunch cartographer_ros demo_backpack_2d.launch bag_filename:= 绝对目录/cartographer_paper_deutsches_museum.bag
# Launch the 3D backpack demo.
roslaunch cartographer_ros demo_backpack_3d.launch bag_filename:= 绝对目录/b3-2016-04-05-14-14-00.bag
播放时,开可以看到ros节点名称
/cartographer_node
/cartographer_occupancy_grid_node
/playbag
/robot_state_publisher
/rosout
/rviz
话题名
/initialpose /joint_states /move_base_simple/goal是没有用到的
查看 /tf_static
transforms:
-
header:
seq: 0
stamp:
secs: 1432647016
nsecs: 482139400
frame_id: "base_link"
child_frame_id: "horizontal_laser_link" 注释:垂直激光与base的静态变换
transform:
translation:
x: 0.1007
y: 0.0
z: 0.0558
rotation:
x: 0.0
y: 0.0
z: 0.0
w: 1.0
-
header:
seq: 0
stamp:
secs: 1432647016
nsecs: 482139400
frame_id: "base_link"
child_frame_id: "imu_link" 注释:IMU与base的静态变换
transform:
translation:
x: 0.0
y: 0.0
z: 0.0
rotation:
x: 0.0
y: 0.0
z: 0.0
w: 1.0
-
header:
seq: 0
stamp:
secs: 1432647016
nsecs: 482139400
frame_id: "base_link"
child_frame_id: "vertical_laser_link" 注释:水平激光与base的静态变换
transform:
translation:
x: 0.1007
y: 0.0
z: 0.1814
rotation:
x: 0.707106665647
y: 1.22474483074e-07
z: 0.707106896726
w: -1.22474523098e-07
查看动态TF,也提供了通常所说的map to odom, 以及odom to base;
/constraint_list
/submap_list
跑3D数据包
2D栅格地图的效果:
运行完之后,离线建图,保存3D地图 ,步骤如下:
先结束建图:通过ros的service 结束轨迹,轨迹可以理解为一次建图过程。
source install_isolated/setup.bash
rosservice call /finish_trajectory 0
- 序列化保存其当前状态:
rosservice call /write_state "{filename: '${HOME}/Downloads/b3-2016-04-05-14-14-00.bag.pbstream', include_unfinished_submaps: 'true'}"
若报错,ERROR: Unable to send request. One of the fields has an incorrect type: field include_unfinished_submaps is not a bool, 则改为:
rosservice call /write_state "{filename: '${HOME}/Downloads/b3-2016-04-05-14-14-00.bag.pbstream', include_unfinished_submaps: 1}"
(1)修改assets_writer_backpack_3d.lua
VOXEL_SIZE = 5e-2 --0.05
include "transform.lua"
options = {
tracking_frame = "base_link",
pipeline = {
{
action = "min_max_range_filter", --距离过滤器;主要成员min_range_、max_range_;
min_range = 1.,
max_range = 60.,
},
{
action = "dump_num_points", --记录输出处理的点数量;主要成员num_points;
},
{
action = "fixed_ratio_sampler",--采样过滤器,控制固定采样频率的点通过;主要成员sampling_ratio;
sampling_ratio = 0.001,
},
{
action = "intensity_to_color", --将光强转化为颜色;主要成员min_intensity_、max_intensity_、frame_id_;
min_intensity = 0.,
max_intensity = 4095.,
},
{
action = "write_pcd", --存储pcd格式点云;
filename = "points.pcd",
},
-- Gray X-Rays. These only use geometry to color pixels.
{
action = "write_xray_image", --存储切片透明图片;主要成员voxel_size;
voxel_size = VOXEL_SIZE,
filename = "xray_yz_all",
transform = YZ_TRANSFORM,
},
{
action = "write_xray_image",
voxel_size = VOXEL_SIZE,
filename = "xray_xy_all",
transform = XY_TRANSFORM,
},
{
action = "write_xray_image",
voxel_size = VOXEL_SIZE,
filename = "xray_xz_all",
transform = XZ_TRANSFORM,
},
-- Now we recolor our points by frame and write another batch of X-Rays. It
-- is visible in them what was seen by the horizontal and the vertical
-- laser.
{
action = "color_points", --根据frame_id给点云添加颜色;主要成员color、frame_id;
frame_id = "horizontal_vlp16_link",
color = { 255., 0., 0. },
},
{
action = "color_points",
frame_id = "vertical_vlp16_link",
color = { 0., 255., 0. },
},
{
action = "write_xray_image",
voxel_size = VOXEL_SIZE,
filename = "xray_yz_all_color",
transform = YZ_TRANSFORM,
},
{
action = "write_xray_image",
voxel_size = VOXEL_SIZE,
filename = "xray_xy_all_color",
transform = XY_TRANSFORM,
},
{
action = "write_xray_image",
voxel_size = VOXEL_SIZE,
filename = "xray_xz_all_color",
transform = XZ_TRANSFORM,
},
}
}
return options
修改.lua之后需要重新编译
通过assets_writer将pbstream信息写为三维地图
$ roslaunch cartographer_ros assets_writer_backpack_3d.launch bag_filenames:='${HOME}/Downloads/b3-2016-04-05-14-14-00.bag' pose_graph_filename:='${HOME}/Downloads/b3-2016-04-05-14-14-00.bag.pbstream'
离线等待一段时间,由包的数据大小确定
大约几分钟之后:
可以在包和pbstream的目录下看到有六张png地图。
经过此包得到的二维图
得到3维点云地图
2.同理,在跑二维数据集时,获取pbstream
通过以下命令则能够将pbstream转为map的pgm和yaml格式的地图
rosrun cartographer_ros cartographer_pbstream_to_ros_map -map_filestem=${HOME}/Downloads/b2-2016-04-05-14-44-52.bag -pbstream_filename=${HOME}/Downloads/b2-2016-04-05-14-44-52.bag.pbstream -resolution=0.05