当前位置:网站首页>ROS learning (XIX) robot slam function package cartographer

ROS learning (XIX) robot slam function package cartographer

2022-07-07 01:52:00 Ice cream with code


Preface

  cartographer The core is cartographer_node node , When running this node , Need one Lua Compiling .lua file , The main function of this file is to configure parameters , This is related to gmapping、hector stay launch The direct configuration parameters in the file are different .
  cartographer The highlight of is code standardization and engineering , Suitable for commercial application and secondary development , It can effectively avoid the interference of moving objects in the environment during the mapping process , Support multi-sensor data mapping , Support 2D-slam and 3D-slam Drawing .
   I customized a robot model before , Later in use cartographer In the process , It feels like something's wrong , But I can't solve this problem , I don't know if it's a configuration problem , still TF The problem of , ha-ha . So at the beginning of this article , Discard the previously customized robot model , Re customize a robot model , That is, use teacher Zhao's model , It is also convenient for follow-up kinect Use . Of the model xacro You can go to Baidu online , I will not introduce .

One 、cartographer_2d.launch file

launch The contents of the document are as follows :

<!-- 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. -->

<launch>
  <param name="/use_sim_time" value="true" />

  <node name="cartographer_node" pkg="cartographer_ros" type="cartographer_node" args=" -configuration_directory $(find robot_slam_cartographer)/configuration_files -configuration_basename rplidar.lua" output="screen">
    <remap from="scan" to="scan" />
    <param name="base_link" value="base_footprint"/>
  </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 robot_slam_cartographer)/config/default.rviz" />

</launch>

This document mainly includes two parts , First, operation cartographer_node node , Two is to start rviz Visual interface . When running cartographer_node Node time , Need to use a by lua Written code file rplidar.lua, Configure parameters ,lua The contents of the document will be introduced later .

Two 、mbot_sim_gazebo_navigation_world.launch file

launch The contents of the document are as follows :

<?xml version="1.0"?>
<launch>
  <include file="$(find gazebo_ros)/launch/empty_world.launch">
    <arg name="world_name" value="worlds/mbot_sim_gazebo_navigation.world"/> 
    <arg name="paused" value="false"/>
    <arg name="use_sim_time" value="true"/>
    <arg name="gui" value="true"/>
    <arg name="headless" value="false"/>
    <arg name="debug" value="false"/>
  </include>
</launch>

3、 ... and 、robot_gazebo_navigation.launch file

launch The contents of the document are as follows :

<?xml version="1.0"?>
<launch>
 	<!--  function gazebo Simulation environment  -->
    <include file="$(find gazebo_ros)/launch/mbot_sim_gazebo_navigation_world.launch">
    </include>

    <!-- Robot parameter settings -->
    <arg name="model" default="$(find xacro)/xacro --inorder '$(find robot_slam_cartographer)/urdf/xacro/robot.xacro'" />
     
    <!--robot_description  The parameter name is preset by the parameter server , Can't change -->
    <param name="robot_description" command="$(arg model)" />
    
    <!--  function joint_state_publisher node , Release the joint status of the robot  -->
    <node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher" />

    <!--  function robot_state_publisher node , Release tf -->
    <node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher" />

      <!--  stay gazebo Loading robot model in -->
    <node name="urdf_spawner" pkg="gazebo_ros" type="spawn_model" respawn="false" output="screen" args="-urdf -model mrobot -param robot_description"/> 

    <!--<node name="rviz" pkg="rviz" type="rviz" args="-d $(find mbot_slam_cartographer)/config/default.rviz"/>-->

    <!--gmapping  The package realizes synchronous positioning and map establishment  <node name="slam_gmapping" pkg="gmapping" type="slam_gmapping"> <remap from="scan" to="/scan"/> <param name="base_link" value="base_footprint"/> </node>-->

    <include file="$(find robot_slam_cartographer)/launch/cartographer_2d.launch"/>

</launch>

Four 、rplidar.lua file

The contents of the document are as follows :

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 = "base_link",
    odom_frame = "odom",
    provide_odom_frame = true,
    use_odometry = 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,


}

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_search_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_delta_cost_weight = 1e-1

SPARSE_POSE_GRAPH.optimization_problem.huber_scale = 1e2
SPARSE_POSE_GRAPH.optimize_every_n_scans = 35
SPARSE_POSE_GRAPH.constraint_builder.min_score = 0.65     

return options

5、 ... and 、 Compile operation

Every modification lua After the document , All need to be compiled , The order is as follows :

catkin_make_isolated --install --use-ninja

 Insert picture description here
function launch file , The order is as follows :

roslaunch robot_slam_cartographer robot_gazebo_navigation.launch

then , Then run the keyboard control startup file , The order is as follows :

rosrun teleop_twist_keyboard teleop_twist_keyboard.py

Last , The effect of drawing is as follows :
 Please add a picture description

6、 ... and 、 Save the map

Method 1、 Use map_saver Save directly as pgm and yaml file

Switch to map Catalog , newly build map_saver_map Folder , Execute the following command :

rosrun map_server map_saver -f myMapFile

Method 2、 Save it as .pbstream file , Convert to pgm and yaml file

Steps are as follows :

1、 Stop map building

rosservice call /finish_trajectory 0

2、 Generate .pbstream file

rosservice call /write_state "{filename: '${HOME}/catkin_google_ws/src/robot_slam_cartographer/map/carto_map.pbstream'}"

3、 take pbstream Turn into pgm and yaml file

rosrun cartographer_ros cartographer_pbstream_to_ros_map -map_filestem=${
    HOME}/catkin_google_ws/src/robot_slam_cartographer/map/myMapFile -pbstream_filename=${
    HOME}/catkin_google_ws/src/robot_slam_cartographer/map/carto_map.pbstream -resolution=0.05

The implementation effect is as follows :
 Insert picture description here
The location of the map in the function pack is as follows :
 Insert picture description here

原网站

版权声明
本文为[Ice cream with code]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207061812139269.html