> 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/15.-ros2/15.6.-simulation-mo-ni.md).

# 15.6. Simulation 模擬

{% hint style="danger" %}
**警告**：不要在 TurtleBot3 的 SBC 端執行此節指令。 請在 **remote PC** 上按照此節步驟進行操作。
{% endhint %}

**\[Remote PC 端]**&#x20;

1\. 增加 GAZEBO\_MODEL\_PATH 路徑

```
$ echo '# Add gazebo model path' >> ~/.bashrc
$ echo 'export GAZEBO_MODEL_PATH=$GAZEBO_MODEL_PATH:~/turtlebot3_ws/src/turtlebot3/turtlebot3_simulations/turtlebot3_gazebo/models' >> ~/.bashrc
$ source ~/.bashrc
```

{% hint style="info" %}
**注意**：在執行指令前，必須先指定 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 %}

2\. 在 Turtlebot3 world 地圖載入 TB3

```
$ export TURTLEBOT3_MODEL=${TB3_MODEL}
$ ros2 launch turtlebot3_gazebo turtlebot3_world.launch.py
```

<div align="left"><img src="https://3058168660-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LkXc5k_SFaP9gK2gsU8%2F-Ll6IcwhHjW7pDAsskSU%2F-Ll6c6e-msvJqQ10jMAL%2Fgazebo_world.png?alt=media&amp;token=b2fb0bbf-37dd-4f96-943c-008215ab941f" alt=""></div>

3\. 啟動 Cartographer

```
$ ros2 launch turtlebot3_cartographer cartographer.launch.py use_sim_time:=True
```

4\. 執行 teleoperation node 節點

```
$ export TURTLEBOT3_MODEL=${TB3_MODEL}
$ ros2 run turtlebot3_teleop teleop_keyboard
```

5\. 儲存地圖

```
$ ros2 run nav2_map_server map_saver -f ~/map
```

<div align="left"><img src="https://3058168660-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LkXc5k_SFaP9gK2gsU8%2F-Ll6IcwhHjW7pDAsskSU%2F-Ll6dDD6jdpQi0jPzcFQ%2Fgazebo_cartographer.png?alt=media&amp;token=0771e7d9-1543-4cf7-bd80-acb57f11e705" alt=""></div>

* [**TB3 ROS2 Cartographer 影片**](https://youtu.be/PUr9k8CRNE0)

{% hint style="info" %}
**注意**：你應該設置一些參數以使用模擬時間。如果你需要更多訊息，請參考 [**navigation2 repo**](https://github.com/ros-planning/navigation2/tree/master/nav2_bringup) 資訊
{% endhint %}

6\. 載入TB3 模型然後以下指令啟動 Navigation2

```
$ export TURTLEBOT3_MODEL=${TB3_MODEL}
$ ros2 launch turtlebot3_navigation2 navigation2.launch.py use_sim_time:=True map:=$HOME/map.yaml
```

{% hint style="info" %}
**注意**：在執行指令前，必須先指定 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 %}

* 點擊選單欄中的 “**2D Pose Estimate**” 按鈕，然後在地圖上指向 turtlebot3 的精確方位。
* 如果 TurtleBot3 靠近 costmap 或接近了 costmap 地圖，請點擊選單欄中的**Navigation2 Goal** 按鈕，然後在地圖上指向目標方位。

<div align="left"><img src="https://3058168660-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LkXc5k_SFaP9gK2gsU8%2F-Ll6IcwhHjW7pDAsskSU%2F-Ll6e9NrmFoMHJmex3PS%2Fgazebo_navigation2.png?alt=media&amp;token=9e8c3a56-8018-43b9-9944-3a2c06979d19" alt=""></div>

* [**TB3 ROS2 Navigation2 導航影片**](https://youtu.be/aQh8JqSrmCs)
