ROS仿真,gmapping,建图,导航

目录

  • turtlebot
  • gmapping实现SLAM建图/导航
    • 建图
    • TurtleBot自主导航功能

参考 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
ROS仿真,gmapping,建图,导航_第1张图片
不过还是没有显示点云,就形状,不过问题不大ROS仿真,gmapping,建图,导航_第2张图片

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

ROS仿真,gmapping,建图,导航_第3张图片
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可选择目标点

你可能感兴趣的:(slam,ubuntu)