> For the complete documentation index, see [llms.txt](https://idminer.gitbook.io/robotis/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://idminer.gitbook.io/robotis/part-1-turtlebot3/untitled/9.1.-zhi-hang-slam-nodes.md).

# 9.1. 執行 SLAM nodes

**\[Remote PC端]**: 執行 roscore

```
$ roscore
```

**\[TurtleBot 端]**: 啟用基本套件來開始 TB3 應用

```
$ roslaunch turtlebot3_bringup turtlebot3_robot.launch
```

**\[Remote PC端]**: 開啟一個新的 terminal 視窗, 啟動 SLAM 檔案

{% hint style="info" %}
Tip：在執行指令前，必須先指定 TurtleBot3 的 model 模型名稱。${TB3\_MODEL} 是表示所使用的 burger, waffle, waffle\_pi 模型的名稱。如果你要永久設定 export setting，請參考 [**Export TURTLEBOT3\_MODEL**](http://emanual.robotis.com/docs/en/platform/turtlebot3/export_turtlebot3_model) 網頁。
{% endhint %}

```
$ export TURTLEBOT3_MODEL=${TB3_MODEL}
$ roslaunch turtlebot3_slam turtlebot3_slam.launch slam_methods:=gmapping
```

{% hint style="info" %}
Tip：當執行上述指令時，3D 視覺化工具 RViz 也會一起執行。如果你要分開執行 RViz，請使用下列指令之一。&#x20;

* $ rviz -d `rospack find turtlebot3_slam`/rviz/turtlebot3\_gmapping.rviz&#x20;
* $ rviz -d `rospack find turtlebot3_slam`/rviz/turtlebot3\_cartographer.rviz&#x20;
* $ rviz -d `rospack find turtlebot3_slam`/rviz/turtlebot3\_hector.rviz&#x20;
* $ rviz -d `rospack find turtlebot3_slam`/rviz/turtlebot3\_karto.rviz&#x20;
* $ rviz -d `rospack find turtlebot3_slam`/rviz/turtlebot3\_frontier\_exploration.rviz
  {% endhint %}

{% hint style="info" %}
備註：支援不同的 SLAM 方法&#x20;

* 在各種 SLAM 方法中，TB3 支援 Gmapping, Cartographer, Hector, 及 Karto 等方法。你可以使用 slam\_methods:=xxxxx 選項來更改方法。
* slam\_methods 選項有 gmapping, cartographer, hector, karto, frontier\_exploration 等, 你可以擇一使用&#x20;
* 舉例如果要選擇 Karto 方法，則指令為&#x20;
  * $ roslaunch turtlebot3\_slam turtlebot3\_slam.launch slam\_methods:=karto
    {% endhint %}

{% hint style="info" %}
備註：安裝跟 SLAM 套件相關的套件有&#x20;

* For Gmapping:&#x20;
  * 跟 Gmapping 相關的套件已在執行 PC Setup 時就安裝了.&#x20;
* For Cartographer:&#x20;
  * sudo apt-get install ros-kinetic-cartographer ros-kinetic-cartographer-ros ros-kinetic-cartographer-ros-msgs ros-kinetic-cartographer-rviz
* For Hector Mapping:&#x20;
  * sudo apt-get install ros-kinetic-hector-mapping
* For Karto:&#x20;
  * sudo apt-get install ros-kinetic-slam-karto
* For Frontier Exploration:
  * Frontier Exploration 使用 gmapping 套件, 且下列套件也要一起安裝&#x20;
  * sudo apt-get install ros-kinetic-frontier-exploration ros-kinetic-navigation-stage
    {% endhint %}

{% hint style="info" %}
Tip：我們測試了 Cartographer version 0.3.0。Cartographer 套件是由 Google 開發，在 ROS Melodic 版支援 0.3.0版，但在 ROS Kinetic 版是支援 0.2.0 版。如果你需要在 ROS Kinetic 跑 Cartographer version 0.3.0，你應該下載原始碼後，以下列方式來 build 建立套件。請參考 [**official wiki page**](https://google-cartographer-ros.readthedocs.io/en/latest/#building-installation) 來了解更多資訊。
{% endhint %}

```
$ 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
```

```
$ source ~/catkin_ws/install_isolated/setup.bash
$ roslaunch turtlebot3_slam turtlebot3_slam.launch slam_methods:=cartographer
```
