The Problem: Laser Scan Drift
While running SLAM on my Create 2-based robot with an RPLiDAR, I noticed an odd issue. Initially, the map looked fine and the robot localized correctly, but over time, the laser scan visualization in RViz started drifting away from the map. The pink laser scan lines—meant to reflect real-world walls and obstacles—became increasingly misaligned. The map itself didn't distort, but the scan data no longer lined up, making it hard to trust the real-time sensor output.
The Cause: Coordinate Frame Misalignment
After some investigation, I found the issue was a coordinate frame mismatch. Specifically:
-
The LiDAR’s internal 0° direction was pointing backward, opposite to the robot’s forward direction.
-
ROS and SLAM algorithms expect the laser’s +X axis to face forward.
-
This mismatch introduced a 180° angular offset, which affected how odometry and scan data fused over time.
The SLAM system was trying to make sense of data coming in at the wrong orientation, which led to scan drift, even though mapping and localization initially appeared correct.
The Fix: Correcting the Laser Frame Orientation
To fix this, I modified the URDF to rotate the laser frame by 180° around the Z-axis. I added this transform to align the LiDAR’s forward direction with the robot’s:
<origin xyz="0 0 0.1" rpy="0 0 3.14159" />
This single change ensured that:
-
The laser’s 0° angle points in the robot’s forward direction.
-
SLAM receives properly oriented scan data.
-
TF transformations (map → odom → base_link → laser) stay consistent.
The Result: Solid, Aligned SLAM
After making the adjustment:
-
Laser scans in RViz stay aligned with the map.
-
Real-time obstacle data matches physical surroundings.
-
The robot can map reliably with minimal drift.
Current Status
Using SLAM Toolbox, I’m now able to generate accurate maps. I briefly tested AMCL by running Nav2 with the saved map published via the map server. Localization appears accurate, and the robot’s estimated position matches the environment. The next step is to test autonomous navigation using this setup.
Vipin M
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.