【踩坑记录】实体机器人运行Cartographer 3D Slam(深度摄像头)--未解决

本文档详述了在ROS Noetic上为NXRoboSPARK-T机器人安装和配置CartographerROS进行3D SLAM的过程。包括lua配置文件的修改,如坐标系设置、建图优化参数以及使用机器人odom的调整。同时,介绍了如何通过launch文件启动Cartographer,并分析了在遮挡摄像头时出现的问题及解决方案。
摘要由CSDN通过智能技术生成

【运行背景】

ROS1.0  20.04 noetic

机器人:NXRobo SPARK-T

安装cartographer请看:

【安装学习】安装Cartographer ROS(noetic)_Howe_xixi的博客-CSDN博客_noetic安装cartographer网上使用noetic安装cartographer的比较少,所以将安装步骤记录下来https://blog.csdn.net/weixin_44362628/article/details/122540297?spm=1001.2014.3001.5502虚拟环境下的3D SLAM请看:

【踩坑记录】仿真环境使用小车进行Cartographer 3D Slam(深度摄像头)_Howe_xixi的博客-CSDN博客仿真环境下采用深度摄像头运行cartographer 3D slamhttps://blog.csdn.net/weixin_44362628/article/details/122720861?spm=1001.2014.3001.5502


【踩坑记录1 Cartographer配置(使用cartographer提供的odom)】

cartographer_ros配置文件.lua文件路径位于cartographer_ros/configuration_files中,选择其中的revo_lds.lua文件复制修改,取新名字为spark_pointcloud.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 = "IMU_link", --实体选imu,仿真选base_footprint
  published_frame = "odom", --机器人底盘坐标系
  odom_frame = "carto_odom", -- cartographer发布的odom坐标系名
  provide_odom_frame = true, --是否使用cartographer提供的坐标系
  publish_frame_projected_to_2d = false, --是否使用纯2d姿态(去掉俯仰,偏航)
  use_pose_extrapolator = false, --是否使用姿势外推器
  use_odometry = false, --是否使用机器人odom
  use_nav_sat = false, --是否使用gps
  use_landmarks = false, --是否使用landmark数据
  num_laser_scans = 0, --激光雷达数量
  num_multi_echo_laser_scans = 0, --要订阅的多回波激光扫描主题的数量
  num_subdivisions_per_laser_scan = 1, --将激光雷达的数据拆分成几次发出来,对于普通的激光雷达,此处为1 
  num_point_clouds = 1, --点云数量
  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., --odom信息的固定比率采样。
  fixed_frame_pose_sampling_ratio = 1.,
  imu_sampling_ratio = 1.,
  landmarks_sampling_ratio = 1.,
}

TRAJECTORY_BUILDER_3D.num_accumulated_range_data = 1 --1帧数据拆分成几次发送
TRAJECTORY_BUILDER_3D.use_online_correlative_scan_matching = true --这个参数配置的是否使用 实时的闭环检测方法 来进行前端的扫描匹配。如果这项为false,则扫描匹配使用的是通过前一帧位置的先验,将当前scan与之前做对比,使用 高斯牛顿法 迭代 求解最小二乘问题 求得当前scan的坐标变换。如果这项为true,则使用闭环检测的方法,将当前scan在一定的搜索范围内搜索,范围为设定的平移距离及角度大小,然后在将scan插入到匹配的最优位置处。这种方式建图的效果非常好,即使建图有漂移也能够修正回去,但是这个方法的计算复杂度非常高,非常耗cpu。

MAP_BUILDER.use_trajectory_builder_3d = true --3d激光还是2d激光
MAP_BUILDER.num_background_threads = 8 --核数
POSE_GRAPH.optimization_problem.huber_scale = 1e2 
POSE_GRAPH.optimize_every_n_nodes = 10
POSE_GRAPH.constraint_builder.sampling_ratio = 0.1 --对应于约束的数量上限
POSE_GRAPH.optimization_problem.ceres_solver_options.max_num_iterations = 10
POSE_GRAPH.constraint_builder.min_score = 0.60 --成为约束的最低分数,这个值越大,计算速度相对越快,约束数量相对越少,在sampling_ratio较小的情况下,很可能会造成约束过少而导致建图失败,这个值越小,则效果相反,因此这个值可能需要多次调整;
POSE_GRAPH.constraint_builder.global_localization_min_score = 0.66
POSE_GRAPH.constraint_builder.fast_correlative_scan_matcher.linear_search_window=1.
POSE_GRAPH.constraint_builder.fast_correlative_scan_matcher.angular_search_window=math.rad(1.) --对应于闭环检测(约束检测)时的搜索范围



return options

需要注意修改的参数有以下几个:

1.TF坐标系:建图的坐标系转换应该按照,map-->odom-->tracking_frame,根据是否使用cartographer提供的odom坐标系而进行更改

a) 若使用提供的odom,参数修改如下,

b) tracking_frame 选择imu相关的link

2.建图优化:

a)TRAJECTORY_BUILDER_3D.use_online_correlative_scan_matching = true,若机子好可使用此参数配置

b)POSE_GRAPH.constraint_builder.sampling_ratio = 0.1 选择约束的数量上限 和POSE_GRAPH.constraint_builder.min_score = 0.60 成为约束的最低分数

此处参数调整感谢:

cartographer 参数理解_运动的肉肉子的博客-CSDN博客_cartographer参数

cartographer参数调整 - xjEzekiel - 博客园

cartographer探秘第一章之安装编译与参数配置_李想的博客-CSDN博客_install_abseil.sh

【修改launch文件】

cartographer_ros的launch文件backpack_3d.launch(使用的激光雷达较为相似)路径位于/cartographer_ros/launch中,选择并进行复制修改,取新名字spark_cartographer_3d.launch,内容如下:

<?xml version="1.0"?>
<launch>
  
  <param name="/use_sim_time" value="false" />
  
  <node name="rviz" pkg="rviz" type="rviz" required="true"
      args="-d $(find cartographer_ros)/configuration_files/demo_3d.rviz" />
      
  <node name="cartographer_node" pkg="cartographer_ros"
      type="cartographer_node" args="
          -configuration_directory $(find cartographer_ros)/configuration_files
          -configuration_basename spark_pointcloud.lua"
      output="screen">
    <remap from="/points2" to="/camera/depth_registered/points" />
    <remap from="imu" to="/imu_data" />
    <remap from="odom" to="/odom" />
    
  </node>

  <node name="cartographer_occupancy_grid_node" pkg="cartographer_ros"
        type="cartographer_occupancy_grid_node" args="-resolution 0.05" />

</launch>

该launch文件包含四部分:

    1.启动cartographer_node节点,配置文件指向刚刚设置的.lua文件,同时映射points2,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

【运行Cartographer】

首先启动机器人运行节点

source devel_isolated/setup.bash
roslaunch spark_teleop move.launch

详细内容,感兴趣的同学可以看【踩坑记录】实体机器人运行Cartographer 2D Slam_Howe_xixi的博客-CSDN博客

接着启动cartographer,就是刚刚我们编写的spark_cartographer_3d.launch

source devel_isolated/setup.bash
roslaunch cartographer_ros spark_cartographer_3d.launch 

运行效果分为两种情况:

1)用物品遮挡摄像头

odom乱飞

 即使选择不采用机器人的odom坐标系,在TF树上还是能看到有odom存在

 出现问题:

建图速度缓慢,点云更新卡顿,导致无法生成地图,采用rqt_tf_tree查看tf树,map的坐标也不存在了

警告信息:

 


【踩坑记录2 Cartographer配置(使用机器人提供的odom)】

【修改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 = "IMU_link", --实体选imu,仿真选base_footprint
  published_frame = "odom", --机器人底盘坐标系
  odom_frame = "carto_odom", -- cartographer发布的odom坐标系名
  provide_odom_frame = false, --是否使用cartographer提供的坐标系
  publish_frame_projected_to_2d = true, --是否使用纯2d姿态(去掉俯仰,偏航)
  use_pose_extrapolator = false, --是否使用姿势外推器
  use_odometry = true, --是否使用机器人odom
  use_nav_sat = false, --是否使用gps
  use_landmarks = false, --是否使用landmark数据
  num_laser_scans = 0, --激光雷达数量
  num_multi_echo_laser_scans = 0, --要订阅的多回波激光扫描主题的数量
  num_subdivisions_per_laser_scan = 1, --将激光雷达的数据拆分成几次发出来,对于普通的激光雷达,此处为1 
  num_point_clouds = 1, --点云数量
  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., --odom信息的固定比率采样。
  fixed_frame_pose_sampling_ratio = 1.,
  imu_sampling_ratio = 1.,
  landmarks_sampling_ratio = 1.,
}

TRAJECTORY_BUILDER_3D.num_accumulated_range_data = 1 --1帧数据拆分成几次发送
TRAJECTORY_BUILDER_3D.use_online_correlative_scan_matching = true --这个参数配置的是否使用 实时的闭环检测方法 来进行前端的扫描匹配。如果这项为false,则扫描匹配使用的是通过前一帧位置的先验,将当前scan与之前做对比,使用 高斯牛顿法 迭代 求解最小二乘问题 求得当前scan的坐标变换。如果这项为true,则使用闭环检测的方法,将当前scan在一定的搜索范围内搜索,范围为设定的平移距离及角度大小,然后在将scan插入到匹配的最优位置处。这种方式建图的效果非常好,即使建图有漂移也能够修正回去,但是这个方法的计算复杂度非常高,非常耗cpu。

MAP_BUILDER.use_trajectory_builder_3d = true --3d激光还是2d激光
MAP_BUILDER.num_background_threads = 8 --核数
POSE_GRAPH.optimization_problem.huber_scale = 1e2 
POSE_GRAPH.optimize_every_n_nodes = 10
POSE_GRAPH.constraint_builder.sampling_ratio = 0.1 --对应于约束的数量上限
POSE_GRAPH.optimization_problem.ceres_solver_options.max_num_iterations = 10
POSE_GRAPH.constraint_builder.min_score = 0.60 --成为约束的最低分数,这个值越大,计算速度相对越快,约束数量相对越少,在sampling_ratio较小的情况下,很可能会造成约束过少而导致建图失败,这个值越小,则效果相反,因此这个值可能需要多次调整;
POSE_GRAPH.constraint_builder.global_localization_min_score = 0.66
POSE_GRAPH.constraint_builder.fast_correlative_scan_matcher.linear_search_window=1.
POSE_GRAPH.constraint_builder.fast_correlative_scan_matcher.angular_search_window=math.rad(20.) --对应于闭环检测(约束检测)时的搜索范围



return options

 与之前对比,主要修改的参数:

provide_odom_frame = false,use_odometry = true

【重新编译】

catkin_make_isolated --install --use-ninja

【运行cartographer】

启动步骤与上文一致,就不赘述了,运行效果

启动rqt_tf_tree查看

当运行前挡住摄像头的时候

 当把遮挡的物体去掉后,查看tf树

警告信息

 

 

       

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值