0开始配置Cartographer建图和导航定位

0开始配置Cartographer

日期:12-19

硬件:激光雷达+IMU

小车的tf变换:

建图配置

lua文件配置:my_robot.lua

lua 复制代码
include "map_builder.lua"
include "trajectory_builder.lua"

options = {
  map_builder = MAP_BUILDER,
  trajectory_builder = TRAJECTORY_BUILDER,
  map_frame = "map",
  tracking_frame = "imu_link",
  published_frame = "base_link",
  odom_frame = "odom",
  provide_odom_frame = true,
  publish_frame_projected_to_2d = true,
  use_pose_extrapolator = false,
  use_odometry = false,
  use_nav_sat = false,
  use_landmarks = false,
  num_laser_scans = 1,
  num_multi_echo_laser_scans = 0,
  num_subdivisions_per_laser_scan = 10,
  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.num_accumulated_range_data = 10

return options

launch配置:my_robot_map.launch

xml 复制代码
<launch>
  <!-- <param name="robot_description"
    textfile="$(find cartographer_ros)/urdf/my_robot_2d.urdf" />

  <node name="robot_state_publisher" pkg="robot_state_publisher"
    type="robot_state_publisher" /> -->

  <node name="cartographer_node" pkg="cartographer_ros"
      type="cartographer_node" args="
          -configuration_directory $(find cartographer_ros)/configuration_files
          -configuration_basename my_robot.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>

源码修改

文件路径:/home/hgrobot/cartographer_ws/src/cartographer_ros/cartographer_ros/cartographer_ros/occupancy_grid_node_main.cc

建图需要取消注释

  // 注释不发送地图
  // occupancy_grid_publisher_.publish(*msg_ptr);

重新编译

catkin_make_isolated --install --use-ninja

source环境

catkin_make_isolated --install --use-ninja

运行并建图

启动底盘和imu:

roslaunch castlex_plus_bringup castlex_plus_bringup.launch

启动雷达:

roslaunch wj_716_lidar wj.launch

启动建图:

roslaunch cartographer_ros my_robot_map.launch

启动键盘控制:

roslaunch castlex_keyboard_control keyboard_control.launch

停止接收地图数据:

rosservice call /finish_trajectory 0

保存地图:

rosservice call /write_state "{filename: '/home/hgrobot/cartographer_ws/src/cartographer_ros/cartographer_ros/map/map.pbstream'}"

将地图转成png:

rosrun cartographer_ros cartographer_pbstream_to_ros_map -map_filestem=/home/hgrobot/ws/src/castlex_navigation/maps/map -pbstream_filename=/home/hgrobot/cartographer_ws/src/cartographer_ros/cartographer_ros/map/map.pbstream -resolution=0.05

导航配置

源码修改:

文件路径:/home/hgrobot/cartographer_ws/src/cartographer_ros/cartographer_ros/cartographer_ros/occupancy_grid_node_main.cc

导航需要注释

  // 注释不发送地图
  // occupancy_grid_publisher_.publish(*msg_ptr);

launch配置:my_robot_2d_localization.launch

xml 复制代码
<launch>
  <arg name="load_state_filename" default="/home/hgrobot/cartographer_ws/src/cartographer_ros/cartographer_ros/map/map.pbstream"/>

  <node name="cartographer_node" pkg="cartographer_ros"
      type="cartographer_node" args="
          -configuration_directory $(find cartographer_ros)/configuration_files
          -configuration_basename my_robot_location.lua
          -load_state_filename $(arg load_state_filename)"
      output="screen">
    <remap from="scan" to="scan" />
    <remap from="imu" to="imu" />
  </node>

  <node name="cartographer_occupancy_grid_node" pkg="cartographer_ros"
      type="cartographer_occupancy_grid_node" args="-resolution 0.05 " />  <!-- 增加是否纯定位模式参数pure_localization -->

</launch>

lua文件配置:

lua 复制代码
include "my_robot.lua"

TRAJECTORY_BUILDER.pure_localization_trimmer = {
    max_submaps_to_keep = 3,
  }
  POSE_GRAPH.optimize_every_n_nodes =100

return options

启动底盘和imu:

roslaunch castlex_plus_bringup castlex_plus_bringup.launch

启动雷达:

roslaunch wj_716_lidar wj.launch

启动定位:

注意小车启动位置要和开始位置一样

roslaunch cartographer_ros my_robot_2d_localization.launch

启动导航:

roslaunch castlex_navigation teb_nav.launch

遇到的问题:

编译错误---解决方法:删除build,重新编译

小车跳变---tf有问题,小车底盘发布的是odom-base_footprint的tf变换,没有发布base_footprint-base_link的变换,move_base设置的是base_link,map,odom。使用的是teb算法。

存在问题:

1.建图和定位切换需要修改源码

2.不能自动重定位

相关推荐
古月居GYH31 分钟前
ROS一键安装脚本
人工智能·机器人·ros
DeepAlchemy1 小时前
ROSSERIAL与Arduino IDE交叉开发(UBUNTU环境,包含ESP32、arduino nano)
c++·单片机·ros·rosserial
Mr.Winter`3 天前
轨迹优化 | 基于Savitzky-Golay滤波的无约束路径平滑(附ROS C++/Python仿真)
人工智能·算法·机器人·自动驾驶·ros·ros2·数值优化
huanggang9825 天前
在Ubuntu22.04上源码构建ROS noetic环境
ros·ubuntu 22.04
找不着地窖的皮险家6 天前
ROS Action
c++·机器人·ros
Code-world-111 天前
Ubuntu 的 ROS 操作系统安装与测试
linux·ubuntu·ros·noetic ninjemy
饮啦冰美式14 天前
ROS2humble版本使用colcon构建包
ros
knighthood200114 天前
解决:ros进行gazebo仿真,rviz没有显示传感器数据
c++·ubuntu·ros
knighthood200116 天前
ros中仿真编写launch时robot_state_publisher,output参数
c++·ubuntu·ros
Mr.Winter`17 天前
路径规划 | ROS中多个路径规划算法可视化与性能对比分析
人工智能·算法·机器人·自动驾驶·ros·ros2·路径规划