使用cartographer扩展地图

说明

主要是使用cartographer在已有地图的基础上扩展未知区域地图,避免对已有地图重复建图

1. 加载已有地图

首先要在定位模式下加载已有地图

启动launch文件

bash 复制代码
<launch>
    <arg name = "configuration_directory" default = "/work/slam/script"/>
  <arg name = "configuration_basename" default = "expand_map.lua"/>
  <arg name = "load_state_filename" default = "/work/slam/maps/map.pbstream"/>
  <arg name="load_frozen_state" default="true"/>
 
  <node name="cartographer_node" pkg="cartographer_ros"
      type="cartographer_node" args="
          -configuration_directory $(arg configuration_directory)
          -configuration_basename $(arg configuration_basename)
          -load_state_filename $(arg load_state_filename)
          -load_frozen_state $(arg load_frozen_state)"
      output="screen">
  </node>
  <node name="rviz" pkg="rviz" type="rviz" required="true"  
        args="-d /work/slam/script/demo_2d.rviz" />
  </launch> 

2. 结束当前轨迹

需要结束定位产生的轨迹

bash 复制代码
source install_isolated/setup.bash
rosservice call /finish_trajectory 1

3. 开启新的轨迹

通过调用cartographer服务开启新的轨迹

bash 复制代码
rosservice call /start_trajectory "configuration_directory: '/work/slam/script'
configuration_basename: 'expand_map.lua'
use_initial_pose: true     
initial_pose:
  position: {x: -0.0551091, y: -0.939531, z: 0.0}
  orientation: {x: 0.0, y: 0.0, z: -0.00436956, w: 0.999996}
relative_to_trajectory_id: 0" 

4. 保存地图

当对未知地图完成扫描后保存地图

bash 复制代码
#!/bin/bash
source install_isolated/setup.bash

# Call the ROS service and save the output to a variable
response=$(rosservice call /get_trajectory_states "{}")

# Extract the trajectory_id array from the response
trajectory_ids=$(echo "$response" | awk -F'trajectory_id: ' '{print $2}' | awk -F']' '{print $1}')

# Extract the last element from the trajectory_id array
last_element=$(echo "$trajectory_ids" | awk -F', ' '{print $NF}')

# Print the last element
echo "Last element of trajectory_id: $last_element"

rosservice call /finish_trajectory $last_element

rosservice call /write_state "{filename: '/work/slam/map/map.pbstream'}"

注意

1, 由于在定位阶段加载了lua参数,新建轨迹时如果参数不同,不会生效;

2, 在定位模式下,结束当前轨迹时,会删除当前轨迹,导致在转换地图时出现

bash 复制代码
F0317 08:40:01.665091 111541 proto_stream_deserializer.cc:70] Check failed: pose_graph_.pose_graph().trajectory_size() == all_trajectory_builder_options_.all_trajectory_builder_options() .options_with_sensor_ids_size() (2 vs. 1) 
*** Check failure stack trace: ***
    @     0x7a369d2e90cd  google::LogMessage::Fail()
    @     0x7a369d2eaf33  google::LogMessage::SendToLog()
    @     0x7a369d2e8c28  google::LogMessage::Flush()
    @     0x7a369d2eb999  google::LogMessageFatal::~LogMessageFatal()
    @     0x6503b3f07528  (unknown)
    @     0x6503b3ef915a  (unknown)
    @     0x6503b3ef7968  (unknown)
    @     0x7a369ba21c87  __libc_start_main
    @     0x6503b3ef901a  (unknown)

因此需要在代码中对删除的操作进行特别处理

相关推荐
whyTeaFo21 小时前
MIT 6.1810: xv6 book Chapter6: Interrupts and device drivers 笔记
笔记
weixin_4280053021 小时前
C#调用 AI学习从0开始-第2阶段(Function Calling+工具调用智能体)-第9天实战
人工智能·学习·ai·c#·functioncalling
SNSZR121 小时前
2026 AI实操五大学习思路:破解碎片化自学无法落地商用项目的核心痛点
人工智能·学习
落地加湿器21 小时前
从Hermes cli的源代码中学习skill
人工智能·python·学习·智能体·源码解读
MartinYeung521 小时前
[论文学习]人工智慧启用系统的隐私增强技术:威胁分析、PETs 应用框架
学习·威胁分析
浩风祭月21 小时前
Coding-Interview-University 学习路径实测与效能评估
学习
惜年_night21 小时前
Go语言学习-04结构体/自定义类型/接口
学习
3DVisionary21 小时前
高温下钢管如何测应变?数字散斑DIC高温压缩测试方案
数码相机·学习·全场应变测量·实验力学·数字散斑dic·高温材料测试·钢管轴向压缩
map1e_zjc21 小时前
Redis入门笔记(2)
数据库·redis·笔记
我想我不够好。21 小时前
消防监控学习 6.5 1.5hour
学习