content
Practice 2:UOA Robotics Lab Map Building + Navigation
1. 啟動地圖
ros2 launch stage_ros2 stage.launch.py \
world:=/usr/local/share/stage/worlds/uoa_robotics_lab \
enforce_prefixes:=false
2. 檢查 topic
ros2 topic list | grep scan
ros2 topic list | grep cmd_vel
ros2 topic list | grep odom
通常可能會看到:
/robot_0/base_scan
/robot_0/cmd_vel
/robot_0/odom
3. throttle scan
ros2 run topic_tools throttle messages /robot_0/base_scan 10.0 /robot_0/base_scan_throttle
4. SLAM Toolbox 參數
把 mapper_params_stage.yaml 改成:
slam_toolbox:
ros__parameters:
use_sim_time: true
scan_topic: /robot_0/base_scan_throttle
map_frame: map
odom_frame: robot_0/odom
base_frame: robot_0/base_link
tf_buffer_duration: 30.0
5. 啟動 SLAM
ros2 launch slam_toolbox online_async_launch.py \
slam_params_file:=/home/lee/nav_class_ws/config/mapper_params_stage.yaml
6. teleop 開車建圖
ros2 run teleop_twist_keyboard teleop_twist_keyboard \
--ros-args -r cmd_vel:=/robot_0/cmd_vel
建議路線:
1. 起點原地旋轉 360 度
2. 沿著走道慢慢前進
3. 每個房間或轉角都停下來旋轉
4. 回到起點附近做 loop closure
5. 再儲存地圖
7. 儲存地圖
mkdir -p ~/nav_class_assets/maps
ros2 run nav2_map_server map_saver_cli \
-f ~/nav_class_assets/maps/uoa_lab_map
產生:
uoa_lab_map.yaml
uoa_lab_map.pgm
8. Navigation 使用新地圖
ros2 launch nav2_bringup bringup_launch.py \
use_sim_time:=true \
map:=/home/lee/nav_class_assets/maps/uoa_lab_map.yaml \
params_file:=/home/lee/nav_class_assets/nav2/nav2_stage_robot0.yaml
然後 RViz:
1. Fixed Frame = map
2. 2D Pose Estimate 設定初始位置
3. Nav2 Goal 點選目標