gazebo仿真环境下cartographer应用建图(融合odom和scan)

发布时间:2026/7/29 16:13:43
gazebo仿真环境下cartographer应用建图(融合odom和scan) 一、环境说明ros1 noetic版本仿真环境为turtlebot3_house.world下图为笔者自己搭建的丑陋小车二、配置2.1、文章参考可以参考笔者上篇文章快速配置。链接:Turtlebot3gazebo仿真cartographer建图踩坑经验分享2.2、.lua 代码my_car/config/turtlebot3_lds_2d_gazebo.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.includemap_builder.luaincludetrajectory_builder.luaoptions{map_builderMAP_BUILDER,trajectory_builderTRAJECTORY_BUILDER,map_framemap,tracking_framebase_footprint,-- imu_link, If you are using gazebo, use base_footprint (libgazebo_ros_imus bug)published_frameodom,odom_frameodom,provide_odom_framefalse,publish_frame_projected_to_2dfalse,use_odometrytrue,use_nav_satfalse,use_landmarksfalse,num_laser_scans1,num_multi_echo_laser_scans0,num_subdivisions_per_laser_scan1,num_point_clouds0,lookup_transform_timeout_sec0.2,submap_publish_period_sec0.3,pose_publish_period_sec5e-3,trajectory_publish_period_sec30e-3,rangefinder_sampling_ratio1.,odometry_sampling_ratio1.,fixed_frame_pose_sampling_ratio1.,imu_sampling_ratio1.,landmarks_sampling_ratio1.,}MAP_BUILDER.use_trajectory_builder_2dtrueTRAJECTORY_BUILDER_2D.min_range0.1TRAJECTORY_BUILDER_2D.max_range3.5TRAJECTORY_BUILDER_2D.missing_data_ray_length3.TRAJECTORY_BUILDER_2D.use_imu_datafalse#笔者只改了这里把imu关掉 TRAJECTORY_BUILDER_2D.use_online_correlative_scan_matchingtrueTRAJECTORY_BUILDER_2D.motion_filter.max_angle_radiansmath.rad(0.1)POSE_GRAPH.constraint_builder.min_score0.65POSE_GRAPH.constraint_builder.global_localization_min_score0.7returnoptions注意笔者这部分的代码是直接复制的turtlebot3/turtlebot3_slam/config/turtlebot3_lds_2d_gazebo.lua只把imu关掉了如上代码的中文注释部分为什么要把imu关掉呢turtlebot3官方建图融合的是odom、scan、imu但是turtlebot3的launch文件里多启动了一个turtlebot3/turtlebot3_slam/src/flat_world_imu_node.cpp节点这个节点大家可以自行研究不启动这个节点建图就会报错笔者目前能力有限暂时调过这个节点把imu关掉只融合odom和scan2.3、launch代码启动次文件前需要启动你的gazebo环境并检查tf链是否正确文件my_car/launch/new_cartographer.launch代码如下launchargnameconfiguration_basenamedefaultturtlebot3_lds_2d_gazebo.lua/!-- cartographer_node --nodepkgcartographer_rostypecartographer_nodenamecartographer_nodeargs-configuration_directory $(find my_car)/config -configuration_basename $(arg configuration_basename)outputscreen/node!-- cartographer_occupancy_grid_node --nodepkgcartographer_rostypecartographer_occupancy_grid_nodenamecartographer_occupancy_grid_nodeargs-resolution 0.05//launchrviz需在单独在一终端另行启动2.4、启动通用键盘控制节点rosrun teleop_twist_keyboard teleop_twist_keyboard.py当然如果你对move_base足够熟练可以用move_base需自行添加这样建图只需要简单鼠标点几下就可以了三、建图结果如下