> 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/13.-autonomous-driving-zi-dong-jia-shi/13.2.-tb3-autorace-tiao-zhan-sai-jiao-cheng/13.2.5.-jiao-cheng-5-jie-ge-bie-ren-wu/13.2.5.3.-jiao-cheng-5.3-gong-lv-deng-traffic-light.md).

# 13.2.5.3. 教程 5.3：紅綠燈 Traffic Light

1\. 把 TB3 機器人放在車道上。如果正確放置，黃線應在機器人的左側，白線應在機器人的右側。 需確認 turtlebot3\_bringup 套件的 turtlebot3\_robot node 節點尚未啟動。如果它已經啟動，機器人將突然在軌道上運行。

2\. **\[Remote PC 端]** 開新的 terminal 視窗，輸入

```
 $ export AUTO_DT_CALIB=calibration
 $ roslaunch turtlebot3_autorace_detect turtlebot3_autorace_detect_traffic_light.launch
```

3\. **\[Remote PC 端]** 開新的 terminal 視窗，輸入

```
 $ rqt
```

點擊在視窗上方的 plugins -> visualization -> Image view，會產生一個攝影機視角圖的新視窗。用相同方式在 rqt 平板產生額外 4 個新視窗。然後在這 4 個新視窗，分別選擇 /detect/image\_red\_light ， /detect/image\_yellow\_light ， /detect/image\_green\_light ，及 /detect/image\_traffic\_light 的 topics。如果一切正常，三個螢幕將顯示紅色/黃色/綠色燈光的過濾影像，另一個螢幕將以短字串顯示識別出的顏色。在校準模式下，三個螢幕將顯示白色，另一個螢幕則單純顯示結果。此時，您應該調整過濾器參數，以顯示正確的車道線和方向。

4\. **\[Remote PC 端]** 開新的 terminal 視窗，輸入

```
 $ rosrun rqt_reconfigure rqt_reconfigure
```

然後調整 /detect\_traffic\_light 中的參數值。更改 color filter 顏色過濾器的數值，在每種顏色的螢幕上，將會顯示更改的過濾視角圖。之後，將值覆寫到turtlebot3\_autorace\_detect/param/traffic\_light/ 中的 traffic\_light.yaml 檔案。這會使攝影機在下次啟動時，使用你所設置的參數。

{% hint style="info" %}
提示：與教程 5.1 車道檢測相同
{% endhint %}

5\. **\[Remote PC 端]** 在覆寫了校準檔案後，可結束 rqt\_rconfigure 及 turtlebot3\_autorace\_detect\_traffic\_light，然後輸入

```
 $ export AUTO_DT_CALIB=action
 $ roslaunch turtlebot3_autorace_detect turtlebot3_autorace_detect_traffic_light.launch
```

6\. 使用 rqt\_image\_view node 節點來檢查是否輸出的結果正確。
