1.新建功能包
导入依赖: amcl,gmapping,map_server,move_base
2.编写gmapping节点launch文件
<launch>
<!--仿真环境下设置为true-->
<param name="use_sim_time" value="true"/>
<node pkg="gmapping" type="slam_gmapping" name="slam_gmapping" output="screen">
<!--雷达话题-->
<remap from="scan" to="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"/>
<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" args="-d $(find navigation)/config/navi.rviz"/>
<!-- 可以保存 rviz 配置并后期直接使用-->
<!--
<node pkg="rviz" type="rviz" name="rviz" args="-d $(find my_nav_sum)/rviz/gmapping.rviz"/>
-->
</launch>
3. 启动仿真环境
<!-- 将 Urdf 文件的内容加载到参数服务器 -->
<param name="robot_description" command="$(find xacro)/xacro $(find mycar_gazebo)/urdf/xacro/car.xacro" />
<!-- 启动 gazebo -->
<include file="$(find gazebo_ros)/launch/empty_world.launch" >
<!--导入写好的gazabo环境-->
<arg name="world_name" value="$(find mycar_gazebo)/worlds/box_house.world" />
</include>
<!--深度相机的点云信息要进行坐标转换-->
<node pkg="tf2_ros" type="static_transform_publisher" name="static_transform_publisher" args="0 0 0 -1.57 0 -1.57 /support /support_kinec" />
<!-- 在 gazebo 中显示机器人模型 -->
<node pkg="gazebo_ros" type="spawn_model" name="model" args="-urdf -model mycar -param robot_description" />
</launch>
4.键盘控制小车运动
rosrun teleop_twist_keyboard teleop_twist_keyboard.py
5.地图保存服务
<!--保存地图-->
<launch>
<!--对保存的文件进行封装-->
<arg name="filename" value="$(find navigation)/map/nav" />
<!--保存地图信息-->
<node name="map_save" pkg="map_server" type="map_saver" args="-f $(arg filename)"/>
</launch>
6.地图读取服务
<launch>
<arg name="map" default="nav.yaml"/>
<node name="map_server" pkg="map_server" type="map_server" args="$(find navigation)/map/$(arg map)"/>
</launch>