基于机器人(irobot)和激光雷达(rplidar)gmapping地图构建

基于机器人(irobot)和激光雷达(rplidar)gmapping地图构建

说明

  • 介绍irobot搭载激光雷达irplidar通过gmapping算法构建地图

安装准备

  • 测试环境Ubuntu14.04 + indigo
  • ROS依赖包:
    • Turtlebot机器包
      https://github.com/turtlebot/turtlebot
      https://github.com/ncnynl/turtlebot_apps.git
    • 激光雷达rplidar一代驱动包
      https://github.com/ncnynl/rplidar_ros.git
    • slam_gmapping
      https://github.com/ros-perception/slam_gmapping
    • openslam_gmapping包
      https://github.com/ros-perception/openslam_gmapping

步骤

  • 创建工作空间

mkdir -p ~/catkin_ws/src
cd ~/catkin_ws/src

  • 下载turtlebot相关包

git clone https://github.com/turtlebot/turtlebot
git clone https://github.com/ncnynl/turtlebot_apps.git

  • 下载激光雷达rplidar一代驱动

git clone https://github.com/ncnynl/rplidar_ros.git

  • 下载slam_gmapping

git clone https://github.com/ros-perception/slam_gmapping

  • 下载openslam_gmapping

git clone https://github.com/ros-perception/openslam_gmapping

  • 编译

cd ~/catkin_ws
catkin_make
source devel/setup.bash

参数设置

环境参数设置

export TURTLEBOT_BASE=roomba
export TURTLEBOT_STACKS=circles
export TURTLEBOT_3D_SENSOR=rplidar
export TURTLEBOT_SERIAL_PORT=/dev/ttyUSB0

激光雷达串口设置

  • 创建激光雷达串口别名,确认idVendor和idProduct,ID后面的部分idVendor:idProduct

lsusb
Bus 001 Device 006: ID 10c4:ea60

  • 新建 /etc/udev/rules.d/rplidar.rules文件,内容如下:(别名为rplidar,实际名称为:/dev/rplidar)

KERNEL==”ttyUSB*”, ATTRS{idVendor}==”10c4”, ATTRS{idProduct}==”ea60”,
MODE:=”0666”, GROUP:=”dialout”, SYMLINK+=”rplidar”

  • 增加当前用户对串口的默认访问权限:

sudo usermod -a -G dialout 用户名

  • 使UDEV配置生效:(使串口的默认访问权限生效,需要重启机器)

sudo service udev reload
sudo service udev restart

制作雷达启动文件

  • 建立rplidar_laser.launch文件

roscd turtlebot_navigation
mkdir -p laser/driver
touch rplidar_laser.launch

  • 完整代码为:
<launch> 
   
  <node name="rplidarNode"          pkg="rplidar_ros"  type="rplidarNode" output="screen"> 
  <param name="serial_port"         type="string" value="/dev/ttyUSB1"/>  
  <param name="serial_baudrate"     type="int"    value="115200"/> 
  <param name="frame_id"            type="string" value="laser"/> 
  <param name="inverted"            type="bool"   value="false"/> 
  <param name="angle_compensate"    type="bool"   value="true"/> 
  node> 
  <node pkg="tf" type="static_transform_publisher" name="base_to_laser" args="0.0 0.0 0.18 0.0 0.0 0.0 base_link laser 100"/> 
launch>
  • 说明:

    • 检查serial_port是否正确,正确使用别名
    • 增加tf,修改args=”x y z qx qy qz frame_id child_id period_in_ms”,单位为m
  • 增加rplidar_gmapping.launch.xml文件,设置gmapping参数

<launch> 
  <arg name="scan_topic"  default="scan" /> 
  <arg name="base_frame"  default="base_footprint"/> 
  <arg name="odom_frame"  default="odom"/> 
  <node pkg="gmapping" type="slam_gmapping" name="slam_gmapping" output="screen" clear_params="true" > 
    <param name="base_frame" value="$(arg base_frame)"/> 
    <param name="odom_frame" value="$(arg odom_frame)"/> 
    <param name="map_update_interval" value="5"/>  
    <param name="maxUrange" value="6.0"/>  
    <param name="maxRange" value="6.0"/> 
    <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="minimumScore" value="80"/>   
    <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.05"/>   
    <param name="angularUpdate" value="0.0436"/> 
    <param name="temporalUpdate" value="-1.0"/>   
    <param name="resampleThreshold" value="0.5"/>   
    <param name="particles" value="200"/>    

    <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>
  • 增加rplidar_gmapping_demo.launch文件,用于启动gmapping

roscd turtlebot_navigation
touch launch/irobot_rplidar_gmapping_demo.launch

  • 代码为:
<launch> 
   
  <include file="$(find turtlebot_bringup)/launch/minimal.launch"/> 
  
  <include file="$(find turtlebot_navigation)/laser/driver/rplidar_laser.launch" /> 
   
  <include file="$(find turtlebot_navigation)/launch/rplidar_gmapping_params.launch.xml"/> 
   
  <include file="$(find turtlebot_navigation)/launch/move_base.launch"/> 
  <include file="$(find turtlebot_rviz_launchers)/launch/view_navigation.launch"/> 
launch>
  • 新建move_base.launch文件

roscd turtlebot_navigation
touch launch/move_base.launch

 
 "move_base" type="move_base" respawn="false" name="move_base" output="screen" clear_params="true"> 
   <param name="footprint_padding" value="0.01" /> 
    <param name="controller_frequency" value="10.0" /> 
    <param name="controller_patience" value="3.0" /> 
    <param name="oscillation_timeout" value="30.0" /> 
    <param name="oscillation_distance" value="0.5" /> 
    file="$(find turtlebot_navigation)/config/costmap_common_params.yaml" command="load" ns="global_costmap" /> 
    file="$(find turtlebot_navigation)/config/costmap_common_params.yaml" command="load" ns="local_costmap" /> 
    file="$(find turtlebot_navigation)/config/local_costmap_params.yaml" command="load" /> 
    file="$(find turtlebot_navigation)/config/global_costmap_params.yaml" command="load" /> 
    file="$(find turtlebot_navigation)/config/base_local_planner_params.yaml" command="load" /> 
   
  • 增加move_base.launch文件中的.yaml文件

roscd turtlebot_navigation
mkdir -p config
touch config/costmap_common_params.yaml
touch config/lobal_costmap_params.yaml
touch config/global_costmap_params.yaml
touch config/base_local_planner_params.yaml

  • 增加costmap_common_params.yaml文件
obstacle_range: 2.5 
raytrace_range: 3.0 
robot_radius: 0.17 
inflation_radius: 0.18 
max_obstacle_height: 0.6 
min_obstacle_height: 0.0 
observation_sources: laser_scan_sensor 
laser_scan_sensor: {sensor_frame: /base_laser_link, data_type: LaserScan, topic: /base_scan, marking: true, clearing: true}
  • 增加local_costmap_params.yaml文件
  local_costmap: 
   global_frame: /odom 
   robot_base_frame: /base_link 
   update_frequency: 3.0 
   publish_frequency: 2.0 
   static_map: false 
   rolling_window: true 
   width: 4.0 
   height: 4.0 
   resolution: 0.05
  • 增加 global_costmap_params.yaml文件
   global_costmap: 
   global_frame: /odom 
   robot_base_frame: /base_link 
   update_frequency: 3.0 
   publish_frequency: 0.0 
  #static_map: true
  • 增加base_local_planner_params.yaml文件
controller_frequency: 5.0 
TrajectoryPlannerROS: 
  max_vel_x: 0.20 
  min_vel_x: 0.10 
  max_rotational_vel: 0.4 
  min_in_place_rotational_vel: 0.1 
  acc_lim_th: 0.75 
  acc_lim_x: 0.50 
  acc_lim_y: 0.50 
  holonomic_robot: false 
  yaw_goal_tolerance: 0.05 
  xy_goal_tolerance: 0.1 
  goal_distance_bias: 0.8 
  path_distance_bias: 0.6 
  sim_time: 1.2 
  heading_lookahead: 0.325 
  oscillation_reset_dist: 0.05 
  vx_samples: 6 
  vtheta_samples: 20 
  dwa: false

测试激光雷达gmapping构建地图

  • 打开roscore,启动turtlebot、gmapping、rviz

roslaunch turtlebot_navigation irobot_rplidar_gmapping_demo.launch

  • 启动键盘操作irobot

roslaunch turtlebot_teleop keyboard_teleop.launch

  • 建图结束后保存

mkdir -p ~/map
rosrun map_server map_saver -f ~/map/my_map
ls ~/map

记录建图数据

  • 列出当前运行的topic

rostopic list -v

  • 新建一个文件夹用于保存录制的内容,在该目录下运行

mkdir tempbagfiles
cd tempbagfiles
rosbag record -a

  • 使用rosbag info检查bag文件

rosbag info

  • 使用rosbag play命令回放,以再现系统运行过程

rosbag play

默认模式下,rosbag play命令在公告每条消息后会等待一小段时间(0.2秒)后才真正开始发布bag文件中的内容。等待时间可以通过-d选项来指定。你可以通过-s参数选项让rosbag play命令等待一段时间跳过bag文件初始部分后再真正开始回放。最后一个可能比较有趣的参数选项是-r选项,它允许你通过设定一个参数来改变消息发布速率。

  • 数据提取

rostopic echo -b file.bag -p /topic > data.txt

  • 地图创建

roscore
rosmake gmapping
rosparam set use_sim_time true

  • 启动slam_gmapping

rosrun gmapping slam_gmapping scan:=base_scan

  • 在一个新的终端回放bag文件

rosbag play –clock filename

  • 使用map_server包的map_saver保存地图

rosrun map_server map_saver

  • 查看地图的进展

rosrun rviz rviz

你可能感兴趣的:(ros学习)