ROS1 20.04 noetic
机器人:NXRobo SPARK-T
安装cartographer请看:
【安装学习】安装Cartographer ROS(noetic)_Howe_xixi的博客-CSDN博客网上使用noetic安装cartographer的比较少,所以将安装步骤记录下来https://blog.csdn.net/weixin_44362628/article/details/122540297?spm=1001.2014.3001.5501虚拟环境下的2D SLAM请看:
【踩坑记录】仿真环境使用小车进行Cartographer 2D Slam&关于多工作空间下source的使用_Howe_xixi的博客-CSDN博客仿真用小车跑cartographer&多工作空间的连通使用https://blog.csdn.net/weixin_44362628/article/details/122564089?spm=1001.2014.3001.5501
【Cartographer配置】 【修改lua文件】
cartographer_ros配置文件.lua文件路径位于cartographer_ros/configuration_files中,选择其中的revo_lds.lua文件复制修改,取新名字为spark_cartographer_lidar.lua,内容如下
-- Copyright 2016 The Cartographer Authors
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR ConDITIONS OF ANY KIND, either express or
implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
include "map_builder.lua"
include "trajectory_builder.lua"
options = {
map_builder = MAP_BUILDER,
trajectory_builder = TRAJECTORY_BUILDER,
map_frame = "map",
tracking_frame = "base_link",
published_frame = "odom",
odom_frame = "odom",
provide_odom_frame = false,
publish_frame_projected_to_2d = true,
use_pose_extrapolator = true,
use_odometry = true,
use_nav_sat = false,
use_landmarks = false,
num_laser_scans = 1,
num_multi_echo_laser_scans = 0,
num_subdivisions_per_laser_scan = 1,
num_point_clouds = 0,
lookup_transform_timeout_sec = 0.2,
submap_publish_period_sec = 0.3,
pose_publish_period_sec = 5e-3,
trajectory_publish_period_sec = 30e-3,
rangefinder_sampling_ratio = 1.,
odometry_sampling_ratio = 1.,
fixed_frame_pose_sampling_ratio = 1.,
imu_sampling_ratio = 1.,
landmarks_sampling_ratio = 1.,
}
MAP_BUILDER.use_trajectory_builder_2d = true
TRAJECTORY_BUILDER_2D.submaps.num_range_data = 35
TRAJECTORY_BUILDER_2D.min_range = 0.3
TRAJECTORY_BUILDER_2D.max_range = 8.
TRAJECTORY_BUILDER_2D.missing_data_ray_length = 1.
TRAJECTORY_BUILDER_2D.use_imu_data = false
TRAJECTORY_BUILDER_2D.use_online_correlative_scan_matching = true
TRAJECTORY_BUILDER_2D.real_time_correlative_scan_matcher.linear_sear
ch_window = 0.1
TRAJECTORY_BUILDER_2D.real_time_correlative_scan_matcher.translation_
delta_cost_weight = 10.
TRAJECTORY_BUILDER_2D.real_time_correlative_scan_matcher.rotation_del
ta_cost_we
修改了原文件tracking_frame和published_frame参数的值,和使用的机器人匹配
*其他参数值含义可参考官网,链接见以下链接
Cartographer ROS Integration
【修改launch文件】cartographer_ros的launch文件demo_revo_lds.launch(使用的激光雷达较为相似)路径位于/cartographer_ros/launch中,选择并进行复制修改,取新名字spark_cartographer.launch,内容如下:
该launch文件包含四部分:
1.启动cartographer_node节点,配置文件指向刚刚设置的.lua文件,同时映射scan,imu,odom对应的话题
2.启动cartographer_occupancy_grid_node地图格式转换节点,由于cartographer_node建图节点提供的地图是submapList格式的,需要转换成GridMap格式才能在ROS中显示和使用。这里面有两个可配参数,resolution用来设置GridMap地图的分辨率,publish_period_sec用来设置GridMap地图发布的频率。
3.启动Rviz,启动成功后,再根据需求保存配置即可
【重新编译】通过Lua脚本配置参数的方法,每次修改参数后需要重新编译,否则参数无法生效
catkin_make_isolated --install --use-ninja
【SPARK配置】 【启动文件】
新建move.launch,主要包含启动spark的各种驱动(底盘,雷达,相机),放置在sparl_noetic/src/spark/spark_teleop/launch中
【运行Cartographer】 【启动spark】
source devel_isolated/setup.bash roslaunch spark_teleop move.launch【启动Cartographer】
source devel_isolated/setup.bash roslaunch cartographer_ros spark_cartographer.launch
建图效果:
【保存地图】 【生成pbstream地图】
rosservice call /write_state "{filename: '/home/spark/map/map1.pbstream'}"
【pbstream转换】
rosrun cartographer_ros cartographer_pbstream_to_ros_map -map_filestem=/home/spark/map/map1 -pbstream_filename=/home/spark/map/map1.pbstream -resolution=0.05
最终效果:
导航时可以使用map1.yaml文件进行全局规划
感想
cartographer ros使用指南-保存地图 - 创客智造



