---
title: 'ROS rplidar'
disqus: hackmd
---
ROS SLAM Lidar
===
## Table of Contents
[TOC]
## Goals in the semester
使用光達和樹莓派製作的自走車建構2D地圖
- [x] 1. Understanding how to use ROS (Robot Operating System) on Raspberry PI.
- [x] 2. Figure out how to use Lidar as a ROS node and setup the four-wheel car.
- [x] 3. Run through the RPLidar ROS package and build the 2-D map on PC.
- [x] 4. Connect RPi and PC with SSH network--**Running ROS across multiple machines**
- [x] RPLidar ROS package
- [x] Hector_Slam package
- [x] 5. Attach Lidar to the car
- [x] 6. Achieve the following functions:
- [x] 建圖(Mapping)
- [x] 避障(Collision Avoidance)
- [x] 軌跡規劃(Path Planning)
- [ ] 導航(Navigation)
Introduction
---
Portable laser range-finders, further referred to as LIDAR, and simultaneous localization and mapping (SLAM) are an efficient method of acquiring as-built floor plans. Generating and visualizing floor plans in real-time helps the operator assess the quality and coverage of capture data. Building a portable capture platform necessitates operating under limited computational resources. Therefore, we will use RPLIDAR and Raspberry PI to mapping a room with a small autonomous car. We could use the result of mapping to do a optimize route plan for autonomouse car, such as Robotic Vacuum or Self-driving car.
 <-- Lidar A2
## RPLIDAR A2: The principle of triangulation
The principle of the trigonometric method is as shown in the figure below. The laser emits laser light. After the object is irradiated, the reflected light is received by the linear CCD. Since the laser and the detector are separated by a certain distance, according to the optical path, objects of different distances will be imaged in the CCD. On a different location. Calculated according to the triangle formula, the distance of the measured object can be derived.

Setup the enviroment for pragramming
---
* We use virtual machine to run the Ubuntu system (Linux operation system).
* Install the ROS (melodic) and build the catkin work space.
http://wiki.ros.org/ROS/Tutorials/catkin/CreateWorkspace
* Setup the Network between Raspberry Pi and PC with the tutorial in http://wiki.ros.org/ROS/NetworkSetup and http://wiki.ros.org/ROS/Tutorials/MultipleMachines to further confirm the connection.
* Using the following command to download the RPLidar ros package and Hector_Slam package in Raspberry Pi and PC.
> git clone -b master https://github.com/Slamtec/rplidar_ros
> git clone https://github.com/tu-darmstadt-ros-pkg/hector_slam.git
* Catkin_make on RPi and PC
* *We reference the ROS wiki for all the information. http://wiki.ros.org/ROS/Tutorials*
## Hecktor Slam
用2D網格的方式,將Laser scanner的值透過tf library轉換成xy坐標。
Pm為sensor位置,其餘紅點為暫存走過的格點。
estimate估計障礙物可能的位置並且描繪,重複掃描用bilinear filtering方式不斷修正地圖。
>
Diagram Flows
---
```sequence
Raspberry Pi3->Lidar: Python
Note right of Raspberry Pi3: ros
Note LEFT of 2D MAP: ros
Lidar->2D MAP : SLAM
```
Project Timeline
---
```mermaid
gantt
title Gantt Diagram
section Section
Goal decision :a1, 2019-09-20, 7d
Set-up ros and lidar package :a2,2019-09-23 , 16d
section Another
simulate in pc :2019-09-30 , 12d
another task : 14d
```
## Progress
---
9/23 : 和組員討論時間進度,以及想法[^first]
9/24 : 試著跑過lidar
**實驗室的2D平面 
9/30Slam in rplidar

這使用馬達slam的成果,好像是把它包成類似IMU的輸出值,直接丟到tf去做轉換
預計下周規劃(目前我使用其他課程運用到的車子),畫好3d模型
透過這個模型,運用gazebo,先完成模擬(比較陌生,抓3周)

目前我們的流程是:
1. 用自走車自行畫地圖
2. 根據此地圖並決定其中一個點作為坐標
3. 自走車會往目標前進,且自行規劃路線(避障)
Block Diagram of ROS

---
###
## Appendix and FAQ
:::info
**參考網站**
https://zhuanlan.zhihu.com/p/29246697
https://hollyqood.wordpress.com/2015/12/01/ros-slam-2-hector-slam-2d%E5%9C%B0%E5%9C%96%E5%BB%BA%E7%BD%AE/
https://www.itread01.com/p/452710.html
https://www.explainingcomputers.com/rasp_pi_robotics.html
鍵盤控制RPi 前進/後退/轉彎

https://www.seeedstudio.com/SDP-Mini-RPlidar-Experimental-Platform-p-2905.html (預想模型)
https://www.seeedstudio.com/blog/2019/08/05/all-you-need-to-know-about-slamtec-rplidar-mapper-and-slamware/
http://www.iceira.ntu.edu.tw/project-plans/195-robot-operating-system-ros
https://github.com/youtalk/raspimouse_ros2
(example in github)
https://zhuanlan.zhihu.com/p/62992224
###### tags: `ROS` `SLAM`
:::
## New
---
主要目的是了解ros 如何運作在多網路的架構下如何控制,物聯網的時代
整體有三台電腦,分為兩層,第一層為遠端電腦,第二層rpi用以提供姿態資料,與機上電腦用以建構地圖與反應實時狀況。再輔以ROS的Master功能,進行topic的傳輸。
在上面更改了一個節點,透過ros master 的方式去尋找第二台電腦完成記憶體不夠的運算
控制機上電腦端的rplidar_ros/launch/view_slam.launch, 刪掉<includefile="$(find rplidar_ros)/launch/rplidar.launch" />。 即刻透過ros master 方式抓到 rpi的tf資料
降低rpi 的cpu 佔有率 提高效能
成果
使用前:

使用後:

這是在同樣環境掃出來的
明顯發現圖2的邊框更明顯與正確
以光達建置出本身位置,透過hectorslam的完成位置確定
hector slam 使用2D網格的方式,將Laser scanner的值透過tf library轉換成xy坐標。
紀錄sensor位置,暫存走過的格點,以(0~1)機率的方式表示
estimate估計障礙物可能的位置並且描繪,重複掃描用bilinear filtering方式不斷修正地圖。
透過定時紀錄描繪好的地圖,並儲存成txt檔,回報地圖與位置完成路徑規劃


Dijkstra演算法

Dubins Curve

