1. 程式人生 > >移動機器人gazebo模擬(3)—替換地圖並建圖

移動機器人gazebo模擬(3)—替換地圖並建圖

參考文章:

按照參考文章建立好地圖


然後根據如下步驟:

(1)路徑   .gazebo/models/robot_sim1 下


(2)在/usr/share/gazebo-7/worlds目錄下建立robot_sim1.world檔案,新增以下文字:

<?xml version="1.0" ?>
<sdf version="1.5">
  <world name="default">
    <include>
      <uri>model://ground_plane</uri>
    </include>
    <include>
      <uri>model://sun</uri>
    </include>
    <include>
      <uri>model://robot_sim1</uri>
    </include>
  </world>
</sdf>

這裡可能需要更改worlds資料夾的許可權:

$ sudo su
$ chmod -R 777 資料夾路徑
(3)在gazebo_ros/launch 目錄下建立名為 robot_sim1.launch的檔案,新增如下文字:
<?xml version="1.0"?>
<launch>

  <!-- We resume the logic in empty_world.launch, changing only the name of the world to be launched -->
  <include file="$(find gazebo_ros)/launch/empty_world.launch">
    <arg name="world_name" value="worlds/robot_sim1.world"/> <!-- Note: the world_name is with respect to GAZEBO_RESOURCE_PATH environmental variable -->
    <arg name="paused" value="false"/>
    <arg name="use_sim_time" value="true"/>
    <arg name="gui" value="true"/>
    <arg name="headless" value="false"/>
    <arg name="debug" value="false"/>
  </include>

</launch>

最後修改上篇部落格ros模擬建圖(2)中新建的檔案 my_world_hk.launch,將empty_world.launch替換為robot_sim1.launch

如下:(其中remap的那句語句可以修改成為/turtlebot/laser/scan 這樣資料就是hokuyo鐳射的資料了)

<launch>
  <arg name="world_file"  default="$(env TURTLEBOT_GAZEBO_WORLD_FILE)"/>

  <arg name="base"      value="$(optenv TURTLEBOT_BASE kobuki)"/> <!-- create, roomba -->
  <arg name="battery"   value="$(optenv TURTLEBOT_BATTERY /proc/acpi/battery/BAT0)"/>  <!-- /proc/acpi/battery/BAT0 --> 
  <arg name="gui"    default="true"/>
  <arg name="stacks"    value="$(optenv TURTLEBOT_STACKS hexagons)"/>  <!-- circles, hexagons --> 
  <!--arg name="3d_sensor" value="$(optenv TURTLEBOT_3D_SENSOR kinect)"/-->  <!-- kinect, asus_xtion_pro --> 

<arg name="3d_sensor" value="$(optenv TURTLEBOT_3D_SENSOR KinectHokuyo)"/>  <!-- kinect, asus_xtion_pro -->


<!--include file="$(find gazebo_ros)/launch/empty_world.launch">
    <arg name="use_sim_time" value="true"/>
    <arg name="debug" value="false"/>
    <arg name="gui" value="$(arg gui)" />
    <arg name="world_name" value="$(arg world_file)"/>
  </include-->



  <include file="$(find gazebo_ros)/launch/robot_sim1.launch">
    </include>



  <!--include file="$(find turtlebot_gazebo)/launch/includes/$(arg base).launch.xml"-->
 <include file="/home/jk/ros_sim/src/robot_hokuyo_kinect/launch/include/$(arg base).launch.xml">
   <arg name="base" value="$(arg base)"/>
    <arg name="stacks" value="$(arg stacks)"/>
    <arg name="3d_sensor" value="$(arg 3d_sensor)"/>
  </include>
  
  <node pkg="robot_state_publisher" type="robot_state_publisher" name="robot_state_publisher">
    <param name="publish_frequency" type="double" value="30.0" />
  </node>
  
  <!-- Fake laser -->
  <node pkg="nodelet" type="nodelet" name="laserscan_nodelet_manager" args="manager"/>
  <node pkg="nodelet" type="nodelet" name="depthimage_to_laserscan"
        args="load depthimage_to_laserscan/DepthImageToLaserScanNodelet laserscan_nodelet_manager">
    <param name="scan_height" value="10"/>
    <param name="output_frame_id" value="/camera_depth_frame"/>
    <param name="range_min" value="0.45"/>
    <remap from="image" to="/camera/depth/image_raw"/>
    <remap from="scan" to="/scan"/>
  </node>
</launch>

儲存後執行

roslaunch robot_hokuyo_kinect my_world_hk.launch 

發現turtlebot位置不對,(後來發現這只是特殊情況,再次重建地圖就沒有該問題了)


修改turtlebot的pose(位姿)


最後就可以根據前兩篇部落格使用gazeon和rviz進行建圖了

roslaunch robot_hokuyo_kinect my_world_hk.launch   
roslaunch robot_hokuyo_kinect gmapping_demo.launch   
roslaunch turtlebot_rviz_launchers view_navigation.launch    
roslaunch turtlebot_teleop keyboard_teleop.launch  

使用鍵盤控制機器人移動,建立地圖如下:



之後使用map_server儲存地圖

sudo apt-get install ros-kinetic-map-server
rosrun map_server map_saver -f /地址/mymap