cartographer启动的launch文件是存放在cartographer_detailed_comments_ws/src/cartographer_ros/cartographer_ros/launch/
文件夹中,也可以在该文件夹下创建自己的launch文件。
<launch>
<!--rosbag包的地址-->
<arg name="rosbag_file" default="$(env HOME)/bagfile/rslidar16.bag"/>
<param ="/use_sim_time" value="true"/>
<!--cartographer_ros-->
<node name="cartographer_ros_node" pkg="cartographer_ros" type="cartographer_ros_node"
args ="-configuration_directory $(find cartographer_ros)/configuration_files
-configuration_basename my_test.lua"
output="screen"/>
<remap form="points2" to="rslidar"/>
<remap form="scan" to="my_scan"/>
<remap form="odom" to="my_odom"/>
<remap form="imu" to="my_imu"/>
<remap from="fix" to="fix" />
<!--map save-->
<node name="cartographer_occupancy_grid_node" pkg="cartographer_ros"
type="cartographer_occupancy_grid_node" args="-resolution 0.05" />
<node name="playbag" pkg="rosbag" type="play"
args="--clock $(arg bag_filename)" />
</launch>
在启动cartographer_ros节点中,configuration_directory
是表示lua文件的存放地址。configuration_basename
是具体的lua文件
对于cartographer具体的一些参数都会存放在lua文件中(感觉和ros中读取yaml文件有点类似),它存放在configuration_file文件夹下,lua文件的内容如下:
#include "map_builder.lua"
#include "trajectory_builder.lua"
-- #include ""
options={
map_builder=MAP_BUILDER,
trajectory_builder=TRAJECTORY_BUILDER,
map_frame="map";
tracking_frame="imu_link",
published_frame="odom";
odom_frame="odom",
provide_odom_frame=false,
publish_frame_projected_to_2d=false,
use_pose_extrapolator=false,
use_odometry=true,
use_landmarks=false,
use_landmarks=false, --GPS
num_laser_scans=1,
num_point_clouds=1,
num_multi_echo_laser_scans=0,
num_subdivisions_per_laser_scan=1,
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.use_imu_data=true
TRAJECTORY_BUILDER_2D.min_z=-0.1
return options
文件主要分为4个部分
#include "map_builder.lua" #include "trajectory_builder.lua"
options={
map_builder=MAP_BUILDER,//map_build.lua的配置信息
trajectory_builder=TRAJECTORY_BUILDER,//同理
map_frame="map", //地图坐标系的名称
tracking_frame="imu_link", //有imu就写imu坐标系,没有的话就写base_link,就是将所有传感器的数据转换到tracking_frame坐标系下
published_frame="footprint", //tf最底层的坐标名称
odom_frame="odom", //里程计坐标信息的名字
provide_odom_frame=false, //如果ROSbag中有odom那么就为false(map->odom->footprint),没有的话写true(map->footprint)
publisher_frame_projected_to_2d=false,//是否将坐标系投影到平面上
use_pose_extrapolator = false, //位姿推测器,一般设为false(发布tf使用前端计算出来的位姿),
//这三个要使用必须有相应topic,可以在launch中设置重映射
use_odometry=false,//是否使用里程计, 如果要用必须包含odom
use_nav_sat=false,//gps
use_landmark=false,//landmark
num_laser_scans=0,//单线雷达
num_multi_echo_laser_scan=0,//
num_subdivisions_per_laser_scan=1,
num_point_clouds=1,//多线雷达
//time
lookup_transform_timeout_sec = 0.2, //tf查询超时时间
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.,
}
3.对头文件中的一些参数进行覆盖
MAP_BUILDER.use_trajectory_builder_2d = true
TRAJECTORY_BUILDER_2D.use_imu_data = true//是否使用imu数据
TRAJECTORY_BUILDER_2D.min_range = 0.3//雷达数据的使用范围
TRAJECTORY_BUILDER_2D.max_range = 100.
TRAJECTORY_BUILDER_2D.min_z = 0.2 //同样也是雷达数据范围
--TRAJECTORY_BUILDER_2D.max_z = 1.4
--TRAJECTORY_BUILDER_2D.voxel_filter_size = 0.02//体素滤波设置的值
--TRAJECTORY_BUILDER_2D.adaptive_voxel_filter.max_length = 0.5//尝试最佳的体素边长,最大为0.5,自适应体素滤波
--TRAJECTORY_BUILDER_2D.adaptive_voxel_filter.min_num_points = 200.//滤波后的点数阈值
--TRAJECTORY_BUILDER_2D.adaptive_voxel_filter.max_range = 50.//
--TRAJECTORY_BUILDER_2D.loop_closure_adaptive_voxel_filter.max_length = 0.9//回环检测时自适应体素滤波
--TRAJECTORY_BUILDER_2D.loop_closure_adaptive_voxel_filter.min_num_points = 100
--TRAJECTORY_BUILDER_2D.loop_closure_adaptive_voxel_filter.max_range = 50.
TRAJECTORY_BUILDER_2D.use_online_correlative_scan_matching = false//是否使用online_correlative_scan_matching为ceres提供先验信息,精度高但是计算量很大
TRAJECTORY_BUILDER_2D.ceres_scan_matcher.occupied_space_weight = 1.//ceres前端扫描匹配的设置,地图匹配权重
TRAJECTORY_BUILDER_2D.ceres_scan_matcher.translation_weight = 1.//平移权重
TRAJECTORY_BUILDER_2D.ceres_scan_matcher.rotation_weight = 1.//旋转权重
--TRAJECTORY_BUILDER_2D.ceres_scan_matcher.ceres_solver_options.max_num_iterations = 12//最大迭代次数
//防止子图插入太多,在子图插入之前对数据进行过滤
--TRAJECTORY_BUILDER_2D.motion_filter.max_distance_meters = 0.1
--TRAJECTORY_BUILDER_2D.motion_filter.max_angle_radians = 0.004
--TRAJECTORY_BUILDER_2D.imu_gravity_time_constant = 1.
//子图配置 一个子图里最多插入80*2个数据(也就是说当子图插入了160个数据,那么后端就可以优化了)
TRAJECTORY_BUILDER_2D.submaps.num_range_data = 80.
TRAJECTORY_BUILDER_2D.submaps.grid_options_2d.resolution = 0.1//地图分辨率
//优化方程的参数
POSE_GRAPH.optimize_every_n_nodes = 160.
POSE_GRAPH.constraint_builder.sampling_ratio = 0.3//局部子图计算回环的频率,数越大,频率越高
POSE_GRAPH.constraint_builder.max_constraint_distance = 15.//局部子图回环检测时最大的约束距离
POSE_GRAPH.constraint_builder.min_score = 0.48//回环检测最低的分数阈值(局部)
POSE_GRAPH.constraint_builder.global_localization_min_score = 0.60//回环检测最低的分数阈值(整体)
4.return