技術分享 | turtlebot3自動駕駛之識別道路

turtlebot簡介 相信很多接觸過ROS的人,對turtlebot這個機器人都不陌生。它是一款低成本、開源的個人機器人套件,有着ROS的官方支持,是ROS的標準平臺。turtlebot系列的設計有着易於購買、搭建和組裝,並且可以從ROS wiki下載官方的SDK進行二次開發,是作爲入門級不可或缺的機器人移動平臺。 turtlebot至今已經發布了三代,今天將會介紹如何以turtlebot3爲載體,在gazebo中實現自動駕駛中尋路(lane detection)功能。 file

前期準備 工欲善其事必先利其器,要想通過turtlebot3實現自動駕駛功能,首先需要安裝一些環境。本次測試是基於 ubuntu 20.04的ROS Noetic版本。 file

1.安裝turtlebot3環境 打開終端,輸入 cd ~/catkin_ws/src/ git clone https://github.com/ROBOTIS-GIT/turtlebot3.git cd turtlebot3 git clone https://github.com/ROBOTIS-GIT/turtlebot3_msgs.git git clone -b noetic-devel https://github.com/ROBOTIS-GIT/turtlebot3_autorace_2020.git git clone https://github.com/ROBOTIS-GIT/turtlebot3_simulations.git sudo apt install ros-noetic-image-transport ros-noetic-cv-bridge ros-noetic-vision-opencv python3-opencv libopencv-dev ros-noetic-image-proc 當我們完成以上環境安裝以後,編譯即可 cd ~/catkin_ws catkin_make

當我們編譯完成以後,可以嘗試啓動仿真環境。 打開終端,輸入命令 roslaunch turtlebot3_gazebo turtlebot3_autorace_2020.launch 當出現以下圖片,表示仿真環境成功安裝 file

2.相機校準 自動駕駛在很大程度上依賴於視覺處理,因此相機校準對於成功完成任務起着重要作用。在gazebo仿真環境中不需要校準相機的內參,但需要校準相機外參。注意:在實際使用中需要按照一定的步驟詳細校準相機的內外參數。 首先我們啓動仿真環境 roslaunch turtlebot3_gazebo turtlebot3_autorace_2020.launch 新開一個終端(這裏推薦使用 terminator,非常好用的一款終端,可以分屏) roslaunch turtlebot3_autorace_camera intrinsic_camera_calibration.launch 新開一個終端,輸入 roslaunch turtlebot3_autorace_camera extrinsic_camera_calibration.launch mode:=calibration 新開一個終端,輸入 rqt 然後再rqt的界面,選擇plugins > visualization > Image view。創建兩個窗口(重複操作兩次) 在左邊的窗口選擇 /camera/image_extrinsic_calib/compressed話題,在右邊的窗口選擇 /camera/image_projected_compensated話題。如下圖所示。 file 然後再次打開一個終端,輸入 rosrun rqt_reconfigure rqt_reconfigure 在窗口的左邊選擇 /camera/image_projection 和 /camera/image_compensation_projection。調整參數,然後觀察rqt的兩個窗口。直到左邊窗口的紅色線框在道路內,右邊爲道路的俯視圖。如下圖所示。 file 對應參數如圖所示。 file 當參數調好以後,不要點擊保存。找到加載參數的源文件,手動修改。在本文中,兩個參數的位置都在 ~/catkin_ws/src/turtlebot3/turtlebot3_autorace_2020/turtlebot3_autorace_camera/calibration/extrinsic_calibration/ 目錄下 在文件中找到上述文件,將對應的參數修改 file compensation.yaml文件內容 file projection.yaml文件內容

至此,在gazebo仿真環境中相機參數調節環節結束。

3.道路檢測 當我們完成相機校準以後,下一步就可以進行道路檢測了。 注意:車道檢測左側爲黃色,右側爲白色。 確保黃色車道在機器人的左側。 打開終端,輸入 roslaunch turtlebot3_gazebo turtlebot3_autorace_2020.launch 新開終端,輸入 roslaunch turtlebot3_autorace_camera intrinsic_camera_calibration.launch 新開終端,輸入 roslaunch turtlebot3_autorace_camera extrinsic_camera_calibration.launch 新開終端,輸入 roslaunch turtlebot3_autorace_detect detect_lane.launch mode:=calibration 新開終端,輸入 rqt 在rqt的界面,選擇 /detect/image_lane/compressed 話題,可以看到車道檢測的結果。如下圖所示。 file 選擇話題 /detect/image_yellow_lane_marker/compressed ,可以看到左邊黃色的線,如下圖所示。 file 但這並不是我們想要的結果,我們僅僅需要左邊的黃色的線,因此需要調節參數。 選擇話題 /detect/image_white_lane_marker/compressed 可以看到右邊白色的線,如下圖所示。 file 這也不是我們想要的結果。需要調節參數。 新開終端,輸入 rosrun rqt_reconfigure rqt_reconfigure 選擇窗口左邊的 detect_lane ,調節參數,讓左邊的黃色線只檢測到黃色,右邊的白色線變得更加飽滿。調節最終結果如下圖所示 file 調節的參數如下圖 file 同上面的操作一樣,打開源文件路徑,對應參數列表修改參數。在本文中,參數文件位於 ~/catkin_ws/src/turtlebot3/turtlebot3_autorace_2020/turtlebot3_autorace_detect/param/lane/ file lane.yaml文件內容

Tips: 線的濾色校準在實際中會因爲物理環境而變得困難,例如房間內的光線亮度等。 首先校準hue值,從低到高。 然後校準 saturation 值,從低到高 最後校準 lightness 值,從低到高。但是在源代碼中有自動調節,所以校準亮度值沒有意義。只需將其設置爲255即可。 上述所提參數校準,參考的是HSV色彩模型。 至此,道路檢測校準完成 下面開始進行仿真測試。

4.仿真 首先關閉所有的終端,然後開始測試。 roslaunch turtlebot3_gazebo turtlebot3_autorace_2020.launch

roslaunch turtlebot3_autorace_camera intrinsic_camera_calibration.launch

roslaunch turtlebot3_autorace_camera extrinsic_camera_calibration.launch

roslaunch turtlebot3_autorace_detect detect_lane.launch

roslaunch turtlebot3_autorace_driving turtlebot3_autorace_control_lane.launch

5.結語 自動駕駛是未來的一個趨勢,也是當前前沿熱門技術。Turtlebot3的自動駕駛提供了用於科研與教學的低成本,小型低速自動駕駛的一個平臺和方法,讓我們可以對自動駕駛有一個基礎的認知。 阿木實驗室致力於前沿IT科技的教育和智能裝備,讓機器人研發更高效!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章