--- tags: eurobot2023 --- {%hackmd BJrTq20hE %} # II. 試跑一些東西 (optional) ## <font color="orange">01. Navigate In A Static Map</font> > 參考網站:[turtlebot_gazebo/Tutorials/indigo/Make a map and navigate with it](http://wiki.ros.org/turtlebot_gazebo/Tutorials/indigo/Make%20a%20map%20and%20navigate%20with%20it) ### <font color="pink">1-1. turtlebot3 on noectic installation </font> 安裝步驟: ```= cd ~/${catkin_ws}/src sudo apt install ros-noetic-xacro git clone https://github.com/ROBOTIS-GIT/turtlebot3_msgs.git git clone https://github.com/ROBOTIS-GIT/turtlebot3.git ``` ```= cd ~/${catkin_ws}/src catkin_make ``` 修改文件,加 ```export TURTLEBOT3_MODEL=burger``` 於文末: ```= sudo nano ~/.bashrc ```  接著再裝模擬用的包: ```= sudo apt-get install ros-noetic-gazebo-ros sudo apt install ros-noetic-gazebo-ros-pkgs sudo apt-get install ros-noetic-robot-state-publisher ``` ```= cd ~/${catkin_ws}/src git clone https://github.com/ROBOTIS-GIT/turtlebot3_simulations.git ``` ```= cd ~/catkin_ws catkin_make ``` ### <font color="pink">1-2. turtlebot3 visualization </font> 以下是各 launch 的功能: ```yaml= # 用方向鍵調整機器人速度 roslaunch turtlebot3_teleop turtlebot3_teleop_key.launch # 在 rviz 中模擬 turtlebot3 roslaunch turtlebot3_fake turtlebot3_fake.launch # 在 gazebo 中看 turtlebot3 roslaunch turtlebot3_gazebo turtlebot3_empty_world.launch # gazebo 的 world 地圖 roslaunch turtlebot3_gazebo turtlebot3_world.launch # gazebo 的 house 地圖 roslaunch turtlebot3_gazebo turtlebot3_house.launch ``` #### <font color="skyblue">※ Autonomous Navigation and Obstacle Avoidance</font> > 看 turtlebot3 自動避障。 ```yaml= roslaunch turtlebot3_gazebo turtlebot3_world.launch roslaunch turtlebot3_gazebo turtlebot3_simulation.launch # 用 rviz 看 turtlebot3 雷射掃到的障礙物 roslaunch turtlebot3_gazebo turtlebot3_gazebo_rviz.launch ``` #### <font color="skyblue">※ SLAM simulation</font> > 延續上面的範例,並欣賞 SLAM 建圖。 ```yaml= sudo apt install ros-noetic-slam-gmapping ``` ```yaml= roslaunch turtlebot3_gazebo turtlebot3_world.launch # SLAM 視窗 roslaunch turtlebot3_slam turtlebot3_slam.launch slam_methods:=gmapping roslaunch turtlebot3_gazebo turtlebot3_simulation.launch ``` :::success 現在可以用 gazebo 和 rviz 去看 turtlebot3 在預設地圖上的運動和建圖了。 接著會深入一點了解它的內在。 ::: ## <font color="orange">02. gmapping (SLAM)</font> >安裝:`sudo apt install ros-noetic-gmapping` >資源包:`git clone git@github.com:ros-perception/slam_gmapping.git` ### <font color="pink">2-1. gmapping 簡介 </font> gmapping 是構建地圖的資源包,根據 LiDaR 和 Odometry 數據來生成 2D 地圖,採用粒子濾波。 其中訊息格式 LiDaR 是用 `sensor_msgs/LaserScan`,odometry 則是用 `nav_msgs/Odometry`。 frame 之間的座標轉換都是透過 tf 來完成的。在 topic 上有 `/scan` 和 `/tf` 及 `/tf_static` 。 odometry可以透過輪上的 encoder、IMU 或是視覺里程計來給出,而 gmapping 會把里程計誤差的修正發佈到 map_frame 和 odom_frame 之間的 tf 上,也就是把誤差補償在了地圖坐標系和里程計原點坐標系之間。通過這種方式來修正定位。 ### <font color="pink">2-2. gmapping parameters </font> 打開 `turtlebot3/turtlebot3_slam/config/gmapping_params.yaml`。 這邊只記錄比較重要的,就是其他大神有提到的參數啦。 * <font color="yellow">max_update_interval</font> 地圖更新速率。值越高更新越快,但消耗更多運算。 * <font color="yellow">maxUrange</font> 以車身為圓心的最大有效半徑。 實測下來這個值可以大點,否則地圖會容易偏移歪曲。 * <font color="yellow">minimumScore</font> 採用 LiDaR 的門檻分數。 值越高代表對 LiDaR 的要求更高,如果激光匹配失敗會轉去使用里程計數據。 另方面,值越低則地圖噪音會太多。 * <font color="yellow">particles</font> 決定粒子濾波中的粒子數。合適的粒子數會有高準確度和速度。 ## <font color="orange">03. map server</font> > 安裝:sudo apt install ros-noetic-map-server 提供節點來傳輸地圖數據,並允許動態生成的映射保存到文件。 我們必須提供**地圖文件(.pgm)和地圖描述文件(.yaml)**。 * <font color="yellow">map_server node</font>:讀取地圖訊息,並作為 service 給其他節點數據。 * <font color="yellow">map_saver node</font>:保存地圖數據到地圖文件。 而對應的 topic 則有兩個: * <font color="yellow">/map</font>:地圖中的柵格內容。格式為 `nav_msgs/OccupancyGrid` 。 * <font color="yellow">/map_metedata</font>:地圖描述訊息,如長寬、分辨率。格式為 `nav_msgs/MapMetaData`。 :::info 若已知地圖(無論 SLAM 或測量),機器人最好啟動就能直接加載地圖,而非每次開機都重建。 在這種情況下,就需要有一個節點來發布 /map,提供場景訊息了。 ::: ### <font color="pink">3-1. yaml description </font> ```yaml= image: testmap.png resolution: 0.1 origin: [0.0, 0.0, 0.0] occupied_thresh: 0.65 free_thresh: 0.196 negate: 0 mode: trinary ``` * <font color="yellow">image</font>: 圖檔路徑 * <font color="yellow">resolution</font>: 解析度,單位 meters / pixel * <font color="yellow">origin</font>:最左下角像素的座標。其中 yaw 為 0 表示無旋轉,正值是逆時針旋轉 * <font color="yellow">occupied_thresh</font>:占用率大於此門檻的像素會被認為已完全占用 * <font color="yellow">free_thresh</font>:占用率小於此門檻的像素會被認為是完全空閒的 * <font color="yellow">negate</font>:是否應該顛倒。 * <font color="yellow">mode</font>:預設是 TRINARY。有 TRINARY、SCALE 和 RAW 三種 ### <font color="pink">3-2. yaml value interpretation * <font color="yellow">negate</font> 預設值是 false,像素公式為 $p = 1 - x/255.0$。 黑色(0)有最高值 1,而白色(255)值是 0。 沒有障礙物佔據時為白色。 如果設成 true,則黑白顛倒,但閥值不影響。 * <font color="yellow">TRINARY (mode)</font> 輸出值三種:大於 occupied_thresh 為 100,小於 free_thresh 為 0。 其餘則輸出 -1 或 255。 * <font color="yellow">SCALE (mode)</font> 值大於 occupied_thresh 的輸出為 100,小於 free_thresh 為 0。 但介於兩門檻間的輸出會有漸層分布。 * <font color="yellow">RAW (mode)</font> 輸出每個像素的 x 值。 ### <font color="pink">3-3. 實際跑一次地圖</font> <font color="yellow">step 1. git clone</font> ```yaml= cd ${catkin_ws}/src git clone git@github.com:strawlab/navigation.git ``` 把裡面的 map_server 資料夾移出來,其他的可以先刪掉。 接著我會把用不到的東西刪掉,不刪掉也沒差。 <font color="yellow">step 2. mytest 測試用檔案</font> <font color="yellow">step 3. 修改 png 格式</font> 直接跑會有下面的錯誤訊息: ``` libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: cHRM chunk does not match sRGB ``` 以下是解決方法: ```= pip install scikit-image python -m pip install --upgrade pip python -m pip install --upgrade pillow ``` 在 /src 中新建 png_debug.py(記得更改 path): ```python= import cv2 from skimage import io path = "/home/pomelo925/POMELO/winter/src/map_server/mytest/testmap.png" image = io.imread(path) image = cv2.cvtColor(image, cv2.COLOR_RGBA2BGRA) cv2.imencode('.png',image)[1].tofile(path) ``` 接下來就執行 code 就可以讓該照片正常運行了。 <font color="yellow">step 4. 執行</font> :::warning 還不清楚在幹嘛 !!! ::: 加載自定義的地圖 ```= rosrun map_server map_server Software_Museum.yaml ```  保存當前地圖為mymap.pgn和mymap.yaml ```= rosrun map_server map_saver -f mymap ``` <font color="yellow">step 5. 創 launch 資料夾後新建 map_server.launch</font> ```xml= <launch> <arg name="map_file" default="$(find map_server)/mytest/test.yaml"/> <node pkg="map_server" name="map_server" type="map_server" args="$(arg map_file)" /> </launch> ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up