Ask Your Question

Hector_Slam to AMCL

asked 2020-01-23 12:10:12 -0500

femitof gravatar image

updated 2020-01-30 19:58:54 -0500

Hi All,

I am a newbie to ROS, but i was able to create a map with hector slam using RPlidarA2M6 on ros kinetic, Issues: - Mapping was smooth till it get a certain point where the robot was moving with the lidar but movement on the map was static hence mapping just a single point.. (Though i was able to maneuver my way through this by staying at this point for a while before finally moving) How do i fix this? - I created a fake odometry using laser_scan_matcher but the odometry was stuck at the same point where it was stuck while mapping. how do i fix this? _ amcl is totally wrong,

I need help with these issues, please see the various launch files below.. Thanks

Hector SLAM - launch file

<?xml version="1.0"?>

  <arg name="tf_map_scanmatch_transform_frame_name" default="scanmatcher_frame"/>
  <arg name="base_frame" default="base_link"/>
  <arg name="odom_frame" default="base_link"/>
  <arg name="pub_map_odom_transform" default="true"/>
  <arg name="scan_subscriber_queue_size" default="5"/>
  <arg name="scan_topic" default="scan"/>
  <arg name="map_size" default="2048"/>

  <node pkg="hector_mapping" type="hector_mapping" name="hector_mapping" output="screen">

    <!-- Frame names -->
    <param name="map_frame" value="map" />
    <param name="base_frame" value="$(arg base_frame)" />
    <param name="odom_frame" value="$(arg odom_frame)" />

    <!-- Tf use -->
    <param name="use_tf_scan_transformation" value="true"/>
    <param name="use_tf_pose_start_estimate" value="false"/>
    <param name="pub_map_odom_transform" value="$(arg pub_map_odom_transform)"/>

    <!-- Map size / start point -->
    <param name="map_resolution" value="0.050"/>
    <param name="map_size" value="$(arg map_size)"/>
    <param name="map_start_x" value="0.5"/>
    <param name="map_start_y" value="0.5" />
    <param name="map_multi_res_levels" value="2" />

    <!-- Map update parameters -->
    <param name="update_factor_free" value="0.4"/>
    <param name="update_factor_occupied" value="0.9" />    
    <param name="map_update_distance_thresh" value="0.4"/>
    <param name="map_update_angle_thresh" value="0.06" />
    <param name="laser_z_min_value" value = "-1.0" />
    <param name="laser_z_max_value" value = "1.0" />

    <!-- Advertising config --> 
    <param name="advertise_map_service" value="true"/>

    <param name="scan_subscriber_queue_size" value="$(arg scan_subscriber_queue_size)"/>
    <param name="scan_topic" value="$(arg scan_topic)"/>

    <!-- Debug parameters -->
      <param name="output_timing" value="false"/>
      <param name="pub_drawings" value="true"/>
      <param name="pub_debug_output" value="true"/>
    <param name="tf_map_scanmatch_transform_frame_name" value="$(arg tf_map_scanmatch_transform_frame_name)" />

  <node pkg="tf" type="static_transform_publisher" name="base_to_laser_broadcaster" args="0 0 0 0 0 0 base_link laser 100" />


Laser_Scan_matcher Launch file: < <launch>

 <node pkg="laser_scan_matcher" type="laser_scan_matcher_node" 
    name="laser_scan_matcher_node" output="screen">

    <param name="base_frame" value="base_link"/>
    <param name="fixed_frame" value="odom"/>
    <param name="use_alpha_beta" value="false"/>
    <param name="use_odom" value="true"/>
    <param name="use_imu" value="false"/>
    <param name="max_iterations" value="4"/>
    <param name="publish_pose" value="true"/>
    <param name="publish_tf" value="true"/>


  <node pkg="tf" type="static_transform_publisher" name="base_to_laser_broadcaster" args="0 0 0 0 0 0 base_link laser 100" />

AMCL Launch file:

<node pkg="amcl" type="amcl" name="amcl" output="screen ...
edit retag flag offensive close merge delete


I editted your title to follow our community guidelines. Please do not add excessive "!", its not productive.

stevemacenski gravatar image stevemacenski  ( 2020-01-23 12:40:49 -0500 )edit

Hi, there can be many reasons why your setup is not working. Please post your launch files and error messages to give any sort of useful answer.

Namal Senarathne gravatar image Namal Senarathne  ( 2020-01-23 20:40:30 -0500 )edit

Thanks Namal for your comment.. I have edited the post and posted the launch files..

I used laser_match to create a fake odometry, but it seems to be stuck at a place on the map and the amcl is totally wrong..what could be wrong?

femitof gravatar image femitof  ( 2020-01-24 18:24:20 -0500 )edit

@femitof: could you clarify how #q342504 and this question are related?

gvdhoorn gravatar image gvdhoorn  ( 2020-01-25 03:52:56 -0500 )edit

@gvdhoorn deleted... Can you please help me? @Namal Senarathne@gvdhoorn


femitof gravatar image femitof  ( 2020-01-25 14:20:34 -0500 )edit

Thanks for uploading the launch files, but I don't see any error messages apart form your description of the error. Can you post any error messages you see and better yet upload a rosbag file capturing the exact erroneous phase during localization.

Anyway my hunch is that your robot is passing through a "feature sparse" location which both hector mapping and amcl is finding difficult to match to its existing map. May be you can try using some other tool for mapping and localization like

Namal Senarathne gravatar image Namal Senarathne  ( 2020-01-28 21:14:30 -0500 )edit

Yeah, there are no error messages, but AMCL just doesn't localize is totally incorrect.. Any ideas what could be wrong? Also do you haver an idea of how i could upload a video or something? @Namal Senarathne

femitof gravatar image femitof  ( 2020-01-29 17:30:20 -0500 )edit

Hi, you can probably upload your bag files and videos to some web storage (like google drive, dropbox) and provide a link in your question. Also please update your question with information about how you initialize AMCL with the initial pose of the robot to figure out the reasons for failure in localization.

Namal Senarathne gravatar image Namal Senarathne  ( 2020-01-29 23:41:45 -0500 )edit

1 Answer

Sort by » oldest newest most voted

answered 2020-01-30 02:02:12 -0500

Namal Senarathne gravatar image

updated 2020-02-05 10:11:36 -0500

To resolve laser odometry issues, try using the default scan matching parameters ( Since you mentioned about fake odometry, I'm assuming you don't have wheel odometry. So use_odom parameter must be set to false in the laser scan matcher launch file.

Regarding AMCL, I think you are using only a small fraction of the laser returns by setting laser_max_beams to 30. This could be a reason by AMCL is not localizing. Instead try setting it to 266 (assuming the angular resolution of your RPlidar is 1.35. 360/1.35 ~= 266)


I ran an AMCL instance using the map data and only the /scan data from your bag file and was able to localize successfully. See :

In the second video, I purposely gave a wrong initial orientation and it was able to converge to the correct pose after a while.

I noticed that somehow your recorded bag file's TF always have a ZERO static transform between map and odom. See below

image description

image description

You should double check your launch files to see if any of them is publishing an unwanted static transform between odom and map. Only AMCL should be publishing this transform. I've also uploaded the launch files I used in the same shared folder for your reference. localize.launch is the main launch file.

Note however that your environment is somewhat challenging to localize overtime (Especially when the robot is in the middle of the corridor.) because your laser has only about 15 meter range. When the robot is in the middle of the corridor the laser can't see one end and all positions along the corridor might look the same.

edit flag offensive delete link more


@Namal Senarathne Thanks. I made the changes as suggested, it still doesnt localize. Also, am i meant to set the initial poisiton of tjhe robot using the 2D pose estimate to the correct position on the map? or AMCL is meant to localize to the correct position successfully?

femitof gravatar image femitof  ( 2020-01-30 20:02:31 -0500 )edit

Also, i have successfully set up wheel odometry.. just need to figure out a way to link it to ROS.. Do you think it would be better than the laser_scanner_match i am currently using?

femitof gravatar image femitof  ( 2020-01-30 21:03:05 -0500 )edit

@Namal Senarathne Still awaiting your input to this. thanks

femitof gravatar image femitof  ( 2020-02-04 12:49:48 -0500 )edit

You can let AMCL to converge automatically or provide initial 2D pose manually. Both works initially as the robot is very close to the distinguishable corner in the environment. Again see the two videos in the shared folder mentioned in the edited answer.

You have to test whether your wheel odometry is better than laser odometry or not. It depends on the wheel odometry implemention. In long corridors with not many distinguishable features, wheel odometry might be more accurate.

Namal Senarathne gravatar image Namal Senarathne  ( 2020-02-05 10:18:56 -0500 )edit

@Namal Senarathne Thank you very much for the inputs.. I am gonna try it out again, but what do you mean by "only AMCL should be publishing this transform?" should i add the static transform in my amcl launch file or AMCL already automatically publishes this transform?

transform here means from odom to map..

femitof gravatar image femitof  ( 2020-02-05 20:57:45 -0500 )edit

I meant AMCL to automatically publish the odom to map transform.

Namal Senarathne gravatar image Namal Senarathne  ( 2020-02-06 02:29:03 -0500 )edit

I tried it without using the static transform publisher, but it outputs " No transform from map to odom" AMCL doesnt automatically publish it,..i dont know why

femitof gravatar image femitof  ( 2020-02-06 21:11:41 -0500 )edit

@Namal Senarathne Hi I have an IMU nodee running and working perfectly, can you direct me how i can utilize this to do mapping and localization? I seem to be stuck..


femitof gravatar image femitof  ( 2020-02-10 23:45:23 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2020-01-23 12:10:12 -0500

Seen: 420 times

Last updated: Feb 05 '20