【踩坑记录】实体机器人运行Cartographer 2D Slam

【运行背景】

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>
  <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文件进行全局规划


感想

cartographer ros使用指南-保存地图 - 创客智造

  • 1
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 7
    评论
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值