Atlas Robotics
Lesson 4/6 · about 20 min

Why must maps be gravity-aligned?

The origin of frame map is where the robot stands when SLAM is turned on, the x-axis follows the robot's nose. But the z axis does not follow the robot's body: it points straight up into the sky, against gravity, even when the robot starts on a slope.

Turn on SLAM when the robot stands in the middle of a 6° slope, then drive onto a flat platform: the map shows a flat platform. Turning this feature off will cause the same platform to slope down 7°.

Test

Place the robot in the middle of the west slope using the spawn parameter, nose facing up the slope:

Terminal 1

ros2 launch atlas3d_bringup bringup.launch.py world:=ramp.sdf wheel_odom_tf:=false rviz:=false \
  x:=-6.0 y:=2.0 z:=0.40 yaw:=0.0

Terminal 2

ros2 launch atlas3d_slam fastlio2.launch.py

Drive straight onto the platform, continue a few meters above the platform. See the pose in frame map:

ros2 topic echo /fastlio2/lio_odom --field pose.pose.position

Second time turning off this feature with a copy of the configuration (turn it all off, reopen Terminal 1 to get the robot to the middle of the slope):

cp ~/atlas_sim3D/src/atlas3d_slam/config/fastlio2_vlp16.yaml /tmp/nogravity.yaml
sed -i 's/^gravity_align: true/gravity_align: false/' /tmp/nogravity.yaml
ros2 launch atlas3d_slam fastlio2.launch.py config:=/tmp/nogravity.yaml
gravity_align: true (default)gravity_align: false
Pitch angle at initialization−7.8° (true −7.2°)0.0° (considered horizontal)
On the platform (really flat)−0.4°, z holds 0.32 m+7.4°, z reduced from −0.05 to −0.69 m

ROS convention: the robot's nose rising is a negative angle. On a 6° slope, Gazebo's ground truth measures the robot's body at 7.2°.

How to do it in code

FAST-LIO2 averages the first 200 IMU samples (imu_init_num) when the robot is stationary. When stationary, the accelerometer only measures gravity, so on average it is the vertical direction. With gravity_align: true, it rotates the frame so that the z axis is in the same direction:

// src/third_party/FASTLIO2_ROS2/fastlio2/src/map_builder/imu_processor.cpp
if (m_config.gravity_align)
{
    m_kf->x().r_wi = (Eigen::Quaterniond::FromTwoVectors((-acc_mean).normalized(), V3D(0.0, 0.0, -1.0)).matrix());
    m_kf->x().initGravityDir(V3D(0, 0, -1.0));
}

This rotation only adjusts tilt (roll, pitch); The robot's nose direction (yaw) remains the same. Configure at src/atlas3d_slam/config/fastlio2_vlp16.yaml. That is also the reason why you have to let the robot stand still for a few seconds when turning on SLAM (M01 lesson 1): driving immediately will average the IMU and the acceleration of the movement.

What does this rely on

  • traversability map (M01 lesson 4, M11) measures slope and grade along the z axis of map. The map tilts 7°, the flat floor becomes a 7° slope, and the elevation difference increases by 12 cm per meter.
  • "2D Pose Estimate" shows x, y, direction; localizer gets roll, pitch from IMU. The two frames are gravity-aligned so the roll and pitch are the same (M01 lesson 3).
  • PGO blocks the closed loop between the two stages by the z difference (loop_max_z_difference: 0.8, M09).

Frame odom of FAST-LIO2 is also gravity-aligned in the same way, so the map → odom edge is almost only moved and rotated around the z axis.

Why the map must be aligned with gravity · Module 2: The big picture — Atlas Robotics