【运行背景】
ROS1 20.04 noetic
机器人:NXRobo SPARK-T
安装cartographer请看:
【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参数的值,和使用的机器人匹配
*其他参数值含义可参考官网,链接见以下链接
【修改launch文件】
cartographer_ros的launch文件demo_revo_lds.launch(使用的激光雷达较为相似)路径位于/cartographer_ros/launch中,选择并进行复制修改,取新名字spark_cartographer.launch,内容如下:
<launch>
<param name="/use_sim_time" value="false" />
<node name="cartographer_node" pkg="cartographer_ros"
type="cartographer_node" args="
-configuration_directory $(find cartographer_ros)/configuration_files
-configuration_basename spark_cartographer_lidar.lua"
output="screen">
<remap from="scan" to="scan"/>
<remap from="imu" to="imu"/>
<remap from="odom" to="odom"/>
</node>
<node name="cartographer_occupancy_grid_node" pkg="cartographer_ros"
type="cartographer_occupancy_grid_node" args="-resolution 0.05" />
<node name="rviz" pkg="rviz" type="rviz" required="true"
args="-d $(find cartographer_ros)/configuration_files/demo_2d.rviz" />
</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中
<!--让SPARK跑起来-->
<launch>
<!-- 启动哪种摄像机 -->
<arg name="camera_type_tel" default="astrapro" doc="camera type [astrapro, astra, d435...]"/>
<arg name="lidar_type_tel" default="3iroboticslidar2" doc="lidar type [3iroboticslidar2, ydlidar_g2]"/>
<!--spark底盘驱动,机器人描述,底盘,相机-->
<include file="$(find spark_bringup)/launch/driver_bringup.launch">
<arg name="camera_types" value="$(arg camera_type_tel)"/>
<arg name="lidar_type_tel" value="$(arg lidar_type_tel)"/>
</include>
<!-- 启动雷达 -->
<include file="$(find lidar_driver_transfer)/launch/$(arg lidar_type_tel).launch">
</include>
<!--创建新的终端,spark键盘控制 “wsad”分别代表“前后左右”-->
<node pkg="spark_teleop" type="keyboard_control.sh" name="kc" />
</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文件进行全局规划
感想