本文讲述使用cartographer进行数据回放和参数调优的过程,属于官方文档的阅读笔记,加入了部分自己的理解。
wget -P ~/Downloads https://storage.googleapis.com/cartographer-public-data/bags/backpack_2d/cartographer_paper_deutsches_museum.bag
roslaunch cartographer_ros demo_backpack_2d.launch bag_filename:=${HOME}/Downloads/cartographer_paper_deutsches_museum.bag
以下操作在机器人的ros系统上运行:
roscore
roslaunch your_lidar_package your_lidar_package.launch
rosbag record -O my_robot.bag your_scan_topic_name
从此处开始,以下全部操作可以都在开发电脑上运行。
首先,验证rosbag数据包,确认没有问题:
cartographer_rosbag_validate -bag_filename my_robot.bag
cp install_isolated/share/cartographer_ros/configuration_files/backpack_2d.lua install_isolated/share/cartographer_ros/configuration_files/my_robot.lua
cp install_isolated/share/cartographer_ros/urdf/backpack_2d.urdf install_isolated/share/cartographer_ros/urdf/my_robot.urdf
cp install_isolated/share/cartographer_ros/launch/backpack_2d.launch install_isolated/share/cartographer_ros/launch/my_robot.launch
cp install_isolated/share/cartographer_ros/launch/demo_backpack_2d.launch install_isolated/share/cartographer_ros/launch/demo_my_robot.launch
cp install_isolated/share/cartographer_ros/launch/offline_backpack_2d.launch install_isolated/share/cartographer_ros/launch/offline_my_robot.launch
cp install_isolated/share/cartographer_ros/launch/demo_backpack_2d_localization.launch install_isolated/share/cartographer_ros/launch/demo_my_robot_localization.launch
cp install_isolated/share/cartographer_ros/launch/assets_writer_backpack_2d.launch install_isolated/share/cartographer_ros/launch/assets_writer_my_robot.launch
roslaunch cartographer_ros demo_my_robot.launch bag_filename:=/path/to/your_bag.bag
Cartographer可以被视为如下两个独立但相关的子系统:
根据使用的激光雷达型号的不同,进行不同的参数配置。
TRAJECTORY_BUILDER_nD.min_range
TRAJECTORY_BUILDER_nD.max_range
TRAJECTORY_BUILDER_nD.num_accumulated_range_data
TRAJECTORY_BUILDER_nD.voxel_filter_size
TRAJECTORY_BUILDER_nD.*adaptive_voxel_filter.max_length
TRAJECTORY_BUILDER_nD.*adaptive_voxel_filter.min_num_points
TRAJECTORY_BUILDER_2D.use_imu_data
TRAJECTORY_BUILDER_nD.imu_gravity_time_constant
Local SLAM的过程包括两部分:
扫描匹配(Scan Match)有两种方式:
TRAJECTORY_BUILDER_2D.ceres_scan_matcher.occupied_space_weight
TRAJECTORY_BUILDER_3D.ceres_scan_matcher.occupied_space_weight_0
TRAJECTORY_BUILDER_3D.ceres_scan_matcher.occupied_space_weight_1
TRAJECTORY_BUILDER_nD.ceres_scan_matcher.translation_weight
TRAJECTORY_BUILDER_nD.ceres_scan_matcher.rotation_weight
TRAJECTORY_BUILDER_nD.ceres_scan_matcher.ceres_solver_options.use_nonmonotonic_steps
TRAJECTORY_BUILDER_nD.ceres_scan_matcher.ceres_solver_options.max_num_iterations
TRAJECTORY_BUILDER_nD.ceres_scan_matcher.ceres_solver_options.num_threads
当没有其他传感器,纯用激光雷达进行SLAM计算时,需要使用RealTimeCorrelative ScanMatcher来进行初始位置的估计。
TRAJECTORY_BUILDER_nD.use_online_correlative_scan_matching
TRAJECTORY_BUILDER_nD.real_time_correlative_scan_matcher.linear_search_window
TRAJECTORY_BUILDER_nD.real_time_correlative_scan_matcher.angular_search_window
TRAJECTORY_BUILDER_nD.real_time_correlative_scan_matcher.translation_delta_cost_weight
TRAJECTORY_BUILDER_nD.real_time_correlative_scan_matcher.rotation_delta_cost_weight
TRAJECTORY_BUILDER_nD.motion_filter.max_time_seconds
TRAJECTORY_BUILDER_nD.motion_filter.max_distance_meters
TRAJECTORY_BUILDER_nD.motion_filter.max_angle_radians
TRAJECTORY_BUILDER_nD.submaps.num_range_data
TRAJECTORY_BUILDER_2D.submaps.grid_options_2d.grid_type
TRAJECTORY_BUILDER_2D.submaps.range_data_inserter.probability_grid_range_data_inserter.hit_probability
TRAJECTORY_BUILDER_2D.submaps.range_data_inserter.probability_grid_range_data_inserter.miss_probability
TRAJECTORY_BUILDER_3D.submaps.range_data_inserter.hit_probability
TRAJECTORY_BUILDER_3D.submaps.range_data_inserter.miss_probability
TRAJECTORY_BUILDER_2D.submaps.grid_options_2d.resolution
TRAJECTORY_BUILDER_3D.submaps.high_resolution
TRAJECTORY_BUILDER_3D.submaps.low_resolution
TRAJECTORY_BUILDER_3D.high_resolution_adaptive_voxel_filter.max_range
TRAJECTORY_BUILDER_3D.low_resolution_adaptive_voxel_filter.max_range
POSE_GRAPH.optimize_every_n_nodes
POSE_GRAPH.constraint_builder.max_constraint_distance
POSE_GRAPH.fast_correlative_scan_matcher.linear_search_window
POSE_GRAPH.fast_correlative_scan_matcher_3d.linear_xy_search_window
POSE_GRAPH.fast_correlative_scan_matcher_3d.linear_z_search_window
POSE_GRAPH.fast_correlative_scan_matcher*.angular_search_window
POSE_GRAPH.constraint_builder.sampling_ratio
POSE_GRAPH.constraint_builder.fast_correlative_scan_matcher.branch_and_bound_depth
POSE_GRAPH.constraint_builder.fast_correlative_scan_matcher_3d.branch_and_bound_depth
POSE_GRAPH.constraint_builder.fast_correlative_scan_matcher_3d.full_resolution_depth
POSE_GRAPH.constraint_builder.min_score
POSE_GRAPH.constraint_builder.ceres_scan_matcher_3d
POSE_GRAPH.constraint_builder.ceres_scan_matcher
POSE_GRAPH.constraint_builder.loop_closure_translation_weight
POSE_GRAPH.constraint_builder.loop_closure_rotation_weight
POSE_GRAPH.matcher_translation_weight
POSE_GRAPH.matcher_rotation_weight
POSE_GRAPH.optimization_problem.*_weight
POSE_GRAPH.optimization_problem.ceres_solver_options
POSE_GRAPH.optimization_problem.huber_scale
POSE_GRAPH.max_num_final_iterations
给定一张已有地图,可以进行单纯的定位操作。在定位操作下,参数配置的要求有如下改变:
要进入定位模式,首先需要设置:
TRAJECTORY_BUILDER.pure_localization = true
同时,需要大幅减小POSE_GRAPH.optimize_every_n_nodes以保障结果的快速输出。在这样的设置下,Global SLAM的计算资源要求大增,可能无法满足实时要求,为此,需要大幅调低global_sampling_ratio和constraint_builder.sampling_ratio。
设置use_odometry = true,可以在Local SLAM中使用里程计。同样也可以通过配置如下几个参数来使Global SLAM也从里程计的数据获得一定收益。
POSE_GRAPH.optimization_problem.local_slam_pose_translation_weight
POSE_GRAPH.optimization_problem.local_slam_pose_rotation_weight
POSE_GRAPH.optimization_problem.odometry_translation_weight
POSE_GRAPH.optimization_problem.odometry_rotation_weight
我们可以根据我们对Local SLAM或里程计的信任程度来设置这些权重。默认情况下,在全局优化中里程计的权重和Local SLAM的位姿相同。然而,来自轮速编码器的里程计的角速度通常具有很高的不确定性。在这种情况下,旋转的权重可以减小,甚至降低到零。
使用rviz可以在constraints一栏中打开或者关闭约束和残差的显示,对于可视化的参数优化很有帮助。