ROS SLAM #2 Hector SLAM (2D地圖建置)

最近看的資料有點多,頭昏腦脹的^^"

大概就是如下面的影片那樣,利用RPLidar這個Laser scanner感測器,搭配Hector SLAM演算法去做地圖建置。

[安裝RPLidar driver]

硬體:RPLidar、Tegra TK1
軟體:Ubuntu 14.04、ROS Indigo

大概可以掃到的範圍是六米內,在使用前還是得先到官方網站下載SDK

Image.png

[圖一] RPLidar的樣子

官網的資料提供Windows跟Ubuntu板本的範例,同時也附上cp2102轉接晶片的driver。(在ubuntu安裝外來驅動點我)

如果原本的kernel版本裡面就有的話也可以從裡面將驅動打開就好

這是RPLidar的Driver

$ cd ~/rplidar_sdk_v1.4.5/sdk/sdk

$ make

S__9781254.jpg

[圖二] RPLidar盒子附的轉接頭

windows在這裡就不說了,然而Ubuntu的sample要build過才能執行喔(大家自己摸索吧哇哈哈)

驅動都OK之後,要記得把com port的權限改掉,否則會遇到無法從感測器獲得資訊的情況。

先確定有認到port,再改權限成666即可。

$ ls /dev/ttyUSB*

Screenshot from 2015-11-27 13_38_53.png

[圖三]

更改com port 權限

$ sudo chmod 666 /dev/ttyUSB0

再來要裝的是RPLidar 在 ROS的package,有兩種方式。

第一種:透過PPA下載

$ sudo apt-get install ros-indigo-rplidar-ros

第二種:把Github 上的 source code放到catkin_ws裡 (選擇SLAM的branch)

未命名.png

$ cd ~/catkin_ws/src

$ git clone -b slam https://github.com/robopeak/rplidar_ros

$ cd ~/catkin_ws

$ catkin_make

載好ROS的範例就可以來執行看看囉~

單純preview畫面

$ roslaunch rplidar_ros view_rplidar.launch

Screenshot from 2015-11-27 13_59_46.png
[圖四] RPLidar preview

[下載Hector SLAM]

$ cd ~/catkin_ws/src

$ git clone https://github.com/tu-darmstadt-ros-pkg/hector_slam

$ cd ~/catkin_ws

$ catkin_make

然後就可以來執行SLAM的部份

$ roslaunch rplidar_ros view_slam.launch

Screenshot from 2015-11-27 14_01_07.png

[圖五] 搭配hector slam demo

這是我自己做的Demo影片

Hector SLAM簡介

Hector = Heterogeneous Cooperating Team of Robots
成立於2008的秋天,於2010年晚期從原本的RoboFrame中的演算法移植變成ROS的型式package。
註:RoboFrame似乎是某一個機器人作業系統

用2D網格的方式,將Laser scanner的值透過tf library轉換成xy坐標。
Pm為sensor位置,其餘紅點為暫存走過的格點。
estimate估計障礙物可能的位置並且描繪,重複掃描用bilinear filtering方式不斷修正地圖。

未命名.png

[圖六] Hector SLAM原裡

感測器使用的是RPLidar,下圖是利用rqt_graph畫出的關係圖。
大致上主要的路徑已塗上顏色。
RPlidar讀資料跟SLAM演算法是不同Package,並不是寫在一起的,透過message機制傳遞資訊。(這就是ROS的優點啊!)

Node
Node                                         功能
/link2_broadcaster              ROS navigation的功能[見補充]
/link1_broadcaster               ROS navigation的功能[見補充]
/rplidarNode                           將讀到的值丟到 /scan 的這個topic
/hector_height_mapping   Hector SLAM演算法
Topic (資料型態)
Topic              Data type                               功能
/tf_static      tf2_msgs/TFMessage         ROS navigation的功能[見補充]
/tf                    tf2_msgs/TFMessage         ROS navigation的功能[見補充]
/initalpose()                                                   ROS navigation的功能[見補充]
/scan              sensor_msgs/LaserScan      Lidar讀到的值
/map               nav_msgs/OccupancyGrid  Map的值Screenshot from 2015-11-27 15_44_52.png

[圖七] node關係圖

再將hector mapping的部份拆開來會看到
Node                                          功能
hector_pose_estimation   將sensor的值轉換成imu資訊丟給tf處理。
hector_mapping                  不斷地即時更新map,並publish。
hector_map_server            儲存並畫出地圖形狀,提供查詢位置(pose)服務。
hector_trajectory_server  從TF中提取資訊,轉換成移動路徑位置。
hector_geotiff                       將所有得到的資訊整合到網格地圖(可以從rviz看到)。
imu = (Inertial Measurement Unit) 

data type:geometry_msgs
包含方位變異值(orientation)、角速度變異值(angular velocity)、線性加速度變異值(linear acceleration)主要是roll(x)與pitch(y),因為不需要考慮高度。

未命名 (1).png

[圖八] 網路上抓的,畫的比較好的圖。
[補充] ROS navigation的功能
包含tfactionlibpluginlibdynamic_reconfigure簡單來說,是ros提供用在地圖與機器人姿態之間轉換的功能。
用這些現成的工具,就可以做到定位(相對定位)的效果。

歡迎轉載分享,但是要告知並註明出處。

若有錯誤,懇請指正。

 

2017.12.25 修正branch下載的連結說明,感謝網友sunpochin的幫忙。聖誕快樂!

對「ROS SLAM #2 Hector SLAM (2D地圖建置)」的想法

  1. hector slam在没有odometry的时候,转弯如果速度过快,会导致地图方向错乱,比如本来是像东走的,但在地图上方向就完全反了,请问你有遇到这个问题么?

  2. [view_slam.launch] is neither a launch file in package [rplidar_ros] nor is [rplidar_ros] a launch file name
    The traceback for the exception was written to the log file
    請問大大,每次我在執行貓slam部份時總是會跑出這個紅字訊息,不曉得如何解決,請求大大指導

      • 大大妳好,想請教你一下,我是使用rplidar這顆激光雷達,也有確實的照上面所編寫的文章去執行,但我總是會在最後面去執行hector slam部份時,出現我[view_slam.launch] is neither a launch file in package [rplidar_ros] nor is [rplidar_ros] a launch file name
        The traceback for the exception was written to the log file錯誤代碼,我嘗試著解決後來重新下載hector slam然後去catkin_make時發現 在80%以後會出現沒有辦法run application/x-executable,這個檔的紅字錯誤訊息,想請問一下的是說,是不是因為這個錯誤導致我沒有辦法執行slam,那如果是的話我需要安裝甚指令才有辦法正確執行 application/x-executable 檔,請大大不吝嗇指教,萬分感謝妳

  3. Hello my problem is can’t not locate the hector_mapping

    i got this info
    ERROR: cannot launch node of type [hector_mapping/hector_mapping]: can’t locate node [hector_mapping] in package [hector_mapping]

    what happen for this problem??

  4. 為何我要透過PPA下載這些node或package時永遠出現

    Reading package lists… Done
    Building dependency tree
    Reading state information… Done
    E: Unable to locate package ros-groovy-laser-drivers

    是有哪邊要設定嗎?

    • “ros-groovy-laser-drivers" >>你是要下載groovy版本的package嗎?
      現在已經沒有在維護那個版本了喔,也許你可以下載相對應你版本的package
      例如:sudo apt-get install ros-indigo-laser-driver

  5. dd@dd-BM6875-BM6675-BP6375:~$ rosrun rviz rviz -d `rospack find hokuyo_node`/hokuyo_test.vcg
    [ INFO] [1486985674.620119730]: rviz version 1.11.15
    [ INFO] [1486985674.620174373]: compiled against Qt version 4.8.6
    [ INFO] [1486985674.620190326]: compiled against OGRE version 1.8.1 (Byatis)
    ERROR: the config file ‘/opt/ros/indigo/share/hokuyo_node/hokuyo_test.vcg’ is a .vcg file, which is the old rviz config format.
    New config files have a .rviz extension and use YAML formatting. The format changed
    between Fuerte and Groovy. There is not (yet) an automated conversion program.

    可以問一下為何會這樣嗎@@?
    或是有其他方法可以RUN嗎?

    • 補充一下,本人使用的Sensor是hokuyo URG-04LX

      hokuyo_node已經下載

      下面是測試

      dd@dd-BM6875-BM6675-BP6375:~$ ls -l /dev/ttyACM0
      crw-rw—- 1 root dialout 166, 0 Feb 13 04:33 /dev/ttyACM0
      dd@dd-BM6875-BM6675-BP6375:~$ sudo chmod a+rw /dec/ttyACM0
      [sudo] password for dd:
      chmod: cannot access ‘/dec/ttyACM0’: No such file or directory
      dd@dd-BM6875-BM6675-BP6375:~$ sudo chmod a+rw /dev/ttyACM0
      dd@dd-BM6875-BM6675-BP6375:~$ ls -l /dev/ttyACM0
      crw-rw-rw- 1 root dialout 166, 0 Feb 13 04:33 /dev/ttyACM0
      dd@dd-BM6875-BM6675-BP6375:~$ rostopic list
      /diagnostics
      /hokuyo_node/parameter_descriptions
      /hokuyo_node/parameter_updates
      /rosout
      /rosout_agg
      /scan

    • 1.你使用的版本太舊了,就你的log來看,使用的指令也是舊的。
      如果是hokuyo的ros package應該要這樣下指令。
      rosrun hokuyo_node hokuyo_node

      2.USB似乎沒有認到,是否檢查一下USB driver的部分呢?

    • 您好,回覆留言似乎沒辦法附圖。
      我有點不太了解您的意思,"TF如何獲得的"是指我是如何將每個座標系做連接的嗎?
      若是這個問題的話,在影片中的TF關係大概像這樣「map -> base_link -> laser」。
      1. map -> base_link 關係是由slam演算法中做連接的。
      2. base_link -> laser 關係是利用tf node中link1_broadcaster連接。
      可以看到hectormapping.launch中有一行 。
      若想看到詳細的資訊,你可以再開一個terminal下command 「rosrun tf view_frame」。

      第二個問題,"是自己拿着lidar去采集数据吗" ,對的,在本文章中我只是用手移動他。
      這個文章只是想分享如何操作出SLAM效果。
      希望有回答到您的問題 🙂 歡迎來信一起討論喔

  6. Hi everybody, i have the next problem:

    [view_slam.launch] is neither a launch file [rplidar_ros] nor is [rplidar_ros] a launch file name. The traceback for the exception was written to the log file

    i follow your steps…. help me. thank you

  7. 你好
    我想請問你roslaunch rplidar_ros view_rplidar.launch指令後
    會出現介面
    介面上是否就會直接出現當下掃描的結果嘛?
    我輸入指令後只有出現跟你一樣的介面但沒有結果式要再做神麼操作嘛?

  8. 您好!非常感謝您的分享。我是土木工程,最近困擾與“依照現地建模”想使用SLAM來進行2D的量測各個牆與牆相對的位置。這對我們工作效率提升極大。一下是我一些疑問。我的假設條件是手持測量,請問測量過程中手的抖動造成角度的變化,導致LIDAR不再是水平,進而影響到牆與牆之間相對位置的變化。Hector的tf可以識別出因為手抖動造成的角度變化並用做距離上的修正嗎?我在沒有加入Hector之前,故意傾斜LIDAR看到了2D圖面上牆與牆的位置發生明顯的變化。今天弄了很久卡在catkin make那邊,所以以上問題一直還沒實踐。謝謝!

  9. $ cd ~/catkin_ws/src
    $ git clone https://github.com/tu-darmstadt-ros-pkg/hector_slam
    $ cd ~/catkin_ws
    $ catkin_make

    請問一下 當我輸入這段指令到下載完hector_slam的套件,再回到catkin_ws裡面,再輸入catkin_make後,跑沒多久就當機了,試了好幾次,每次都是catkin_make這個會當機,會是什麼原因呢?
    不過在前面這段
    $ cd ~/catkin_ws/src
    $ git clone https://github.com/robopeak/rplidar_ros
    $ cd ~/catkin_ws
    $ catkin_make
    $ roslaunch rplidar_ros view_rplidar.launch
    是正常的。
    我是用 raspberry pi3 +ros kinetic kame + ubuntu mate 16.04.2版本

  10. Hello Alyson 妳好 😀
    真感謝妳寫這篇,對我幫助很大!

    話說我也遇到這個 找不到 “view_slam.launch" 問題。

    我發現問題是這樣,雖然妳文章有寫到:
    “第二種:把Github 上的 source code放到catkin_ws裡 (選擇SLAM的branch)"

    可是當我下命令 “git clone https://github.com/robopeak/rplidar_ros" 的時候,
    git 它並不會因此而選 branch slam 來 clone, 而還是去 clone master, 所以 rpidar_ros/launch 裏面,還是不會有 view_slam.launch 這檔案。

    解決方法是: 把 “git clone https://github.com/robopeak/rplidar_ros"
    改成 “git clone -b slam https://github.com/robopeak/rplidar_ros" 用 -b slam 指定 “我要下載 slam 這個 branch".

      • 請請請, 很高興我做了一點點小貢獻。 🙂

        既然我正在打字就順便說一下我一個問題的解法,萬一有人跟我一樣 google search 找到這邊。
        我的 rplidar 插上筆電後,很高興的轉動著,但遇到了 " /dev/ttyUSB0 找不到 " 的問題。 ( ubuntu 14.04 )
        我找了一堆關於 cp210x, ubuntu kernel 的說明、安裝了、還是無效。

        最後是換用了另一條 破破爛爛的 USB 線,就找到 /dev/ttyUSB* 了,真是線不可貌相。

  11. 你好,想請問定位原理是什麼? 看了你的demo影片,當lidar移動,在電腦畫面上也跟著移動,他是如何計算移動量呢? 是透過G sensor

    • 你好,想請問定位原理是什麼? 看了你的demo影片,當lidar移動,在電腦畫面上也跟著移動,他是如何計算移動量呢? 是透過G sensor、Encoder、還是GPS?

      • 感謝回覆,我想要深入了解,只用RPLidar就可以定位的原理? 我最近剛研究SLAM這個領域,還不太熟悉。
        我用AGV雷射掃描建立地圖,雷射使用Hokuyo UST-05LA,藉由Encoder和陀螺儀定位,掃描直直的走廊,結果地圖卻歪歪斜斜的。(因為AGV使用麥輪,加上地面不平,所以encoder定位累積誤差很大。)
        如果只使用雷射來定位,不使用其他的sensor,這樣有辦法掃描建立地圖嗎? 當AGV沿著走廊平行移動,雷射要如何知道自己的移動位置呢?

  12. 好開心找到這個你寫的好詳細!這個暑假實習都在研究SLAM,但是大多都是國外的教程
    想請教版主現在在做相關的工作嗎?台灣SLAM這塊的市場是有的嗎QQ

    • 很開心有幫助到你:)
      之前是在做相關的,但現在不太相關了
      有沒有市場要從很多層面去看耶
      但我個人覺得裡面包含了許多技術,分別拆開來的話可以應用在很多地方。
      所以對於工程師的成長會是個很好的學習題材啦

  13. 大大您好,我想問一下幾個問題,
    如果我單純想先利用rplidar A1不裝驅動部的情況下有辦法做出SLAM的地圖建構嗎?
    launch裡面我需要Bypass哪一塊呢?

  14. Alyson 你好:
    我是正在學習光達的研究生,你所使用的這個RPLidar,是否能直接改參數,改成Precaster 2D laser CA113這個型號,還有光達回傳的數值是在driver裡面嗎? 謝謝

  15. 您好! 打扰了,我想利于hector_localization包中的hector_pose_estimation node 加入imu数据进行2d建图, 目前在hector_pose_estimation node输入了raw_imu(imu)和poseupdate(hector_mapping的topic),但是运行报错:"Invalid state, resetting…" 。能指点一下怎么加入imu数据吗?
    可以看一下您不加imu的tf view吗? 邮箱syst_ddb@163.com。谢谢!

  16. hi i’m studying rplidar and slam with raspberry pi3, do you run the slam on your pc or raspberry pi? and i want to know how to run slam at pc (lidar is on the raspberrypi) i modify the MASTER_PC of raspberry pi3 to my pc ip

發表留言