ROS navigation implementation: SLAM mapping (slam_gmapping) and saving (map_server)

Navigation implementation: SLAM mapping

First install the relevant ROS function package:

  • Install the gmapping package (for building maps): sudo apt install ros-<ROS version>-gmapping

  • Install the map service package (for saving and reading maps): sudo apt install ros-<ROS version>-map-server

  • Install the navigation package (for positioning and path planning): sudo apt install ros-<ROS version>-navigation

  Create a new function package and import dependencies: gmapping map_server amcl move_base, where gampping is used to build maps, map_server is used to save and read maps, amcl is used for positioning, and move_base is used for path planning

(1) Write gmapping-related launch files

Copy and modify as follows:

<launch>
<param name="use_sim_time" value="true"/>是否使用仿真时间(仿真时要设置为True)
    <node pkg="gmapping" type="slam_gmapping" name="slam_gmapping" output="screen">
      <remap from="scan" to="scan"/>设置雷达话题,前面仿真雷达设置的话题就是scan
      <param name="base_frame" value="base_footprint"/><!--底盘坐标系-->
      <param name="odom_frame" value="odom"/> <!--里程计坐标系-->
      <param name="map_update_interval" value="5.0"/>地图更新频率间隔
      <param name="maxUrange" value="16.0"/>雷达测试范围最大16m
      <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="lskip" value="0"/>
      <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="1.0"/>
      <param name="angularUpdate" value="0.5"/>
      <param name="temporalUpdate" value="3.0"/>
      <param name="resampleThreshold" value="0.5"/>
      <param name="particles" value="30"/>
      <param name="xmin" value="-50.0"/>
      <param name="ymin" value="-50.0"/>
      <param name="xmax" value="50.0"/>
      <param name="ymax" value="50.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"/>
    </node>

    <node pkg="joint_state_publisher" name="joint_state_publisher" type="joint_state_publisher" />
    <node pkg="robot_state_publisher" name="robot_state_publisher" type="robot_state_publisher" />

    <node pkg="rviz" type="rviz" name="rviz" />
    <!-- 可以保存 rviz 配置并后期直接使用-->
    <!--
    <node pkg="rviz" type="rviz" name="rviz" args="-d $(find my_nav_sum)/rviz/gmapping.rviz"/>
    -->
</launch>

(2) Start the Gazebo simulation environment and the prepared slam.launch file

(3) Add components in RVIZ

  • Add robot model RobotModel

  • Add Laserscan and set Topic topic scan

  • Add the coordinate system component TF, you can find map, odom under Fram

  • Add a map component to build a map, set a topic, and publish topic raster map data, here it is set to map

    You can see the following effect:

insert image description here

(4) After configuring in rviz, you can save the current configuration: save config as in the upper left corner, save it to the config folder of the function pack, and add parameters in the rivz startup, and it can be automatically configured after startup.

<node pkg="rviz" type="rviz" name="rviz" args="-d $find(功能包名) 功能包内的相对路径"/>

(5) Start the keyboard control node

rosrun teleop_twist_keyboard teleop_twist_keyboard.py

  Control the movement of the car and walk around the map to build a map.

SLAM mapping

  The result of the map construction is shown in the figure. The white part is the place where there are no obstacles, and the black circled part is the obstacle information.

insert image description here
(6) Save the map map_server

  If you directly close rviz and exit, the built map will disappear, so you need to write a launch file to save it

<launch>
    <arg name="filename" value="$(find mycar_nav)/map/nav" />
    <node name="map_save" pkg="map_server" type="map_saver" args="-f $(arg filename)" />
</launch>

  You can see that two files map_save.pgm and map_save.yaml are generated under the specified path

insert image description here
(7) Read map information (map_server in the map_server package)

  Create a new launch file and use map_server to call the map_save.yaml file saved in the previous step

The code example is as follows:

<launch>
    <node pkg="map_server" type="map_server" name="map_server" args="$(find 功能包名)/功能包内到yaml文件的路径"/>
</launch>

  In this way, the information we released before will be published in the form of topics. To see the visualization effect of the map, we need to use rviz. You can open rviz in the terminal and add the map plug-in. Select the topic as map to see the effect.
insert image description here

Guess you like

Origin blog.csdn.net/weixin_45205599/article/details/129739968