View Categories

TurtleBot3(ROS1)-Noetic-Chap8-Autorace-自駕車挑戰賽

autorace rbiz challenge 2017 robots 1

C8.1. Getting Started #

March, 2025 校正

C8.1.1. 先決條件 #

Remote PC 筆電/桌電

  • 安裝 ROS1 Noetic
  • 本節內容主要是基於 Gazebo 的模擬,故只需要電腦即可完成,但也可以移植到實體 TB3 上實作。

補充資料:實體 TurtleBot3 參加 AutoRace 比賽需要的準備? #

1. TurtleBot3 Burger 漢堡款

  • 使用 AutoRace 套件包在 ROS 上進行自動駕駛的基礎款。
  • AutoRace 套件包的開源碼是基於 TurtleBot3 Burger 開發的

2. Remote PC 筆電/桌電

  • 跟 TB3 的 SBC 單板電腦溝通
  • 安裝 ROS 1 的筆電,桌電,或其他主機裝置

3. Raspberry Pi 攝像機及固定架

  • 你可以更換不同 camera 只要有支援 ROS
  • 用來校準 camera 的原始碼,是基於 Fisheye Lens 魚眼鏡頭模組來開發

4. AutoRace 比賽軌道圖及相關所需物件

C8.1.2. 安裝 Autorace Package 套件包 #

1. [Remote PC] 安裝 AutoRace 2020 meta packages

				
					$ cd ~/catkin_ws/src/
$ git clone -b noetic https://github.com/ROBOTIS-GIT/turtlebot3_autorace_2020.git
$ cd ~/catkin_ws && catkin_make
				
			

2. [Remote PC] 安裝額外的相關套件

				
					$ sudo apt install ros-noetic-image-transport ros-noetic-cv-bridge ros-noetic-vision-opencv python3-opencv libopencv-dev ros-noetic-image-proc

				
			

補充資料:在實體 TB3 安裝 Autorace Package #

以下步驟說明如何安裝 package 及校準 camera

1. 在 Remote PC 及 SBC 安裝 AutoRace 套件包

				
					$ cd ~/catkin_ws/src/
$ git clone -b noetic https://github.com/ROBOTIS-GIT/turtlebot3_autorace_2020.git
$ cd ~/catkin_ws && catkin_make

				
			

2. 在 SBC 安裝額外的相關套件

  • 新增 swap 檔以防止 building OpenCV 時記憶體不足
				
					  $ sudo fallocate -l 4G /swapfile
  $ sudo chmod 600 /swapfile
  $ sudo mkswap /swapfile
  $ sudo swapon /swapfile
				
			
  • 安裝相關套件
				
					  $ sudo apt-get update
  $ sudo apt-get install build-essential cmake gcc g++ git unzip pkg-config
  $ sudo apt-get install libjpeg-dev libpng-dev libtiff-dev libavcodec-dev libavformat-dev libswscale-dev libgtk2.0-dev libcanberra-gtk* libxvidcore-dev libx264-dev python3-dev python3-numpy python3-pip libtbb2 libtbb-dev libdc1394-22-dev libv4l-dev v4l-utils libopenblas-dev libatlas-base-dev libblas-dev liblapack-dev gfortran libhdf5-dev libprotobuf-dev libgoogle-glog-dev libgflags-dev protobuf-compiler
				
			
  • Build with opencv 及 opencv_contrib
				
					  $ cd ~
  $ wget -O opencv.zip https://github.com/opencv/opencv/archive/4.5.0.zip
  $ wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/4.5.0.zip

  $ unzip opencv.zip
  $ unzip opencv_contrib.zip

  $ mv opencv-4.5.0 opencv
  $ mv opencv_contrib-4.5.0 opencv_contrib
				
			
  • 產生 cmake 檔
				
					  $ cd opencv
  $ mkdir build
  $ cd build
  $ cmake -D CMAKE_BUILD_TYPE=RELEASE \
          -D CMAKE_INSTALL_PREFIX=/usr/local \
          -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \
          -D ENABLE_NEON=ON \
          -D BUILD_TIFF=ON \
          -D WITH_FFMPEG=ON \
          -D WITH_GSTREAMER=ON \
          -D WITH_TBB=ON \
          -D BUILD_TBB=ON \
          -D BUILD_TESTS=OFF \
          -D WITH_EIGEN=OFF \
          -D WITH_V4L=ON \
          -D WITH_LIBV4L=ON \
          -D WITH_VTK=OFF \
          -D OPENCV_ENABLE_NONFREE=ON \
          -D INSTALL_C_EXAMPLES=OFF \
          -D INSTALL_PYTHON_EXAMPLES=OFF \
          -D BUILD_NEW_PYTHON_SUPPORT=ON \
          -D BUILD_opencv_python3=TRUE \
          -D OPENCV_GENERATE_PKGCONFIG=ON \
          -D BUILD_EXAMPLES=OFF ..
				
			
  • 會花 1-2 hrs 時間來 build
				
					  $ cd ~/opencv/build
  $ make -j4
  $ sudo make install
  $ sudo ldconfig
  $ make clean
  $ sudo apt-get update
				
			
  • SBC 樹莓派關機,取出 microSD 卡,編輯在 system-boot section 的 config.txt,在 enable_uart=1 行之前加入 start_x=1
				
					  $ sudo apt install ffmpeg
  $ ffmpeg -f video4linux2 -s 640x480 -i /dev/video0 -ss 0:0:2 -frames 1 capture_test.jpg
				
			
  • 再安裝額外相依套件
				
					  $ sudo apt install ros-noetic-cv-camera
				
			

3. [Remote PC] 安裝額外相依套件

				
					$ sudo apt install ros-noetic-image-transport ros-noetic-image-transport-plugins ros-noetic-cv-bridge ros-noetic-vision-opencv python3-opencv libopencv-dev ros-noetic-image-proc ros-noetic-cv-camera ros-noetic-camera-calibration 
				
			

C8.2. 攝影機校準 Calibration #

校準 camera 是自動駕駛很重要的步驟,以下介紹如何簡單地逐步校準 camera。

C8.2.1. 攝影機影像校準 #

使用 Gazebo 模擬時,不需要校準攝影機

補充資料:在實體 TurtleBot3 上校準攝影機影像 #

 1. 在 Remote PC 啟動 roscore

				
					$ roscore
				
			

2. 在 SBC 上啟動 camera

				
					 $ roslaunch turtlebot3_autorace_camera raspberry_pi_camera_publish.launch
				
			

3. 在 Remote PC 上執行 rqt_image_view

				
					 $ rqt_image_view
				
			
noetic rpi rqt image view
rqt_image view

C8.2.2. camera 內部參數校準 #

使用 Gazebo 模擬時,不需要校準攝影機內部參數

補充資料: 如何在實體 TB3 做攝影機內部參數校準 #

 在 A4 尺寸的紙張上印出用於 Camera 內部參數校準的棋盤。

  • 棋盤檔位於 turtlebot3_autorace_camera/data/checkerboard_for_calibration.pdf
  • 修改 turtlebot3_autorace_camera/launch/intrinsic_camera_calibration.launch 檔內的參數值。
  • camera 校準的詳細資訊,可參考 ROS Wiki 的 Camera Calibration 手冊
autorace checkerboard
棋盤

1. 在 Remote PC 啟動 roscore

				
					$ roscore
				
			

2. 在 SBC 啟動 camera

				
					$ roslaunch turtlebot3_autorace_camera raspberry_pi_camera_publish.launch
				
			

3. 在 Remote PC 執行 camera 內部校準啟動檔

				
					$ roslaunch turtlebot3_autorace_camera intrinsic_camera_calibration.launch mode:=calibration
				
			

4. 使用棋盤紙來校準 camera,點擊 CALIBRATE

noetic rpi before intrinsic calibration

5. 點擊 SAVE 來儲存校準後的資料

noetic rpi after intrinsic calibration

6. 在 /tmp 資料夾下會新增一個 calibrationdata.tar.gz 資料夾

noetic rpi calibration data tar gz

7. 從 calibrationdata.tar.gz 內抽取出 ost.yaml 檔

noetic rpi ost yaml file
ost_yaml
noetic rpi ost yaml
Intrinsic Calibration Data in ost.yaml

8. 從 ost.yaml 內複製數據,貼到 camerav2_320x240_30fps.yaml 檔內

noetic rpi camerav2 yaml
ocamerav2_320x240_30fps.yaml
Intrinsic Calibration Data in camerav2_320x240_30fps.yaml

C8.2.3. camera 外部參數校準 #

1. 在 Remote PC 開新的 terminal 啟動 Gazebo

				
					$ roslaunch turtlebot3_gazebo turtlebot3_autorace_2020.launch
				
			

2. 開新的 terminal 啟動內部攝影機校準節點

				
					$ roslaunch turtlebot3_autorace_camera intrinsic_camera_calibration.launch
				
			

3. 開新的 terminal 啟動外部攝影機校準節點

				
					$ roslaunch turtlebot3_autorace_camera extrinsic_camera_calibration.launch mode:=calibration
				
			

4. 在 Remote PC 執行 rqt

				
					$ rqt
				
			

5. 點擊 plugins > visualization > Image view,新增二個攝影機視角圖的視窗

6. 在兩個視窗分別選擇 /camera/image_extrinsic_calib/compressed topic 及 /camera/image_projected_compensated topic

  • 兩個視窗其中一個將顯示紅色梯形影像,另一個將顯示地面投射視圖(鳥瞰視圖)。
左圖 ..compressed topic,右圖 ..compensated topic

7. 在 Remote PC 上執行 rqt_reconfigure

				
					$ rosrun rqt_reconfigure rqt_reconfigure
				
			

8. 調整在 /camera/image_projection 和 /camera/image_compensation_projection 的參數

  • 更改 /camera/image_projection 的參數值,會影響 /camera/image_extrinsic_calib/compressed topic
  • 內部攝影機校準將會修改被紅色梯形所包圍內的影像
rqt_reconfigure

9. 之後覆寫調整的數值到 yaml 檔,位於 turtlebot3_autorace_camera/calibration/extrinsic_calibration/ 目錄下。這會儲存現有校準參數值,以備之後載入。

noetic compensation yaml
../calibration/extrinsic_calibration/compensation.yaml
noetic projection yaml
../calibration/extrinsic_calibration/projection.yaml

補充資料: 如何在實體 TurtleBot3 做攝影機外部參數校準 #

1. 在 Remote PC 啟動 roscore

				
					$ roscore
				
			

2. 在 SBC 啟動 camera

				
					$ roslaunch turtlebot3_autorace_camera raspberry_pi_camera_publish.launch
				
			

3. 在 Remote PC 輸入指令

				
					$ roslaunch turtlebot3_autorace_camera intrinsic_camera_calibration.launch mode:=action
				
			

4. 在 Remote PC 執行 camera 外部校準啟動檔

				
					$ roslaunch turtlebot3_autorace_camera extrinsic_camera_calibration.launch mode:=calibration
				
			

5. 在 Remote PC 執行 rqt

				
					$ rqt
				
			

6. 點擊 plugins > visualization > Image view,可以新增多個攝影機視角圖的視窗

7. 在兩個視窗分別選擇 /camera/image_extrinsic_calib/compressed topic 及 /camera/image_projected_compensated topic

  • 兩個視窗其中一個將顯示紅色矩形框影像,另一個將顯示地面投射視圖(鳥瞰視圖)。
左圖 ..compressed topic,右圖 ..compensated topic

8. 在 Remote PC 上執行 rqt_reconfigure

				
					$ rosrun rqt_reconfigure rqt_reconfigure
				
			

9. 調整在 /camera/image_projection 和 /camera/image_compensation_projection 的參數

  • 更改 /camera/image_projection 的參數值,會影響 /camera/image_extrinsic_calib/compressed topic
  • 內部攝影機校準將會轉換被紅色矩形所包圍的影像,然後呈現為從車道上方所看到的影像
rqt_reconfigure
參數修改後的結果

C8.2.4. 檢查校準的結果 #

在完成所有校準後,請在 Remote PC 逐步的執行以下指令,來檢查校準結果。

1. 關閉全部 terminal

2. 開新的 terminal 執行 Autorace Gazebo simulation。roscore 會在 roslaunch 指令啟動時自動執行

				
					$ roslaunch turtlebot3_gazebo turtlebot3_autorace_2020.launch
				
			

3. 開新的 terminal 啟動內部攝影機校準節點

				
					$ roslaunch turtlebot3_autorace_camera intrinsic_camera_calibration.launch
				
			

4. 開新的 terminal 啟動外部攝影機校準節點

				
					$ roslaunch turtlebot3_autorace_camera extrinsic_camera_calibration.launch
				
			

5. 開新的 terminal 執行 rqt_image_viewer

				
					$ rqt_image_view
				
			

6. 如校準設定成功,則選擇 /camera/image_projected_compensated topic 時,鳥瞰視野會出現如下圖。

noetic camera calibration rqt image view

補充資料: 如何在實體 TB3 檢查校準結果 #

當完成了全部 camera 校準過程(camera 影像校準、內部參數校準、外部參數校準)後,請確認校準結果都已經套用在 camera 上。以下過程敘述影像辨識的設定。

1. 在 Remote PC 啟動 roscore

				
					$ roscore
				
			

2. 在 SBC 啟用 camera

				
					$ roslaunch turtlebot3_autorace_camera raspberry_pi_camera_publish.launch
				
			

3. 在 Remote PC 執行 camera 內部校準啟動檔

				
					$ roslaunch turtlebot3_autorace_camera intrinsic_camera_calibration.launch mode:=action
				
			

4. 在 Remote PC 開新 terminal,下指令

				
					$ roslaunch turtlebot3_autorace_camera extrinsic_camera_calibration.launch mode:=action
				
			

5. 在 Remote PC 執行 rqt

				
					$ rqt
				
			
rqt_reconfigure

現在,以下的說明將主要用來調整物體辨識的 feature detector / color filter (特徵檢測器/濾色器)。之後的每一次調整都是彼此獨立的。不過如果要對每個參數依序做調整,請確認先做好當下這個參數的調整,然後再繼續做下一個參數的調整。

C8.3. Lane Detection 賽道偵測 #

在 Remote PC 執行的 Lane detection 賽道偵測套件包,它接收從 (1)TB3 攝影機,或是 (2)Gazebo 模擬,傳來的影像,做賽道偵測後,然後驅動 TB3 沿賽道行駛。以下指令說明如何透過 rqt 做賽道偵測及校準。

1. 將 TB3 放到賽道上,在黃色及白色的車道線之間.

2. 開新的 terminal 執行 Autorace Gazebo simulation。roscore會在 roslaunch 指令啟動時自動執行

				
					$ roslaunch turtlebot3_gazebo turtlebot3_autorace_2020.launch
				
			

3. 開新的 terminal 啟動內部攝影機校準節點

				
					$ roslaunch turtlebot3_autorace_camera intrinsic_camera_calibration.launch
				
			

4. 開新的 terminal 啟動外部攝影機校準節點

				
					$ roslaunch turtlebot3_autorace_camera extrinsic_camera_calibration.launch
				
			

5. 開新的 terminal 啟動 lane detection calibration 賽道偵測校準節點

				
					$ roslaunch turtlebot3_autorace_detect detect_lane.launch mode:=calibration
				
			

6. 開新的 terminal 執行 rqt

				
					$ rqt
				
			

7. 選擇 Plugins > Visualization > Image view,啟動 rqt image viewer,可同時啟用多個 rqt plugin。

8. 在每個 image viewer 分別顯示三個 topics

  • /detect/image_lane/compressed
noetic detect image lane
  • /detect/image_yellow_lane_marker/compressed: 黃色範圍顏色的過濾影像圖
noetic detect yellow lane
  • /detect/image_white_lane_marker/compressed: 白色範圍顏色的過濾影像圖
noetic detect white lane

9. 開新的 terminal 執行 rqt_reconfigure

				
					$ rosrun rqt_reconfigure rqt_reconfigure
				
			

10. 點擊 detect_lane,然後調整參數,以便正確過濾黃色和白色。

noetic lane reconfigure

11. 開啟在 turtlebot3_autorace_detect/param/lane/ 下的 lane.yaml 檔。你需要將修改後的值覆寫到此檔內。這會使 camera 在以後啟動時,就會使用你所修改的參數。

noetic lane yaml
Modified lane.yaml file

12. 關閉 rqt_reconfiguredetect_lane terminal

13. 開新的 terminal 啟動 lane detect node 不用加 calibration 選項

				
					$ roslaunch turtlebot3_autorace_detect detect_lane.launch
				
			

14. 開新的 terminal 啟動以下節點,來開始 lane following 車道跟隨動作。

				
					$ roslaunch turtlebot3_autorace_driving turtlebot3_autorace_control_lane.launch
				
			

補充資料: 在實體 TB3 上執行賽道偵測 Lane Detection #

Lane detection 賽道偵測套件可讓 TB3 不受外部干擾,在兩條車道線內行走。
以下的步驟描述,如何使用 lane detection 賽道偵測功能及透過 rqt 來校準 camera。

1. 將 TB3 放到賽道上,在黃色及白色的車道線之間.

2. 在 Remote PC 啟動 roscore

				
					$ roscore
				
			

3. 在 SBC 啟用 camera

				
					$ roslaunch turtlebot3_autorace_camera raspberry_pi_camera_publish.launch
				
			

4. 在 Remote PC 執行 camera 內部校準啟動檔

				
					$ roslaunch turtlebot3_autorace_camera intrinsic_camera_calibration.launch mode:=action
				
			

5. 在 Remote PC 執行 camera 外部校準啟動檔

				
					$ roslaunch turtlebot3_autorace_camera extrinsic_camera_calibration.launch mode:=action
				
			

6. 在 Remote PC 執行 lane detection launch 檔

				
					$ roslaunch turtlebot3_autorace_detect detect_lane.launch mode:=calibration
				
			

7. 在 Remote PC 執行 rqt

				
					$ rqt
				
			

8. 點擊 plugins > visualization > Image view,可以新增多個攝影機視角圖的視窗

9. 在新增的三個視窗分別選擇 topics: /detect/image_yellow_lane_marker/compressed, /detect/image_lane/compressed, /detect/image_white_lane_marker/compressed

  • 左側(黃線)及右側(白線)視窗,會顯示過濾後的影像。中間則是 TB3 相機的鳥瞰圖。視窗位置可自行調整。
noetic rpi before detect lane
左圖 黃色,中圖 白色,右圖 鳥瞰影像

10. 在 Remote PC 執行 rqt_reconfigure

				
					$ rosrun rqt_reconfigure rqt_reconfigure
				
			

11. 點擊 Detect Lane,然後調整參數來做車道線的顏色過濾

noetic rpi detect lane param
List of Detect Lane Parameters
noetic rpi after detect lane
Filtered Image after adjusting parameters at rqt_reconfigure

12. 開啟在 turtlebot3_autorace_detect/param/lane/ 下的 lane.yaml 檔。你需要將修改後的值覆寫到此檔內。這會使 camera 在以後啟動時,就會使用你所修改的參數。

noetic rpi lane yaml
Modified lane.yaml file

13. 關閉 rqt_reconfigureturtlebot3_autorace_detect_lane terminal

14. 在 Remote PC 開新 terminal 輸入

				
					$ roslaunch turtlebot3_autorace_detect detect_lane.launch mode:=action
				
			

15. 檢查輸出的結果是否正確

  • 在 Remote PC 開新 terminal 輸入
				
					$ roslaunch turtlebot3_autorace_driving turtlebot3_autorace_control_lane.launch
				
			
  • 在 Remote PC 開新 terminal 輸入
				
					$ roslaunch turtlebot3_bringup turtlebot3_robot.launch
				
			

16. 輸入這些指令後,TB3 會啟動開始運行

C8.4. 交通號誌 Traffic Sign 偵測 #

TB3 的 node 使用 SIFT algorithm 演算法來偵測交通號誌,比較原始的影像跟攝影機的影像。當 TB3 在賽道上行駛時,會執行已編程好的程序。請遵照下列步驟來使用 Traffic sign detection。

1. 開新的 terminal 執行 Autorace Gazebo simulation。roscore會在 roslaunch 指令啟動時自動執行

				
					$ roslaunch turtlebot3_gazebo turtlebot3_autorace_2020.launch
				
			

2. 開新的 terminal 執行 teleoperation node,會驅動 TB3 沿賽道行駛,直到攝影機能夠清楚看到交通號誌的地方就停止。

				
					$ roslaunch turtlebot3_teleop turtlebot3_teleop_key.launch
				
			

3. 開新的 terminal 執行 rqt_image_view

				
					$ rqt_image_view
				
			

4. 選擇 /camera/image_compensated topic 來顯示攝影機影像

5. 從 rqt_image_view 抓取每個交通號誌影像,及切掉無用的影像部分。為了能有最好的效果,建議使用在賽道上看到的原始交通號誌影像檔。

6. 儲存影像到 turtlebot3_autorace_detect package 的 /turtlebot3_autorace_2020/turtlebot3_autorace_detect/image/,記住檔名要跟原始碼用的檔名要一樣。

  • 預設檔名: construction.png, intersection.png, left.png, right.png, parking.png, stop.png, tunnel.png

7. 開新的 terminal 執行 camera 內部校準啟動檔

				
					$ roslaunch turtlebot3_autorace_camera intrinsic_camera_calibration.launch
				
			

8. 開新的 terminal 執行 camera 外部校準啟動檔

				
					$ roslaunch turtlebot3_autorace_camera extrinsic_camera_calibration.launch
				
			

9. 開新的 terminal 執行 traffic sign detection node

  • mission 引數部分需要輸入對應的任務名稱,有 intersection, construction, parking, level_crossing, tunnel。
  • 取代 SELECT_MISSION 關鍵字為上面的任務名稱之一
				
					$ roslaunch turtlebot3_autorace_detect detect_sign.launch mission:=SELECT_MISSION
				
			

10. 開新的 terminal 執行 rqt image view plugin

				
					$ rqt_image_view
				
			

11. 從下拉選單選擇 /detect/image_traffic_sign/compressed。螢幕上會顯示交通號誌偵測結果。

noetic detect intersection
Detecting the Intersection sign when mission:=intersection
noetic detect left
Detecting the Left sign when mission:=intersection
noetic detect right
Detecting the Right sign when mission:=intersection
noetic detect construction
Detecting the Construction sign when mission:=construction
noetic detect parking
Detecting the Parking sign when mission:=parking
noetic detect level crossing
Detecting the Level Crossing sign when mission:=level_crossing
noetic detect tunnel
Detecting the Tunnel sign when mission:=tunnel

C8.5. AutoRace 關卡任務說明 #

C8.5.1. 第一關: Traffic Light 紅綠燈 #

AutoRace 第一關是 Traffic Light 紅綠燈。TurtleBot3 要判斷紅綠燈後開始比賽。

C8.5.1.1. 紅綠燈偵測 #

1. 開新的 terminal 執行 Autorace Gazebo simulation。roscore會在 roslaunch 指令啟動時自動執行

				
					$ roslaunch turtlebot3_gazebo turtlebot3_autorace_2020.launch
				
			

2. 開新的 terminal 啟動內部攝影機校準節點

				
					$ roslaunch turtlebot3_autorace_camera intrinsic_camera_calibration.launch
				
			

3. 開新的 terminal 啟動外部攝影機校準節點

				
					$ roslaunch turtlebot3_autorace_camera extrinsic_camera_calibration.launch
				
			

4. 開新的 terminal 啟動 traffic light detection node 要加上 calibration 選項

				
					$ roslaunch turtlebot3_autorace_detect detect_traffic_light.launch mode:=calibration
				
			

5. 開新的 terminal 執行 rqt,開 4 個 rqt_image_view plugin

				
					$ rqt
				
			

6. 選擇 4 個 topics: /detect/image_red_light, /detect/image_yellow_light, /detect/image_green_light, /detect/image_traffic_light

noetic detect traffic light green
Detecting the Green light. The image on the right displays /detect/image_green_light topic.
noetic detect traffic light yellow
Detecting the Yellow light. The image on the right displays /detect/image_yellow_light topic.
noetic detect traffic light red
Detecting the Red light. The image on the right displays /detect/image_red_light topic.

7. 開新的 terminal 執行 rqt_reconfigure

				
					$ rosrun rqt_reconfigure rqt_reconfigure
				
			

8. 在左邊區域選擇 detect_traffic_light,適當的調整參數,以便紅綠燈顏色可以清楚偵測並分辨。

noetic traffic light reconfigure
Traffic light reconfigure

9. 開啟 traffic_light.yaml 檔,位於 turtlebot3_autorace_detect/param/traffic_light/

noetic traffic light yaml

10. 將調整後的數值覆寫,然後存檔

C8.5.1.2. 測試紅綠燈偵測 #

1. Ctrl + C 關閉所有 terminal

2. 開新的 terminal 執行 Autorace Gazebo simulation。roscore會在 roslaunch 指令啟動時自動執行

				
					$ roslaunch turtlebot3_gazebo turtlebot3_autorace_2020.launch
				
			

3. 開新的 terminal 啟動內部攝影機校準節點

				
					$ roslaunch turtlebot3_autorace_camera intrinsic_camera_calibration.launch
				
			

4. 開新的 terminal 啟動外部攝影機校準節點

				
					$ roslaunch turtlebot3_autorace_camera extrinsic_camera_calibration.launch
				
			

5. 開新的 terminal 啟動 traffic light detection node

				
					$ roslaunch turtlebot3_autorace_detect detect_traffic_light.launch
				
			

6. 開新的 terminal 執行 rqt_image_view

				
					$ rqt_image_view
				
			

7. 檢查 topics: /detect/image_red_light, /detect/image_yellow_light, /detect/image_green_light

C8.5.1.3. 如何進行紅綠燈任務 #

1. Ctrl + C 關閉所有 terminal

2. 開新的 terminal 執行 Autorace Gazebo simulation。roscore會在 roslaunch 指令啟動時自動執行

				
					$ roslaunch turtlebot3_gazebo turtlebot3_autorace_2020.launch
				
			

3. 開新的 terminal 啟動內部攝影機校準節點

				
					$ roslaunch turtlebot3_autorace_camera intrinsic_camera_calibration.launch
				
			

4. 開新的 terminal 啟動 autorace core node,需要加上 mission 任務名稱

				
					$ roslaunch turtlebot3_autorace_core turtlebot3_autorace_core.launch mission:=traffic_light
				
			

5. 開新的 terminal 輸入以下指令。這會透過將 decided_mode 設為 3 ,來準備執行 traffic light 任務。

				
					$ rostopic pub -1 /core/decided_mode std_msgs/UInt8 "data: 3"
				
			

6. 啟動 Gazebo mission node

				
					$ roslaunch turtlebot3_autorace_core turtlebot3_autorace_mission.launch
				
			

C8.5.2. 第二關: Intersection 左右轉 #

AutoRace 第 2 關是 Intersection 左右轉。TB3 在 T 字路口,要辨識特定的轉彎號誌(左轉或右轉),依照指示轉向。

C8.5.2.1. 如何進行 Intersection 左右轉任務 #

1. Ctrl + C 關閉所有 terminal

2. 開新的 terminal 執行 Autorace Gazebo simulation。roscore會在 roslaunch 指令啟動時自動執行

				
					$ roslaunch turtlebot3_gazebo turtlebot3_autorace_2020.launch
				
			

3. 開新的 terminal 啟動內部攝影機校準節點

				
					$ roslaunch turtlebot3_autorace_camera intrinsic_camera_calibration.launch
				
			

4. 開新的 terminal 啟動 keyboard teleoperation node。

控制 TB3 沿賽道行駛到 T 字路口號誌前停下來

				
					$ roslaunch turtlebot3_teleop turtlebot3_teleop_key.launch
				
			

5. 開新的 terminal 啟動 autorace core node 要加上任務名稱

				
					$ roslaunch turtlebot3_autorace_core turtlebot3_autorace_core.launch mission:=intersection
				
			

6. 開新的 terminal 啟動 Gazebo mission node

				
					$ roslaunch turtlebot3_autorace_core turtlebot3_autorace_mission.launch
				
			

7. 開新的 terminal 輸入以下指令。這會透過將 decided_mode 設為 2 ,來準備執行 intersection 任務

				
					$ rostopic pub -1 /core/decided_mode std_msgs/UInt8 "data: 2"
				
			

C8.5.3. 第三關: Construction/Obstacles 避障 #

AutoRace 第三關 Construction/Obstacles 避障。TB3 行駛時須避開賽道上的施工障礙物。

C8.5.3.1. 如何進行 Construction/Obstacles 避障任務 #

1. Ctrl + C 關閉所有 terminal

2. 開新的 terminal 執行 Autorace Gazebo simulation。roscore會在 roslaunch 指令啟動時自動執行

				
					$ roslaunch turtlebot3_gazebo turtlebot3_autorace_2020.launch
				
			

3. 開新的 terminal 啟動內部攝影機校準節點

				
					$ roslaunch turtlebot3_autorace_camera intrinsic_camera_calibration.launch
				
			

4. 開新的 terminal 啟動 keyboard teleoperation node。

控制 TB3 沿賽道行駛到 Construction 施工號誌前停下來

				
					$ roslaunch turtlebot3_teleop turtlebot3_teleop_key.launch
				
			

5. 開新的 terminal 啟動 autorace core node 要加上任務名稱

				
					$ roslaunch turtlebot3_autorace_core turtlebot3_autorace_core.launch mission:=construction
				
			

6. 開新的 terminal 輸入以下指令。這會透過將 decided_mode 設為 2 ,來準備執行避障任務。

				
					$ rostopic pub -1 /core/decided_mode std_msgs/UInt8 "data: 2"
				
			

C8.5.4. 第四關: Parking 停車 #

AutoRace 第四關 Parking 停車。TB3 偵測停車號誌,自行開入空置的停車格內。

C8.5.4.1. 如何執行 Parking 停車任務 #

1. Ctrl + C 關閉所有 terminal

2. 開新的 terminal 執行 Autorace Gazebo simulation。roscore會在 roslaunch 指令啟動時自動執行

				
					$ roslaunch turtlebot3_gazebo turtlebot3_autorace_2020.launch
				
			

3. 開新的 terminal 啟動內部攝影機校準節點

				
					$ roslaunch turtlebot3_autorace_camera intrinsic_camera_calibration.launch
				
			

4. 開新的 terminal 啟動 keyboard teleoperation node。

控制 TB3 沿賽道行駛到 Parking 號誌前停下來

				
					$ roslaunch turtlebot3_teleop turtlebot3_teleop_key.launch
				
			

5. 開新的 terminal 啟動 autorace core node 要加上任務名稱

				
					$ roslaunch turtlebot3_autorace_core turtlebot3_autorace_core.launch mission:=parking
				
			

6. 開新的 terminal 啟動 Gazebo mission node

				
					$ roslaunch turtlebot3_autorace_core turtlebot3_autorace_mission.launch
				
			

7. 開新的 terminal 輸入以下指令。這會透過將 decided_mode 設為 2 ,來準備執行 parking 任務

				
					$ rostopic pub -1 /core/decided_mode std_msgs/UInt8 "data: 2"
				
			

C8.5.5. 第五關: Level Crossing/STOP Bar 柵欄 #

AutoRace 第五關 Level Crossing /STOP Bar 柵欄。TB3 必須偵測 STOP 號誌,當柵欄放下時停止等待,當柵欄升起時通過。

C8.5.5.1. 柵欄升降偵測 Level Crossing Detection #

1. Ctrl + C 關閉所有 terminal

2. 開新的 terminal 執行 Autorace Gazebo simulation。roscore會在 roslaunch 指令啟動時自動執行

				
					$ roslaunch turtlebot3_gazebo turtlebot3_autorace_2020.launch
				
			

3. 開新的 terminal 啟動內部攝影機校準節點

				
					$ roslaunch turtlebot3_autorace_camera intrinsic_camera_calibration.launch
				
			

4. 開新的 terminal 啟動外部攝影機校準節點

				
					$ roslaunch turtlebot3_autorace_camera extrinsic_camera_calibration.launch
				
			

5. 開新的 terminal 啟動 level crossing detection node 要加上 calibration 選項

				
					$ roslaunch turtlebot3_autorace_detect detect_level_crossing.launch mode:=calibration
				
			

6. 開新的 terminal 執行 rqt,開 2 個 rqt_image_view plugin 視窗

				
					$ rqt
				
			

7. 選擇2 個 topics: /detect/image_level_color_filtered/compressed, /detect/image_level/compressed

noetic detect level

8. 開新的 terminal 執行 rqt_reconfigure

				
					$ rosrun rqt_reconfigure rqt_reconfigure
				
			

9. 在左邊區域選擇 detect_level_crossing,調整參數以便增強柵欄偵測。

noetic level reconfigure

10. 開啟 level.yaml 檔,位於 turtlebot3_autorace_detect/param/level/

noetic level yaml

11. 將調整後的數值覆寫,然後存檔

C8.5.5.2. 測試 柵欄升降偵測 #

1. Ctrl + C 關閉所有 terminal

2. 開新的 terminal 執行 Autorace Gazebo simulation。roscore會在 roslaunch 指令啟動時自動執行

				
					$ roslaunch turtlebot3_gazebo turtlebot3_autorace_2020.launch
				
			

3. 開新的 terminal 啟動內部攝影機校準節點

				
					$ roslaunch turtlebot3_autorace_camera intrinsic_camera_calibration.launch
				
			

4. 開新的 terminal 啟動外部攝影機校準節點

				
					$ roslaunch turtlebot3_autorace_camera extrinsic_camera_calibration.launch
				
			

5. 開新的 terminal 啟動 level crossing detection node

				
					$ roslaunch turtlebot3_autorace_detect detect_level_crossing.launch
				
			

6. 開新的 terminal 執行 rqt_image_view

				
					$ rqt_image_view
				
			

7. 檢查 topics: /detect/image_level/compressed

C8.5.5.3. 如何進行 Level Crossing 柵欄任務 #

1. Ctrl + C 關閉所有 terminal

2. 開新的 terminal 執行 Autorace Gazebo simulation。roscore會在 roslaunch 指令啟動時自動執行

				
					$ roslaunch turtlebot3_gazebo turtlebot3_autorace_2020.launch
				
			

3. 開新的 terminal 啟動內部攝影機校準節點

				
					$ roslaunch turtlebot3_autorace_camera intrinsic_camera_calibration.launch
				
			

4. 開新的 terminal 啟動 keyboard teleoperation node。

控制 TB3 沿賽道行駛到 STOP 交通號誌前停下來

				
					$ roslaunch turtlebot3_teleop turtlebot3_teleop_key.launch
				
			

5. 開新的 terminal 啟動 autorace core node,需要加上 mission 任務名稱

				
					$ roslaunch turtlebot3_autorace_core turtlebot3_autorace_core.launch mission:=level_crossing
				
			

6. 開新的 terminal 啟動 Gazebo mission node

				
					$ roslaunch turtlebot3_autorace_core turtlebot3_autorace_mission.launch
				
			

7. 開新的 terminal 輸入以下指令。這會透過將 decided_mode 設為 2 ,來準備執行 level crossing 任務。

				
					$ rostopic pub -1 /core/decided_mode std_msgs/UInt8 "data: 2"
				
			

C8.5.6. 第六關: Tunnel 隧道 #

AutoRace 第六關 Tunnel 隧道。TB3 需避開在未探索隧道內的障礙物,成功的從隧道出口駛出。

C8.5.6.1. 如何進行 Tunnel 隧道任務 #

1. Ctrl + C 關閉所有 terminal

2. 開新的 terminal 執行 Autorace Gazebo simulation。roscore會在 roslaunch 指令啟動時自動執行

				
					$ roslaunch turtlebot3_gazebo turtlebot3_autorace_2020.launch
				
			

3. 開新的 terminal 啟動內部攝影機校準節點

				
					$ roslaunch turtlebot3_autorace_camera intrinsic_camera_calibration.launch
				
			

4. 開新的 terminal 啟動 keyboard teleoperation node。

控制 TB3 沿賽道行駛到 Tunnel 交通號誌前停下來

				
					$ roslaunch turtlebot3_teleop turtlebot3_teleop_key.launch
				
			

5. 開新的 terminal 啟動 autorace core node 要加上任務名稱

				
					$ roslaunch turtlebot3_autorace_core turtlebot3_autorace_core.launch mission:=tunnel
				
			

6. 開新的 terminal 輸入以下指令。這會透過將 decided_mode 設為 2 ,來準備執行 tunnel 任務

				
					$ rostopic pub -1 /core/decided_mode std_msgs/UInt8 "data: 2"