赞
踩
根据建图时所用的传感器的不同,可将现有的slam算法分为两类:
激光雷达扫描信息:
angle_min
:可检测范围的起始角度angle_max
:可检测范围的终止角度,与angle_min
组成激光雷达的可检测范围angle_increment
:相邻数据帧之间的角度步长time_increment
:采集到相邻数据帧之间的时间步长,当传感器处于相对运动状态时进行补偿使用scan_time
:采集一帧数据所需要的时间range_min
:最近可检测深度的阈值range_max
:最远可检测深度的阈值ranges
:一帧深度数据的存储数组pose
:机器人当前位置坐标,包括
twist
:机器人当前的运行状态,包括
创建仿真环境:
roslaunch mbot_gazebo mbot_laser_nav_gazebo.launch
注意:
编译源码时可能需要一些依赖比如:sudo apt-get install ros-kinetic-gazebo-ros-control
安装以上命令有错误时尝试:sudo apt-get –f install
nav_msgs/OccupancyGrid
sudo apt-get install ros-kinetic-gmapping
文件为:src5/mbot_navigation/launch/gmapping.launch
参数说明可参看:http://wiki.ros.org/gmapping
<launch> <arg name="scan_topic" default="scan" /> <node pkg="gmapping" type="slam_gmapping" name="slam_gmapping" output="screen" clear_params="true"> <param name="odom_frame" value="odom"/> <param name="map_update_interval" value="5.0"/> <!-- Set maxUrange < actual maximum range of the Laser --> <param name="maxRange" value="5.0"/> <param name="maxUrange" value="4.5"/> <param name="sigma" value="0.05"/> <param name="kernelSize" value="1"/> <param name="lstep" value="0.05"/> <param name="astep" value="0.05"/> <param name="iterations" value="5"/> <param name="lsigma" value="0.075"/> <param name="ogain" value="3.0"/> <param name="lskip" value="0"/> <param name="srr" value="0.01"/> <param name="srt" value="0.02"/> <param name="str" value="0.01"/> <param name="stt" value="0.02"/> <param name="linearUpdate" value="0.5"/> <param name="angularUpdate" value="0.436"/> <param name="temporalUpdate" value="-1.0"/> <param name="resampleThreshold" value="0.5"/> <param name="particles" value="80"/> <param name="xmin" value="-1.0"/> <param name="ymin" value="-1.0"/> <param name="xmax" value="1.0"/> <param name="ymax" value="1.0"/> <param name="delta" value="0.05"/> <param name="llsamplerange" value="0.01"/> <param name="llsamplestep" value="0.01"/> <param name="lasamplerange" value="0.005"/> <param name="lasamplestep" value="0.005"/> <remap from="scan" to="$(arg scan_topic)"/> </node> </launch>
$ roslaunch mbot_gazebo mbot_laser_nav_gazebo.launch
$ roslaunch mbot_navigation gmapping_demo.launch
$ roslaunch mbot_teleop mbot_teleop.launch
效果如下
用键盘控制机器人移动得到地图
保存地图:rosrun map_server map_saver -f cloister_gmapping
下面为得到的地图 :
src5/mbot_navigation/maps/cloister_gmapping.pgm
src5/mbot_navigation/maps/cloister_gmapping.yaml
image: cloister_gmapping.pgm
resolution: 0.050000
origin: [-15.400000, -12.200000, 0.000000]
negate: 0
occupied_thresh: 0.65
free_thresh: 0.196
$ roslaunch mbot_gazebo mbot_kinect_nav_gazebo.launch
$ roslaunch mbot_navigation gmapping_demo.launch
$ roslaunch mbot_teleop mbot_teleop.launch
效果如下:
# 机器人端
$ roslaunch mbot_bringup mbot_with_laser.launch
# pc端
$ roslaunch mbot_navigation gmapping_demo.launch
$ roslaunch mbot_teleop mbot_teleop.launch
效果如下:
nav_msgs/OccupancyGrid
sudo apt-get install ros-kinetic-hector-slam
src5/mbot_navigation/launch/hector.launch
<launch> <node pkg = "hector_mapping" type="hector_mapping" name="hector_mapping" output="screen"> <!-- Frame names --> <param name="pub_map_odom_transform" value="true"/> <param name="map_frame" value="map" /> <param name="base_frame" value="base_footprint" /> <param name="odom_frame" value="odom" /> <!-- Tf use --> <param name="use_tf_scan_transformation" value="true"/> <param name="use_tf_pose_start_estimate" value="false"/> <!-- Map size / start point --> <param name="map_resolution" value="0.05"/> <param name="map_size" value="2048"/> <param name="map_start_x" value="0.5"/> <param name="map_start_y" value="0.5" /> <param name="laser_z_min_value" value = "-1.0" /> <param name="laser_z_max_value" value = "1.0" /> <param name="map_multi_res_levels" value="2" /> <param name="map_pub_period" value="2" /> <param name="laser_min_dist" value="0.4" /> <param name="laser_max_dist" value="5.5" /> <param name="output_timing" value="false" /> <param name="pub_map_scanmatch_transform" value="true" /> <!-- Map update parameters --> <param name="update_factor_free" value="0.4"/> <param name="update_factor_occupied" value="0.7" /> <param name="map_update_distance_thresh" value="0.2"/> <param name="map_update_angle_thresh" value="0.06" /> <!-- Advertising config --> <param name="advertise_map_service" value="true"/> <param name="scan_subscriber_queue_size" value="5"/> <param name="scan_topic" value="scan"/> </node> </launch>
$ roslaunch mbot_gaze mbot_laser_nav_gazebo.launch
$ roslaunch mbot_navigation hector_demo.launch
$ roslaunch mbot_teleop mbot_teleop.launch
效果如下:
注意:hector_slam过程中发生打滑现象
mkdir -p catkin_google_ws/src
# 安装工具
sudo apt-get update
sudo apt-get install -y python-wstool python-rosdep ninja-build
# 初始化工作空间
cd catkin_google_ws
wstool init src
将源码(位置:catkin_google_ws/src
)复制到src目录下
编译:rosdep install --from-paths src --ignore-src --rosdistro=${ROS_DISTRO} -y
安装:catkin_make_isolated --install --use-ninja
设置环境变量:在home文件夹下的.bashrc
中最后一行添加:
source ~/catkin_google_ws/install_isolated/setup.bash
配置cartographer节点
src5/mbot_navigation/launch/cartographer_demo_rplidar.launch
<launch>
<param name="/use_sim_time" value="true" />
<node name="cartographer_node" pkg="cartographer_ros"
type="cartographer_node" args="
-configuration_directory $(find cartographer_ros)/configuration_files
-configuration_basename rplidar.lua"
output="screen">
<remap from="scan" to="scan" />
</node>
<node name="rviz" pkg="rviz" type="rviz" required="true"
args="-d $(find cartographer_ros)/configuration_files/demo_2d.rviz" />
</launch>
参数配置
src5/mbot_navigation/config/rplidar.lua
include "map_builder.lua" include "trajectory_builder.lua" options = { map_builder = MAP_BUILDER, trajectory_builder = TRAJECTORY_BUILDER, map_frame = "map", tracking_frame = "laser_link", published_frame = "laser_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
启动仿真
cd catkin_google_ws
catkin_make_isolated --install --use-ninja
roslaunch mbot_gazebo mbot_laser_nav_gazebo.launch
roslaunch cartographer_ros cartographer_demo_rplidar.launch
roslaunch mbot_teleop mbot_teleop.launch
效果如下:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。