06-2-SLAM仿真

小芽科技 2022-07-26 11:46:31
Categories: Tags:

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

6.2 SLAM 仿真

在Gazebo模拟器中进行SLAM时,你可以在虚拟世界中选择或创建各种环境和机器人模型。除了准备模拟环境而不是启动机器人外,SLAM模拟与实际TurtleBot3的SLAM相当相似。

下面的说明需要前面章节的前提条件,所以请先查看Simulation部分。

6.2.1 加载运行仿真环境

准备了三个Gazebo环境,但对于用SLAM创建地图,建议使用TurtleBot3 WorldTurtleBot3 House
使用以下指令之一来加载Gazebo环境。

在本指令中,将使用TurtleBot3 World。
请在 TURTLEBOT3_MODEL 参数中使用 burgerwafflewaffle_pi 中适当的关键字。

1
2
$ export TURTLEBOT3_MODEL=burger
$ roslaunch turtlebot3_gazebo turtlebot3_world.launch

 Read more about How to load TurtleBot3 House

$ export TURTLEBOT3_MODEL=burger
$ roslaunch turtlebot3_gazebo turtlebot3_house.launch

6.2.2 运行 SLAM 节点

Ctrl+Alt+T从远程电脑打开一个新的终端,运行SLAM节点。默认使用Gmapping SLAM方法。
请在TURTLEBOT3_MODEL参数中使用burgerwafflewaffle_pi中适当的关键词。

1
2
$ export TURTLEBOT3_MODEL=burger
$ roslaunch turtlebot3_slam turtlebot3_slam.launch slam_methods:=gmapping

6.2.3 运行 Teleoperation 节点

Ctrl+Alt+T从远程电脑上打开一个新的终端,从远程电脑上运行远程操作节点。
请在 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

6.2.4 保存地图

当地图创建成功后,用Ctrl+Alt+T从远程电脑上打开一个新终端,并保存地图。

img

1
$ rosrun map_server map_saver -f ~/map

img

保存 map.pgm 文件

 Read more about How to SLAM with multiple TurtleBot3

In order to create a map with multiple robots, multirobot-map-merge package is required.
Follow the instructions below instead of Launching Simulation World section of this page to operate multiple TurtleBot3.

  1. Install necessary package
    $ sudo apt-get install ros-kinetic-multirobot-map-merge
    
  2. Load multiple TurtleBot3 in TurtleBot3 House.
    These loaded turtlebot3s are set initial position and orientation.
    $ roslaunch turtlebot3_gazebo multi_turtlebot3.launch
    

  3. Launch SLAM for each TurtleBot3
    $ ROS_NAMESPACE=tb3_0 roslaunch turtlebot3_slam turtlebot3_gmapping.launch set_base_frame:=tb3_0/base_footprint set_odom_frame:=tb3_0/odom set_map_frame:=tb3_0/map
    $ ROS_NAMESPACE=tb3_1 roslaunch turtlebot3_slam turtlebot3_gmapping.launch set_base_frame:=tb3_1/base_footprint set_odom_frame:=tb3_1/odom set_map_frame:=tb3_1/map
    $ ROS_NAMESPACE=tb3_2 roslaunch turtlebot3_slam turtlebot3_gmapping.launch set_base_frame:=tb3_2/base_footprint set_odom_frame:=tb3_2/odom set_map_frame:=tb3_2/map
    
  4. Merge map data from each TurtleBot3
    $ roslaunch turtlebot3_gazebo multi_map_merge.launch
    
  5. Launch RViz
    $ rosrun rviz rviz -d `rospack find turtlebot3_gazebo`/rviz/multi_turtlebot3_slam.rviz
    
  6. Operate each TurtleBot3
    $ ROS_NAMESPACE=tb3_0 rosrun turtlebot3_teleop turtlebot3_teleop_key
    $ ROS_NAMESPACE=tb3_1 rosrun turtlebot3_teleop turtlebot3_teleop_key
    $ ROS_NAMESPACE=tb3_2 rosrun turtlebot3_teleop turtlebot3_teleop_key
    

  7. Save the Map
    $ rosrun map_server map_saver -f ~/map