ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

@CdyTritor , instead of installing packages from source you can use apt-get like this:

Install gmapping (change kinetic with your ROS distribution name)

sudo apt-get install ros-kinetic-gmapping

Run gmapping node with necessary parameters to subscribe /odom and /scan topics. If your topic names are different change them accordingly.

 rosrun gmapping slam_gmapping scan:=scan odom_frame:=odom use_sim_time:=true

However, generally it is common practice to create a launch file to call gmapping node with appropriate parameters since it is difficult to call gmapping from the terminal with lots of parameters. For this purpose, you can check test.launch file below and tune parameters accordingly.

test.launch:

<launch>
  <!-- Arguments -->
  <arg name="set_base_frame" default="base_footprint"/>
  <arg name="set_odom_frame" default="odom"/>
  <arg name="set_map_frame"  default="map"/>


  <node pkg="tf" type="static_transform_publisher" name="base_link_to_scan"
    args="0.0 0.0 0.0 0.0 0.0 0.0 /base_link /base_scan 10" />

  <!-- Gmapping -->
  <node pkg="gmapping" type="slam_gmapping" name="kamu_robotu_slam_gmapping" output="screen">
    <param name="base_frame" value="$(arg set_base_frame)"/>
    <param name="odom_frame" value="$(arg set_odom_frame)"/>
    <param name="map_frame"  value="$(arg set_map_frame)"/>
    <param name="map_update_interval" value="0.1"/>
    <param name="maxUrange" value="3.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="minimumScore" value="0"/>
    <param name="srr" value="0.01"/>
    <param name="srt" value="0.02"/>
    <param name="str" value="0.01"/>
    <param name="stt" value="0.02"/>
    <param name="linearUpdate" value="0.05"/>
    <param name="angularUpdate" value="0.2"/>
    <param name="temporalUpdate" value="0.5"/>
    <param name="resampleThreshold" value="0.5"/>
    <param name="particles" value="100"/>
    <param name="xmin" value="-10.0"/>
    <param name="ymin" value="-10.0"/>
    <param name="xmax" value="10.0"/>
    <param name="ymax" value="10.0"/>
    <param name="delta" value="0.01"/>
    <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>
</launch>

The procedure should be as follows: 1-) Set use_sim_time parameter to true. It is necessary if you are using rosbag file to extract the map. On the other hand, if you want to make a real time SLAM, then you should set this parameter false.

rosparam set use_sim_time true

2-) Run test.launch

roslaunch test.launch

3-) Play your bag file with --clock argument. (--clock argument is needed since we set use_sim_time true)

rosbag play --clock yourbagfile.bag

To understand more about gmapping and its parameters please see Gmapping ROS Wiki page

If you have any problem about transform tree, please realize that you need to provide necessary tf's between odom-->base_link, base_link-->base_scan and base_link-->base_footprint. These tf frame names could be different for your case. For example, in test.launch we used static_transform_publisher to define the transform between base_link-->base_scan

<node pkg="tf" type="static_transform_publisher" name="base_link_to_scan"
        args="0.0 0.0 0.0 0.0 0.0 0.0 /base_link /base_scan 10" />

I hope it helps! If it solves your problem, don't forget to click tick button to mark as answer.

@CdyTritor , instead of installing packages from source you can use apt-get like this:

Install gmapping (change kinetic with your ROS distribution name)

sudo apt-get install ros-kinetic-gmapping

Run gmapping node with necessary parameters to subscribe /odom and /scan topics. If your topic names are different change them accordingly.

 rosrun gmapping slam_gmapping scan:=scan odom_frame:=odom use_sim_time:=true

However, generally it is common practice to create a launch file to call gmapping node with appropriate parameters since it is difficult to call gmapping from the terminal with lots of parameters. For this purpose, you can check test.launch file below and tune parameters accordingly.

test.launch:

<launch>
  <!-- Arguments -->
  <arg name="set_base_frame" default="base_footprint"/>
  <arg name="set_odom_frame" default="odom"/>
  <arg name="set_map_frame"  default="map"/>


  <node pkg="tf" type="static_transform_publisher" name="base_link_to_scan"
    args="0.0 0.0 0.0 0.0 0.0 0.0 /base_link /base_scan 10" />

  <!-- Gmapping -->
  <node pkg="gmapping" type="slam_gmapping" name="kamu_robotu_slam_gmapping" output="screen">
    <param name="base_frame" value="$(arg set_base_frame)"/>
    <param name="odom_frame" value="$(arg set_odom_frame)"/>
    <param name="map_frame"  value="$(arg set_map_frame)"/>
    <param name="map_update_interval" value="0.1"/>
    <param name="maxUrange" value="3.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="minimumScore" value="0"/>
    <param name="srr" value="0.01"/>
    <param name="srt" value="0.02"/>
    <param name="str" value="0.01"/>
    <param name="stt" value="0.02"/>
    <param name="linearUpdate" value="0.05"/>
    <param name="angularUpdate" value="0.2"/>
    <param name="temporalUpdate" value="0.5"/>
    <param name="resampleThreshold" value="0.5"/>
    <param name="particles" value="100"/>
    <param name="xmin" value="-10.0"/>
    <param name="ymin" value="-10.0"/>
    <param name="xmax" value="10.0"/>
    <param name="ymax" value="10.0"/>
    <param name="delta" value="0.01"/>
    <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>
</launch>

The procedure should be as follows: 1-) Set use_sim_time parameter to true. It is necessary if you are using rosbag file to extract the map. On the other hand, if you want to make a real time SLAM, then you should set this parameter false.

rosparam set use_sim_time true

2-) Run test.launch

roslaunch test.launch

3-) Play your bag file with --clock argument. (--clock argument is needed since we set use_sim_time true)

rosbag play --clock yourbagfile.bag

To understand more about gmapping and its parameters please see Gmapping ROS Wiki page

If you have any problem about transform tree, please realize that you need to provide necessary tf's between odom-->base_link, base_link-->base_scan and base_link-->base_footprint. These tf frame names could be different for your case. For example, in test.launch we used static_transform_publisher to define the transform between base_link-->base_scan

<node pkg="tf" type="static_transform_publisher" name="base_link_to_scan"
        args="0.0 0.0 0.0 0.0 0.0 0.0 /base_link /base_scan 10" />

Here is an example transform tree (tf) for gmapping

I hope it helps! If it solves your problem, don't forget to click tick button to mark as answer.