一、slam_toolbox介绍
Slam Toolbox 是 Steve Macenski 在 Simbe Robotics 工作时构建的一套用于 2D SLAM 的工具和功能包,在三星研究院期间进行维护,并且大部分时间在他的空闲时间进行维护。'其支持基本的2D SLAM建图,支持自动、手动保存pgm地图;支持加载已保存好的地图,并进行地图的更新;支持无地图定位及有地图定位(类似AMCL);支持同步和异步构建地图等功能。
二、下载与使用
1.下载
二进制下载,关注源码的同学,可以去github上下载。github:slam_toolbox
sudo apt-get install ros-melodic-slam-toolbox*
2.基本2DSLAM使用
2.1 准备工作
gazebo仿真,含有机器人底盘及环境。
2.2 编写启动文件
这里仿照slam_toolbox功能包中的online_sync.launch进行建图文件的编写
slam_toobox_sync.launch
<launch>
<node pkg="slam_toolbox" type="sync_slam_toolbox_node" name="slam_toolbox" output="screen">
<rosparam command="load" file="$(find mbot_navigation)/config/slam_toolbox_sync.yaml" />
</node>
</launch>
slam_toobox_sync.yaml (具体参数含义可自行去github上了解)
# Plugin params
solver_plugin: solver_plugins::CeresSolver
ceres_linear_solver: SPARSE_NORMAL_CHOLESKY
ceres_preconditioner: SCHUR_JACOBI
ceres_trust_strategy: LEVENBERG_MARQUARDT
ceres_dogleg_type: TRADITIONAL_DOGLEG
ceres_loss_function: None
# ROS Parameters
odom_frame: odom
map_frame: map
base_frame: base_footprint
scan_topic: /scan
mode: map #localization
# if you'd like to immediately start continuing a map at a given pose
# or at the dock, but they are mutually exclusive, if pose is given
# will use pose
#map_file_name: test_steve
#map_start_pose: [0.0, 0.0, 0.0]
#map_start_at_dock: true
debug_logging: false
throttle_scans: 1
transform_publish_period: 0.02 #if 0 never publishes odometry
map_update_interval: 5.0
resolution: 0.05
max_laser_range: 15.0 #for rastering images
minimum_time_interval: 0.5
transform_timeout: 0.2
tf_buffer_duration: 30.
stack_size_to_use: 40000000 #// program needs a larger stack size to serialize large maps
enable_interactive_mode: true
# General Parameters
use_scan_matching: true
use_scan_barycenter: true
minimum_travel_distance: 0.5
minimum_travel_heading: 0.5
scan_buffer_size: 10
scan_buffer_maximum_scan_distance: 10
link_match_minimum_response_fine: 0.1
link_scan_maximum_distance: 1.5
loop_search_maximum_distance: 3.0
do_loop_closing: true
loop_match_minimum_chain_size: 10
loop_match_maximum_variance_coarse: 3.0
loop_match_minimum_response_coarse: 0.35
loop_match_minimum_response_fine: 0.45
# Correlation Parameters - Correlation Parameters
correlation_search_space_dimension: 0.5
correlation_search_space_resolution: 0.01
correlation_search_space_smear_deviation: 0.1
# Correlation Parameters - Loop Closure Parameters
loop_search_space_dimension: 8.0
loop_search_space_resolution: 0.05
loop_search_space_smear_deviation: 0.03
# Scan Matcher Parameters
distance_variance_penalty: 0.5
angle_variance_penalty: 1.0
fine_search_angle_offset: 0.00349
coarse_search_angle_offset: 0.349
coarse_angle_resolution: 0.0349
minimum_angle_penalty: 0.9
minimum_distance_penalty: 0.5
use_response_expansion: true
2.3 开始建图
启动仿真环境
roslaunch mbot_gazebo mbot_laser_nav_gazebo.launch
启动slam_toolbox建图
roslaunch mbot_navigation slam_toobox_sync.launch
rviz
之后控制机器人按照环境走一遍,全部走完后,地图构建成功,使用地图保存节点保存地图
rosrun map_server map_saver -f map
效果:
3.地图加载与更新
在构建地图的过程中,可能会出现周围环境的改变;抑或地图构建一半的情况,过去使用的slam算法需要重新构建地图,而slam_toolbox提供了序列化与反序列化的方案供用户使用,并将其用rviz插件的形式开放出来,以便完成对地图的加载与更新。
同然需要启动gazebo仿真环境及建图节点。
控制机器人在环境中走一部分,如图所示,仅仅构建了部分地图,此时,在slamToolboxPlugin插件中Serialize Map后设置地图名称,以map1为例,点击 "Serialize Map"按钮,将地图序列化保存,默认路径在 .ros 目录下:map1.data 、map1.posegraph
关闭仿真节点及建图节点;
重新打开后,在slamToolboxPlugin插件中Deserialize Map后设置加载的地图名称,map1,点击 “Deserialize Map” 按钮,会加载之前构建的地图,如图所示:
之后控制机器人继续运动,会继续构建地图,并更新,如图:
4.定位导航
slam_toolbox提供了类似AMCL的定位功能,可用于机器人的导航。
仿照slam_toolbox功能包中的localization.launch进行定位文件的编写
slam_toobox_localization.launch
<launch>
<node pkg="slam_toolbox" type="localization_slam_toolbox_node" name="slam_toolbox" output="screen">
<rosparam command="load" file="$(find mbot_navigation)/config/slam_toolbox_localization.yaml" />
</node>
</launch>
slam_toolbox_localization.yaml
将mode改为"localization";
map_file_name设置为序列化保存的地图名称,以test为例;
map_start_pose: [0.0, 0.0, 0.0]
其他的参数可参考github了解。
# Plugin params
solver_plugin: solver_plugins::CeresSolver
ceres_linear_solver: SPARSE_NORMAL_CHOLESKY
ceres_preconditioner: SCHUR_JACOBI
ceres_trust_strategy: LEVENBERG_MARQUARDT
ceres_dogleg_type: TRADITIONAL_DOGLEG
ceres_loss_function: None
# ROS Parameters
odom_frame: odom
map_frame: map
base_frame: base_footprint
scan_topic: /scan
mode: localization #localization
# if you'd like to start localizing on bringup in a map and pose
map_file_name: test
map_start_pose: [0.0, 0.0, 0.0]
debug_logging: false
throttle_scans: 1
transform_publish_period: 0.02 #if 0 never publishes odometry
map_update_interval: 5.0
resolution: 0.05
max_laser_range: 15.0 #for rastering images
minimum_time_interval: 0.5
transform_timeout: 0.2
tf_buffer_duration: 30.
stack_size_to_use: 40000000 #// program needs a larger stack size to serialize large maps
# General Parameters
use_scan_matching: true
use_scan_barycenter: true
minimum_travel_distance: 0.5
minimum_travel_heading: 0.5
scan_buffer_size: 3
scan_buffer_maximum_scan_distance: 10
link_match_minimum_response_fine: 0.1
link_scan_maximum_distance: 1.5
do_loop_closing: true
loop_match_minimum_chain_size: 3
loop_match_maximum_variance_coarse: 3.0
loop_match_minimum_response_coarse: 0.35
loop_match_minimum_response_fine: 0.45
# Correlation Parameters - Correlation Parameters
correlation_search_space_dimension: 0.5
correlation_search_space_resolution: 0.01
correlation_search_space_smear_deviation: 0.1
# Correlation Parameters - Loop Closure Parameters
loop_search_space_dimension: 8.0
loop_search_space_resolution: 0.05
loop_search_space_smear_deviation: 0.03
loop_search_maximum_distance: 5.0
# Scan Matcher Parameters
distance_variance_penalty: 0.5
angle_variance_penalty: 1.0
fine_search_angle_offset: 0.00349
coarse_search_angle_offset: 0.349
coarse_angle_resolution: 0.0349
minimum_angle_penalty: 0.9
minimum_distance_penalty: 0.5
use_response_expansion: true
启动仿真环境
roslaunch mbot_gazebo mbot_laser_nav_gazebo.launch
启动slam_toolbox定位节点
roslaunch mbot_navigation slam_toobox_localization.launch
启动导航功能(move_base节点)
roslaunch mbot_navigation nav_cloister_demo.launch
如图所示:机器人可执行导航功能
总结
本文仅仅简单介绍了slam_toolbox的基本使用,可以方便供用户使用,达到开箱即用的效果,当然slam_toolbox还有其他的功能,大家可以一起交流使用,同时感谢作者的开源。