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

Problem with amcl (laser will not align with map after moving)

asked 2020-03-02 05:24:04 -0600

mimi gravatar image

updated 2020-03-02 06:10:57 -0600

I have created a map using hector_slam, loaded the map via map_server. Run my odometry and amcl for localization, at first the laserscan aligns with the map but then when i move the robot using teleop_twist_keyboard the laserscan gets mis aligned. Is this suppose to act this way? I tried changing the Fixed Frame from(laser,map,odom,base_link) and all has the same result. Can anyone identify whats causing the problem? Thanks in advance :)

ROS melodic ROS Master: Raspberry pi 4 ROS Slave: Raspberry pi 4

Master terminal:


Slave terminal:


Ros Master Launch file:


    <node pkg="amcl" type="amcl" name="amcl" output="screen">
       <!-- Publish scans from best pose at a max of 10 Hz -->
      <param name="odom_model_type" value="diff"/>
      <param name="odom_alpha5" value="0.1"/>
      <param name="transform_tolerance" value="0.2" />
      <param name="gui_publish_rate" value="10.0"/>
      <param name="laser_max_beams" value="30"/>
      <param name="min_particles" value="500"/>
      <param name="max_particles" value="5000"/>
      <param name="kld_err" value="0.05"/>
      <param name="kld_z" value="0.99"/>
      <param name="odom_alpha1" value="0.2"/>
      <param name="odom_alpha2" value="0.2"/>
      <!-- translation std dev, m -->
      <param name="odom_alpha3" value="0.8"/>
      <param name="odom_alpha4" value="0.2"/>
      <param name="laser_z_hit" value="0.5"/>
      <param name="laser_z_short" value="0.05"/>
      <param name="laser_z_max" value="0.05"/>
      <param name="laser_z_rand" value="0.5"/>
      <param name="laser_sigma_hit" value="0.2"/>
      <param name="laser_lambda_short" value="0.1"/>
      <param name="laser_lambda_short" value="0.1"/>
      <param name="laser_model_type" value="likelihood_field"/>
      <!-- <param name="laser_model_type" value="beam"/> -->
      <param name="laser_likelihood_max_dist" value="2.0"/>
      <param name="update_min_d" value="0.2"/>
      <param name="update_min_a" value="0.5"/>
      <param name="odom_frame_id" value="odom"/>
      <param name="resample_interval" value="1"/>
      <param name="transform_tolerance" value="0.2"/>
      <param name="recovery_alpha_slow" value="0.0"/>
      <param name="recovery_alpha_fast" value="0.0"/>
    <!--node pkg="tf" type="static_transform_publisher" name="base_laser" args="0 0 0 0 0 0 base_link laser 100"/-->
    <node pkg="teleop_twist_keyboard" name="teleop_twist_keyboard" type="" output="screen"/> 
    <node pkg="rviz" type="rviz" name="rviz"/>


Ros Slave Launch file:

  <node name="rplidarNode"          pkg="rplidar_ros"  type="rplidarNode" output="screen">
  <param name="serial_port"         type="string" value="/dev/ttyUSB0"/>
  <param name="serial_baudrate"     type="int"    value="115200"/><!--A1/A2 -->
  <!--param name="serial_baudrate"     type="int"    value="256000"--><!--A3 -->
  <param name="frame_id"            type="string" value="laser"/>
  <param name="inverted"            type="bool"   value="false"/>
  <param name="angle_compensate"    type="bool"   value="true"/>
<node pkg="mimi_2dnav" name="odom" type="" output="screen"/>
<node pkg="mimi_2dnav" name="subscrib" type="" output="screen"/>
<node pkg="map_server" type="map_server" name="map_server" args="/home/pi/catkin_workspace/src/navigation/map_server/m.yaml" />
<node pkg="tf" type="static_transform_publisher" name="base_link_to_laser" args="0.0 0 ...
edit retag flag offensive close merge delete


Does moving straight work but rotation is bad?

stevemacenski gravatar image stevemacenski  ( 2020-03-02 11:19:50 -0600 )edit

We've been tinkering with the odometry for quite a while now, there were settings that makes moving straight align with the map and the rotation is just bad. But for this settings both rotating and moving straight will destroy the alignment. Do you think the problem is all on the odometry?

mimi gravatar image mimi  ( 2020-03-02 11:24:35 -0600 )edit

If you move forward and it works fine, then yes, its probably your odometry. I'd move slowly in rotation and see if you see what's happening (wrong sign, wrong wheel bias distance, etc). If your wheel bias (distance between wheels) is wrong, you're going to have lots of drift problems that will only manifest in rotations because straight forward both motors are spinning at the same speed forward so there's no contribution.

stevemacenski gravatar image stevemacenski  ( 2020-03-02 11:26:22 -0600 )edit

The distance between wheels is 155mm, so thats 0.155 m. Should I increase/decrease the value to get a usable odometry?

mimi gravatar image mimi  ( 2020-03-02 17:52:58 -0600 )edit

Try it I suppose.

stevemacenski gravatar image stevemacenski  ( 2020-03-02 18:24:08 -0600 )edit

1 Answer

Sort by » oldest newest most voted

answered 2020-03-02 21:56:42 -0600

mimi gravatar image

We fixed it. We rotated the laserscanner by 180° and increased the wheel base by about 27mm. Adjusted the amcl tolerance and odom alphas. Thank you so much for the insight.

edit flag offensive delete link more


Yeah, a flipped laser and 3cms would do it! Can you close the question as resolved?

Or @gvdhoorn use your admin magic to move this dialog to an answer to accept ;-)

stevemacenski gravatar image stevemacenski  ( 2020-03-03 00:24:53 -0600 )edit

Only a moderator, but there you go.

gvdhoorn gravatar image gvdhoorn  ( 2020-03-03 01:25:18 -0600 )edit

It took me awhile to realize you could do that. I thought I was going crazy on occasion when my comment appeared as an answer and vise versa ;-)

stevemacenski gravatar image stevemacenski  ( 2020-03-03 09:16:55 -0600 )edit

@mimi My Rplidar A1 is also looking backwards due to my design choices, can you tell me if you physically rotated the lidar or just from tf, etc?

berk tepebag gravatar image berk tepebag  ( 2020-04-16 02:15:11 -0600 )edit

Physically, although changing the tf values should work too I guess.

mimi gravatar image mimi  ( 2020-04-16 02:21:39 -0600 )edit

I have changed it physically but no luck. Is this problem looking similar the one you had?

berk tepebag gravatar image berk tepebag  ( 2020-04-16 07:08:45 -0600 )edit

Quite similar. Just to be sure, do you have odometry from wheel encoders?

mimi gravatar image mimi  ( 2020-04-16 07:52:57 -0600 )edit

Also, try changing the parameters in amcl and double check your distance between wheels as it has great impact even just a cm difference.

mimi gravatar image mimi  ( 2020-04-16 07:54:21 -0600 )edit

Question Tools

1 follower


Asked: 2020-03-02 05:24:04 -0600

Seen: 1,372 times

Last updated: Mar 02 '20