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和Gazebo,并确保ROS和Gazebo能够正常运行。 接下来,可以按照以下步骤进行操作: 1. 下载gazebo案例的房间模型,并将其保存到catkin工作空间的src目录中。 2. 在模型中添加障碍物,可以通过在模型中添加一个或多个物体来实现。可以使用ROS的模型编辑器或Gazebo提供的编辑器来添加障碍物。 3. 安装gmapping包,该包提供了建图和定位的功能。 ``` sudo apt-get install ros-<distro>-gmapping ``` 4. 在启动文件中,添加gmapping节点和机器人的初始位置。 ``` <node name="gmapping" pkg="gmapping" type="slam_gmapping" output="screen"> <param name="base_frame" value="base_link"/> <param name="odom_frame" value="odom"/> <param name="map_frame" value="map"/> <param name="map_update_interval" value="1.0"/> <param name="maxUrange" value="15.0"/> <param name="sigma" value="0.05"/> <param name="kernelSize" value="1"/> <param name="lstep" value="0.05"/> <param name="astep" value="0.05"/> <param name="iterations" value="5"/> <param name="lsigma" value="0.075"/> <param name="ogain" value="3.0"/> <param name="minimumScore" value="100"/> <param name="srr" value="0.1"/> <param name="srt" value="0.2"/> <param name="str" value="0.1"/> <param name="stt" value="0.2"/> <param name="linearUpdate" value="0.2"/> <param name="angularUpdate" value="0.1"/> <param name="temporalUpdate" value="1.0"/> <param name="resampleThreshold" value="0.5"/> <param name="particles" value="30"/> <param name="xmin" value="-5.0"/> <param name="ymin" value="-5.0"/> <param name="xmax" value="5.0"/> <param name="ymax" value="5.0"/> <param name="delta" value="0.05"/> <param name="llsamplerange" value="0.01"/> <param name="llsamplestep" value="0.01"/> <param name="lasamplerange" value="0.005"/> <param name="lasamplestep" value="0.005"/> <param name="tf_delay" value="0.5"/> <param name="got_map_topic" value="/map"/> </node> <node pkg="tf" type="static_transform_publisher" name="map_odom_broadcaster" args="0 0 0 0 0 0 map odom 100"/> <node pkg="tf" type="static_transform_publisher" name="base_laser_broadcaster" args="0 0 0.5 0 0 0 base_link laser 100"/> <node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher"> <param name="publish_frequency" type="double" value="50.0" /> </node> <node name="spawn_urdf" pkg="gazebo_ros" type="spawn_model" args="-urdf -model robot -param /robot_description -x 0.1 -y 0.1 -z 0.0"/> ``` 5. 启动Gazebo和RViz。 ``` roslaunch my_gazebo_package my_world.launch roslaunch my_robot_description my_robot_rviz.launch ``` 6. 在RViz中,设置机器人的初始位置,并启动导航。 7. 在导航过程中,可以使用ROS的随机数生成器来随机设置目标点,然后在Gazebo中添加障碍物。 ``` # 生成随机坐标 x=$(python -c "import random; print(random.uniform(-5.0, 5.0))") y=$(python -c "import random; print(random.uniform(-5.0, 5.0))") # 发布目标点 rostopic pub /move_base_simple/goal geometry_msgs/PoseStamped "header: seq: 0 stamp: secs: 0 nsecs: 0 frame_id: 'map' pose: position: x: $x y: $y z: 0.0 orientation: x: 0.0 y: 0.0 z: 0.0 w: 1.0" -1 # 在Gazebo中添加障碍物 rosservice call /gazebo/spawn_sdf_model "model_name: 'obstacle' model_xml: '<?xml version='1.0'?> <sdf version='1.4'> <model name='obstacle'> <static>true</static> <link name='link'> <collision name='collision'> <geometry> <box> <size>0.5 0.5 0.5</size> </box> </geometry> </collision> <visual name='visual'> <geometry> <box> <size>0.5 0.5 0.5</size> </box> </geometry> <material> <script> <uri>file://media/materials/scripts/gazebo.material</uri> <name>Gazebo/Red</name> </script> </material> </visual> </link> <pose>$x $y 0 0 0 0</pose> </model> </sdf>' reference_frame: 'world' initial_pose: position: x: $x y: $y z: 0.0 orientation: x: 0.0 y: 0.0 z: 0.0 w: 1.0" ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Dawn Yue

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

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

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

打赏作者

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

抵扣说明:

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

余额充值