04-SLAM

小芽科技 2022-07-26 11:43:24
Categories: Tags:

本文档由北京小芽科技翻译,原文来自于ROBOTIS官方技术文档

4 SLAM

注意

SLAM(Simultaneous Localization and Mapping)**是一种通过在任意空间估计当前位置来绘制地图的技术。SLAM是TurtleBot前辈们的一个著名功能。这里的视频向你展示了TurtleBot3是如何利用其紧凑而经济的平台准确地绘制地图的。

4.1 运行 SLAM 节点

  1. 在远程PC上运行 roscore 。

    1
    $ roscore
  2. 如果 “Bringup “没有在TurtleBot3 SBC上运行,启动Bringup。如果你之前已经启动了Bringup,请跳过此步骤

    • Ctrl+Alt+T在远程电脑上打开一个新的终端,用Raspberry Pi的IP地址连接到它。默认密码是turtlebot

      1
      2
      $ ssh pi@{IP_ADDRESS_OF_RASPBERRY_PI}
      $ roslaunch turtlebot3_bringup turtlebot3_robot.launch
  3. Ctrl+Alt+T从远程电脑上打开一个新的终端,启动SLAM节点。Gmapping被用作默认的SLAM方法。请在 TURTLEBOT3_MODEL 参数中使用适当的关键字 burgerwafflewaffle_pi

    1
    2
    $ export TURTLEBOT3_MODEL=burger
    $ roslaunch turtlebot3_slam turtlebot3_slam.launch

 如何保存TURTLEBOT3_MODEL参数?

The $ export TURTLEBOT3_MODEL=${TB3_MODEL} command can be omitted if the TURTLEBOT3_MODEL parameter is predefined in the .bashrc file.
The .bashrc file is automatically loaded when a terminal window is created.

  • Example of defining TurtlBot3 Burger as a default model.
    $ echo 'export TURTLEBOT3_MODEL=burger' >> ~/.bashrc
    $ source ~/.bashrc
    
  • Example of defining TurtlBot3 Waffle Pi as a default model.
    $ echo 'export TURTLEBOT3_MODEL=waffle_pi' >> ~/.bashrc
    $ source ~/.bashrc
    

 阅读更多关于其他SLAM方法的信息

  • Gmapping (ROS WIKI, Github)
    1. Install dependent packages on PC.
      Packages related to Gmapping have already been installed on PC Setup section.
    2. Launch the Gmapping SLAM node.
      $ roslaunch turtlebot3_slam turtlebot3_slam.launch slam_methods:=gmapping
      
  • Cartographer (ROS WIKI, Github)
    1. Download and build packages on PC.
      The Cartographer package developed by Google supports ROS1 Kinetic with 0.2.0 version. So if you need to use Cartogrpher on Kinetic, you should download and build the source code as follows instead of installing with the binary packages. Please refer to official wiki page for more detailed installation instructions.
      $ sudo apt-get install ninja-build libceres-dev libprotobuf-dev protobuf-compiler libprotoc-dev
      $ cd ~/catkin_ws/src
      $ git clone https://github.com/googlecartographer/cartographer.git
      $ git clone https://github.com/googlecartographer/cartographer_ros.git
      $ cd ~/catkin_ws
      $ src/cartographer/scripts/install_proto3.sh
      $ rm -rf protobuf/
      $ rosdep install --from-paths src --ignore-src -r -y --os=ubuntu:xenial
      $ catkin_make_isolated --install --use-ninja
      
    2. Launch the Cartographer SLAM node.
      $ source ~/catkin_ws/install_isolated/setup.bash
      $ roslaunch turtlebot3_slam turtlebot3_slam.launch slam_methods:=cartographer
      
  • Hector (ROS WIKI, Github)
    1. Install dependent packages on PC.
      $ sudo apt-get install ros-kinetic-hector-mapping
      
    2. Launch the Hector SLAM node.
      $ roslaunch turtlebot3_slam turtlebot3_slam.launch slam_methods:=hector
      
  • Karto (ROS WIKI, Github)
    1. Install dependent packages on PC.
      $ sudo apt-get install ros-kinetic-slam-karto
      
    2. Launch the Karto SLAM node.
      $ roslaunch turtlebot3_slam turtlebot3_slam.launch slam_methods:=karto
      
  • Frontier Exploration (ROS WIKI, Github)
    Frontier Exploration uses gmapping, and the following packages should be installed.
    1. Install dependent packages on PC.
      $ sudo apt-get install ros-kinetic-frontier-exploration ros-kinetic-navigation-stage
      
    2. Launch the Frontier Exploration SLAM node.
      $ roslaunch turtlebot3_slam turtlebot3_slam.launch slam_methods:=frontier_exploration
      

4.2 运行 Teleoperation 节点

一旦SLAM节点成功启动并运行,TurtleBot3将使用远程操作探索地图的未知区域。重要的是要避免剧烈的运动,如过快地改变线性和角速度。在使用TurtleBot3构建地图时,扫描地图的每个角落是一个好的做法。

  1. 打开一个新的终端,从远程PC上运行远程操作节点。

    请在TURTLEBOT3_MODEL参数中使用burgerwafflewaffle_pi中适当的关键字。

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
       $ export TURTLEBOT3_MODEL=burger
    $ roslaunch turtlebot3_teleop turtlebot3_teleop_key.launch

    Control Your TurtleBot3!
    ---------------------------
    Moving around:
    w
    a s d
    x

    w/x : increase/decrease linear velocity
    a/d : increase/decrease angular velocity
    space key, s : force stop

    CTRL-C to quit
  2. 开始探索和绘制地图。
    img

4.3 调试指南

Gmapping有许多参数可以改变不同环境下的性能。你可以在ROS WiKi中获得关于整个参数的信息,或者参考ROS机器人编程的第11章。本调整指南提供了配置gmapping参数的提示。如果你想针对你的环境优化SLAM性能,本节可能会有帮助。

以下参数在turtlebot3_slam/config/gmapping_params.yaml文件中定义。

4.3.1 maxUrange

该参数设置激光雷达传感器的最大可用范围。

4.3.2 map_update_interval

这个参数定义了更新地图的间隔时间。
该值越小,地图的更新就越频繁。
但是,设置得太小,将需要更多的处理能力来计算地图。根据地图环境来设置这个参数。

img

4.3.3 minimumScore

该参数设置决定传感器扫描数据匹配测试成功或失败的最小分值。这可以减少机器人在大区域内的预期位置的误差。如果该参数设置得当,你会看到类似于下图的信息。

1
2
3
4
5
6
Average Scan Matching Score=278.965
neff= 100
Registering Scans:Done
update frame 6
update ld=2.95935e-05 ad=0.000302522
Laser Pose= -0.0320253 -5.36882e-06 -3.14142

如果设置太高,你可能会看到下面的警告。

1
2
3
Scan Matching Failed, using odometry. Likelihood=0
lp:-0.0306155 5.75314e-06 -3.14151
op:-0.0306156 5.90277e-06 -3.14151

4.3.4 linearUpdate

当机器人平移的距离大于该值时,它将运行扫描过程。

4.3.5 angularUpdate

当机器人旋转超过该值时,它将运行扫描过程。建议将此值设置为小于linearUpdate。

4.4 保存地图

该地图是根据机器人的dometrytf和扫描信息绘制的。这些地图数据是在TurtleBot3行驶时在RViz窗口中绘制的。在创建完所需区域的完整地图后,将地图数据保存到本地硬盘,以便以后使用。

  1. 在map_server包中启动map_saver节点,创建地图文件。

    地图文件被保存在启动map_saver节点的目录中。

    除非提供特定的文件名,否则map将被用作默认文件名,并创建map.pgmmap.yaml

    1
    $ rosrun map_server map_saver -f ~/map

-f选项指定了一个文件夹位置和文件名,文件将被保存。
使用上述命令,map.pgmmap.yaml将被保存在主文件夹~/(/home/${username})。

4.5 地图

该地图使用二维的占用网格图(OGM),这在ROS中是常用的。保存的地图将如下图所示,其中白色区域是无碰撞区域,而黑色区域是被占用和无法进入的区域,灰色区域代表未知区域。该地图用于导航

img

下图显示了使用TurtleBot3创建一个大型地图的结果。创建一个行进距离约为350米的地图大约花了一个小时。

img