当前位置:   article > 正文

ROS2导航SLAM建图_ros2 slam 导航

ros2 slam 导航

ROS2 导航

#1 安装

# 环境 
Ubuntu 20.04 
ROS2 Foxy
  • 1
  • 2
  • 3
# 查看本机是否已经安装 turtlrbot3
ros2 pkg list | grep turtlebot3

# You will get 
# turtlebot3
# turtlebot3_bringup
# turtlebot3_cartographer
# turtlebot3_description
# turtlebot3_example
# turtlebot3_gazebo
# turtlebot3_msgs
# turtlebot3_navigation2
# turtlebot3_node
# turtlebot3_teleop

# 安装 turtlrbot3
sudo apt install ros-foxy-turtlebot3 -y 
sudo apt install ros-foxy-gazebo-dev -y 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
# 查看本机是否已经安装 cartographer
ros2 pkg list |grep cartographer

# You will get 
# cartographer_ros
# cartographer_ros_msgs

# 安装 cartographer
sudo apt install ros-foxy-cartographer -y 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

#2 建图

#2.1 Rviz

打开新终端

  • 设置
source /opt/ros/foxy/setup.zsh

export TURTLEBOT3_MODEL=burger
  • 1
  • 2
  • 3
  • 启动
ros2 launch turtlebot3_cartographer cartographer.launch.py use_sim_time:=True
  • 1

在这里插入图片描述

#2.2 Gazebo

打开新终端

  • 设置
source /opt/ros/foxy/setup.zsh

export GAZEBO_MODEL_PATH=$GAZEBO_MODEL_PATH:`ros2 pkg prefix turtlebot3_gazebo`/share/turtlebot3_gazebo/models/

export TURTLEBOT3_MODEL=burger
  • 1
  • 2
  • 3
  • 4
  • 5
  • 启动
ros2 launch turtlebot3_gazebo turtlebot3_world.launch.py
  • 1

在这里插入图片描述

#2.3 键盘控制节点

打开新终端

  • 设置
source /opt/ros/foxy/setup.zsh

export TURTLEBOT3_MODEL=burger
  • 1
  • 2
  • 3
  • 启动
ros2 run turtlebot3_teleop teleop_keyboard
  • 1

使用键盘控制小车运动, 扫描地图数据

在这里插入图片描述

#2.4 保存地图

打开新终端

  • 设置
source /opt/ros/foxy/setup.zsh

mkdir ~/cartographer
  • 1
  • 2
  • 3
  • 启动
ros2 run nav2_map_server map_saver_cli -f ~/cartographer/map
  • 1

生成地图文件:

~/cartographer/map.pgm
~/cartographer/map.yaml
  • 1
  • 2
image: ~/cartographer/map.pgm
mode: trinary
resolution: 0.05
origin: [-1.31, -2.48, 0]
negate: 0
occupied_thresh: 0.65
free_thresh: 0.25%
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • image:图像路径
  • mode: 图像模式,默认为trinary(三进制),还有另外两个可选项scale(缩放的)和raw(原本的值)。
  • resolution:分辨率,一个栅格对应的物理尺寸,单位为m。0.05则表示一个栅格为0.05m
  • origin:地图原点位置,单位是m。
  • negate:是否反转图像
  • cooupied_thresh:占据阈值
  • free_thresh:空闲阈值

#3 导航

根据已有的地图进行导航

关闭上面的窗口

#3.1 导航

打开新终端

  • 设置
source /opt/ros/foxy/setup.zsh

export TURTLEBOT3_MODEL=burger
  • 1
  • 2
  • 3
  • 启动
// 注意 #2.4 生成的地图文件路径
cd ~/cartographer
ros2 launch turtlebot3_navigation2 navigation2.launch.py map:=map.yaml
  • 1
  • 2
  • 3

在这里插入图片描述

#3.2 Gazebo

打开新终端

  • 设置
source /opt/ros/foxy/setup.zsh

export GAZEBO_MODEL_PATH=$GAZEBO_MODEL_PATH:`ros2 pkg prefix turtlebot3_gazebo`/share/turtlebot3_gazebo/models/

export TURTLEBOT3_MODEL=burger
  • 1
  • 2
  • 3
  • 4
  • 5
  • 启动
ros2 launch turtlebot3_gazebo turtlebot3_world.launch.py
  • 1

#3.3 初始化位置

  • 点击 “2D Pose Estimate” 按钮
  • 单击机器人所在的地图中的近似点,拖动箭头指出机器人所面朝的方向(如果一次不行,就试多次)
    在这里插入图片描述

在这里插入图片描述

#3.4 设置终点

  • 单机 “ 2D Nav Goal “按钮
  • 单击地图中的特定点以设置目标位置,并将光标拖动到 TurtleBot 最后应该面对的方向
    在这里插入图片描述

紫红色的线就是规划路径
在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/正经夜光杯/article/detail/830767
推荐阅读
相关标签
  

闽ICP备14008679号