梦应逍遥 发表于 2025-3-21 18:16:51

使用cartographer扩展舆图

阐明

重要是使用cartographer在已有舆图的基础上扩展未知地区舆图,避免对已有舆图重复建图
1. 加载已有舆图

首先要在定位模式下加载已有舆图
启动launch文件
<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. 竣事当前轨迹

须要竣事定位产生的轨迹
source install_isolated/setup.bash
rosservice call /finish_trajectory 1
3. 开启新的轨迹

通过调用cartographer服务开启新的轨迹
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. 保存舆图

当对未知舆图完成扫描后保存舆图
#!/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, 在定位模式下,竣事当前轨迹时,会删除当前轨迹,导致在转换舆图时出现
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: ***
    @   0x7a369d2e90cdgoogle::LogMessage::Fail()
    @   0x7a369d2eaf33google::LogMessage::SendToLog()
    @   0x7a369d2e8c28google::LogMessage::Flush()
    @   0x7a369d2eb999google::LogMessageFatal::~LogMessageFatal()
    @   0x6503b3f07528(unknown)
    @   0x6503b3ef915a(unknown)
    @   0x6503b3ef7968(unknown)
    @   0x7a369ba21c87__libc_start_main
    @   0x6503b3ef901a(unknown)
因此须要在代码中对删除的操纵举行特殊处理

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页: [1]
查看完整版本: 使用cartographer扩展舆图