ROS仿真,gmapping,建图,导航


参考 https://blog.csdn.net/midi666/article/details/96277971
https://zhuanlan.zhihu.com/p/35822939
若出现依赖关系问题可以看看源,换源 https://blog.csdn.net/qq_45539458/article/details/106454421#2sourceslist_6

turtlebot

sudo apt-get install ros-kinetic-turtlebot-* --fix-missing
sudo gedit ~/.bashrc
添加

export TURTLEBOT_GAZEBO_WORLD_FILE="/opt/ros/kinetic/share/turtlebot_gazebo/worlds/playground.world"

source ~/.bashrc
或者

export TURTLEBOT_GAZEBO_WORLD_FILE="/opt/ros/kinetic/share/turtlebot_gazebo/worlds/playground.world"
roslaunch turtlebot_gazebo turtlebot_world.launch

我机器人没出来…参考https://blog.csdn.net/seeseeatre/article/details/84742357

rosdep update
sudo apt-get install python-pip
sudo pip install -U rosdep

ok,rostopic list可以查看当前系统中的话题列表

打开rviz,键盘控制

roslaunch turtlebot_rviz_launchers view_navigation.launch
roslaunch turtlebot_teleop keyboard_teleop.launch

GAZEBO里可以动了,rviz还是错误,单纯用rviz直接打开可以,查查资料https://blog.csdn.net/liweibin1994/article/details/53115639?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-4.nonecase&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-4.nonecase
左上角的Global Options下面的Fixed Frame左边的map可以改,那我知道了,看看 GAZEBO里机器人模型是base_footprint,就改成base_footprint,再看看https://zhuanlan.zhihu.com/p/35822939里面的图,勾掉所有map,点击add
在这里插入图片描述
不过还是没有显示点云,就形状,不过问题不大在这里插入图片描述

gmapping实现SLAM建图/导航

建图

打开gmapping_demo.launch,gmapping.launch.xml文件的路径前加入gmapping文件夹

roscd turtlebot_gazebo/launch/
sudo gedit gmapping_demo.launch

原来内容

<launch>
  <arg name="3d_sensor" default="$(env TURTLEBOT_3D_SENSOR)"/>  <!-- r200, kinect, asus_xtion_pro -->
  <arg name="custom_gmapping_launch_file" default="$(find turtlebot_navigation)/launch/includes/gmapping/$(arg 3d_sensor)_gmapping.launch.xml"/>
  <include file="$(arg custom_gmapping_launch_file)"/>
</launch>

改成

<launch>
  <arg name="3d_sensor" default="$(env TURTLEBOT_3D_SENSOR)"/>  <!-- r200, kinect, asus_xtion_pro -->
  <arg name="custom_gmapping_launch_file" default="$(find turtlebot_navigation)/launch/includes/gmapping/$(arg 3d_sensor)_gmapping.launch.xml"/>
  <include file="$(find turtlebot_navigation)/launch/includes/gmapping/gmapping.launch.xml"/>
</launch>

我的目录

/opt/ros/kinetic/share/turtlebot_navigation/launch/includes/gmapping
/opt/ros/kinetic/share/turtlebot_gazebo/launch
/opt/ros/kinetic/share/turtlebot_rviz_launchers/launch

开始

roslaunch turtlebot_gazebo turtlebot_world.launch
roslaunch turtlebot_gazebo gmapping_demo.launch//
roslaunch turtlebot_rviz_launchers view_navigation.launch
roslaunch turtlebot_teleop keyboard_teleop.launch

在这里插入图片描述
SLAM结束后使用如下命令保存地图,命名为myslam,文件夹先建好 /home/ycx/map/

rosrun map_server map_saver -f ~/map/myslam

TurtleBot自主导航功能

roscd turtlebot_gazebo/launch/
sudo gedit amcl_demo.launch

原来

<launch>
  <!-- Map server -->
  <arg name="map_file" default="$(env TURTLEBOT_GAZEBO_MAP_FILE)"/>
  <arg name="3d_sensor" default="$(env TURTLEBOT_3D_SENSOR)"/>  <!-- r200, kinect, asus_xtion_pro -->

  <node name="map_server" pkg="map_server" type="map_server" args="$(arg map_file)" />

  <!-- Localization -->
  <arg name="initial_pose_x" default="0.0"/>
  <arg name="initial_pose_y" default="0.0"/>
  <arg name="initial_pose_a" default="0.0"/>
  <arg name="custom_amcl_launch_file" default="$(find turtlebot_navigation)/launch/includes/amcl/$(arg 3d_sensor)_amcl.launch.xml"/> 

  <include file="$(arg custom_amcl_launch_file)">
    <arg name="initial_pose_x" value="$(arg initial_pose_x)"/>
    <arg name="initial_pose_y" value="$(arg initial_pose_y)"/>
    <arg name="initial_pose_a" value="$(arg initial_pose_a)"/>
  </include>

  <!-- Move base -->
 <include file="$(find turtlebot_navigation)/launch/includes/move_base.launch.xml"/>
</launch>

改成

<launch>
   <!-- Map server -->
   <arg name="map_file" default="$(env TURTLEBOT_GAZEBO_MAP_FILE)"/>
   <node name="map_server" pkg="map_server" type="map_server" args="$(arg map_file)" />
 
   <!-- Localization -->
   <arg name="initial_pose_x" default="0.0"/>
   <arg name="initial_pose_y" default="0.0"/>
   <arg name="initial_pose_a" default="0.0"/>
   <include file="$(find turtlebot_navigation)/launch/includes/amcl/amcl.launch.xml">
       <arg name="initial_pose_x" value="$(arg initial_pose_x)"/>
       <arg name="initial_pose_y" value="$(arg initial_pose_y)"/>
       <arg name="initial_pose_a" value="$(arg initial_pose_a)"/>
   </include>
 
   <!-- Move base -->
  <include file="$(find turtlebot_navigation)/launch/includes/move_base.launch.xml"/>
</launch>

关闭除仿真环境以外的其他节点和rviz(意思就是只保持gazebo不关,别的都关了:)

roslaunch turtlebot_gazebo amcl_demo.launch map_file:=/home/ycx/map/myslam.yaml
roslaunch turtlebot_rviz_launchers view_navigation.launch

2D Nav Goal可选择目标点

你好!关于ROS中的建图,gmapping是一个常用的SLAM(Simultaneous Localization and Mapping)算法,用于在机器人移动过程中同时进行定位和地图构建。你可以通过以下步骤来使用gmapping进行建图: 1. 首先,确保你已经安装了ROS和gmapping软件包。如果没有安装,可以通过以下命令进行安装: ``` sudo apt-get install ros-<distro>-slam-gmapping ``` 其中`<distro>`是你使用的ROS发行版名称,例如`melodic`、`noetic`等。 2. 创建一个ROS工作空间(如果你还没有创建): ``` mkdir -p ~/catkin_ws/src cd ~/catkin_ws/ catkin_make ``` 3. 下载并编译gmapping软件包: ``` cd ~/catkin_ws/src git clone https://github.com/ros-perception/slam_gmapping.git cd .. catkin_make ``` 4. 启动一个ROS核心节点: ``` roscore ``` 5. 启动你的机器人(如果你有一个真实的机器人)或者启动一个仿真环境。 6. 启动gmapping节点,并订阅机器人的传感器数据: ``` roslaunch slam_gmapping gmapping.launch ``` 7. 在另一个终端中,启动机器人的驱动程序(如果有)或者模拟机器人的运动: ``` roslaunch YOUR_ROBOT_DESCRIPTION_PACKAGE YOUR_ROBOT_DESCRIPTION.launch ``` 8. 在另一个终端中,启动RViz可视化工具,查看地图的构建过程: ``` rviz ``` 在RViz中,你可以添加一个"Map"显示来查看实时构建的地图。你还可以添加其他传感器数据的显示,如激光雷达数据。 9. 移动机器人以便gmapping能够收集足够的数据进行建图。在仿真环境中,你可以使用键盘或者发布控制指令的节点来控制机器人的移动。 10. 当你认为地图已经构建好了,你可以保存地图: ``` rosrun map_server map_saver -f my_map ``` 这将在当前目录下保存一个名为"my_map"的地图文件。 希望这些步骤能帮助到你!如果你有其他问题,请随时提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Dawn Yue

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值