X2 SLAM Mapping and Localization
An open-source SLAM stack (FAST-LIO2 + RTAB-Map + PCD/BBS cold-start relocalization) for mapping and localization. The source code ships with the SDK under extra/slam/ (a git submodule); build it and deploy it to the robot yourself.
Note
Use this chapter when you need to inspect or modify the algorithm source, tune parameters, or develop algorithms: build your own LiDAR-IMU odometry + visual loop-closure mapping + cold-start relocalization stack on the robot with the LiDAR and the stereo cameras.
If you are using the robot’s built-in optional SLAM module (/integrated_command mapping commands and the GetStoredMapByName service), see SLAM (optional). The two are independent stacks with incompatible map formats; use only one at a time.
Differences from the built-in SLAM module
The robot has two independent mapping/localization stacks: the open-source SLAM stack in this chapter and the built-in optional SLAM module. Their map formats are incompatible and must not be mixed. Key differences:
Aspect |
This chapter (open-source SLAM stack) |
SLAM (optional) (built-in module) |
|---|---|---|
Delivery form |
|
Built into the robot firmware, no source delivered |
Sensors |
Chest-mounted RoboSense E1R LiDAR + built-in IMU + head stereo visual loop closure |
Determined by the built-in module |
Algorithms |
FAST-LIO2 odometry + RTAB-Map loop closure + PCD/BBS cold-start relocalization |
Implemented inside the built-in module |
Map outputs |
rtabmap |
Built-in format |
Intended users |
Users who need to inspect/modify source code, tune parameters, or do secondary development |
Users who only need mapping/localization functionality |
Data interfaces |
Standard ROS 2 topics / TF |
Topics / services in the SLAM (optional) chapter |
Source package overview
The in-house / adapted packages under extra/slam/ are as follows (rtabmap / rtabmap_ros / livox_ros_driver2 / Livox-SDK2 are external dependencies, not included in the submodule; build or install them separately):
Package |
Localization |
Status |
|---|---|---|
|
FAST-LIO2 frontend odometry + RTAB-Map integration, unified entry launch (shared by mapping and localization) |
Production |
|
PCD cold-start SE(2) global relocalization (includes the |
Production |
|
3D-BBS global relocalization (generates cold-start BBS candidates; depends on the vendored |
Production (the target is skipped automatically when the GPU library is missing) |
|
Scan Context loop closure + GTSAM pose graph (requires gtsam) |
Experimental, not part of the mapping / localization workflow below |
|
Upstream 3D-BBS library (vendored; CPU / GPU builds) |
Dependency library |
You may build and evaluate the experimental packages yourself, but the deployment and usage instructions in this document cover only the production stack (fast_lio + PCD/BBS localization).
System composition and data flow
A single launch file starts the following components (the stereo bridge node is embedded; no need to start it separately):
E1R LiDAR + IMU ──▶ FAST-LIO2 (fast_lio) ──odometry──▶ RTAB-Map (loop closure + pose graph)
│ │ │
│ ▼ ▼
│ /cloud_registered_body_zup /rtabmap/map (2D grid)
│ │ │
└── stereo cameras ──▶ stereo_dmabuf_bridge ──▶ stereo_sync ──visual loop──┘
Started additionally in localization mode:
3D-BBS candidate ──▶ PCD cold-start relocalization (fastlio_pcd_localization) ──initial pose──▶ RTAB-Map
└── waist_scan_helper (autonomous ±45° waist sweep)
Main ROS 2 topics (all internal data-flow topics of the stack; subscribe to observe them):
Topic |
Type |
Content |
|---|---|---|
|
|
FAST-LIO2 odometry output |
|
|
Odometry trajectory |
|
|
Point cloud registered in the body frame (z-axis up) |
|
|
RTAB-Map 2D occupancy grid map |
|
|
Pose output by the PCD relocalizer |
|
|
PCD localizer status |
Prerequisites
Before you start, confirm each hardware, system, and account requirement below — any unmet item will cause the subsequent build or launch to fail:
Item |
Requirement |
|---|---|
Robot |
Lingxi X2 with a chest-mounted RoboSense E1R LiDAR, firmware 1.2 (stereo images delivered over the dmabuf channel) |
Compute |
Jetson Orin NX 16GB (on the robot), or a host PC that meets the dependencies |
OS |
Ubuntu 22.04 + ROS 2 Humble |
Account |
Build and launch on the robot as the |
Battery |
Battery level at startup must be above 15% (startup is refused below the threshold; see “Startup gates”) |
Dependencies and building
The SLAM stack depends heavily on third-party libraries, and some must be built from source. Overall order: build the external dependencies first (rtabmap / livox drivers), then build this workspace.
Software dependencies
Dependency |
Purpose |
How to obtain |
|---|---|---|
ROS 2 Humble |
Base framework |
System installation |
PCL (>= 1.12), Eigen3, OpenMP |
Point cloud and linear algebra |
apt |
|
Loop closure + pose graph + map management |
Must be built from source (see below) |
|
E1R LiDAR driver |
Build from source |
g2o |
Graph optimization library |
Restored from deploy assets (see “Robot deployment”) |
CUDA + 3D-BBS GPU library |
Required only by |
Optional |
Building rtabmap / rtabmap_ros from source (required)
The latest robot firmware switched the ROS 2 message serialization library to fastcdr v2, while apt install ros-humble-rtabmap is prebuilt against fastcdr v1 and crashes at runtime. Build from source, and apply the stereo_sync patch from the submodule first:
# 1. Apply the patch (<rtabmap_ros> is the source directory)
cp extra/slam/patches/rtabmap_sync/stereo_sync.hpp <rtabmap_ros>/rtabmap_sync/include/rtabmap_sync/stereo_sync.hpp
cp extra/slam/patches/rtabmap_sync/stereo_sync.cpp <rtabmap_ros>/rtabmap_sync/src/nodelets/stereo_sync.cpp
# 2. Build with colcon together with livox_ros_driver2; source the resulting install space in later steps
colcon build --symlink-install
Building the SLAM workspace
cd extra/slam
source /opt/ros/humble/setup.bash
# Source the prebuilt rtabmap_ros and livox_ros_driver2 install spaces first
source <dependency install space>/setup.bash
colcon build --symlink-install
source install/setup.bash
When fastlio_bbs_localization cannot find the 3D-BBS GPU library it does not fail: it prints a WARNING and skips the target (the BBS candidate of the localization stack is then unavailable).
Robot deployment
The robot firmware 1.2 runtime differs considerably from a development machine; after copying the build artifacts to the robot, two deployment steps are required. Repeat them after every firmware flash / OTA upgrade.
Restoring dependencies after an OTA (restore_deps.sh)
The SLAM stack dynamically links three system-level dependencies: g2o, livox, and the fastcdr v2 fix. An OTA / firmware flash wipes system paths such as /opt/ros/humble and /usr/local, so the restore script must be replayed (the three assets ship with the submodule under deploy_deps/, self-contained):
# First deployment: copy the whole deploy_deps/ directory to the robot's home partition (survives OTA)
# Use the actual robot IP; account run, password 1
tar cf - -C extra/slam deploy_deps | ssh run@<robot-IP> "tar xf - -C /home/agi/"
ssh run@<robot-IP> # password 1 (after firmware 1.2 only run has sudo)
export HOME=/home/agi # run's home directory is not agi; the script locates things via $HOME
bash /home/agi/deploy_deps/restore_deps.sh
The script restores g2o to /opt/ros/humble/lib/aarch64-linux-gnu/ and livox to /usr/local/lib/, fixes the fastcdr v2 symlinks and overwrites the CMake export config, then runs ldconfig and verifies that no key library resolves as not found.
Injecting the aimdk_msgs libraries (patch_workspace_env.sh)
The cold-start waist-scan script waist_scan_helper.py depends on the aimdk_msgs Python bindings and typesupport shared libraries, which exist only in the factory firmware path /robot/software/common/, not in the workspace install/ tree. Use the idempotent script to inject both kinds of paths into the workspace environment:
bash tools/waist_scan/patch_workspace_env.sh /home/agi/workspace
Re-run it after every colcon build or firmware OTA (it appends only once; repeated runs are skipped automatically). Afterwards source install/setup.bash carries the aimdk_msgs PYTHONPATH and LD_LIBRARY_PATH automatically.
Usage
Start both mapping and localization as the run account. The unified entry launch fastlio_rtabmap_rgb.launch.py embeds the stereo bridge node, so a single command is enough.
Startup gates
The launch file performs two kinds of preflight checks and refuses to start outright, printing the reason, when a check fails:
Gate |
Behavior |
|---|---|
Low battery |
Reads the battery level from |
Map count limit |
In mapping mode, startup is refused when the directory containing |
Mapping
ssh run@<robot-IP> # password 1
cd /home/agi/workspace
source install/setup.bash
ros2 launch fast_lio fastlio_rtabmap_rgb.launch.py mode:=mapping \
database_path:=/absolute/path/to/your_map.db
database_pathmust be an absolute path ending in.db, and the file must not already exist — mapping mode refuses to overwrite an existing database and exits.When mapping ends (Ctrl+C), the
.dband the 2D grid map (pgm/yamlundermap2d/) are saved automatically.
Exporting the PCD map
After mapping, export the database to a global PCD point cloud (required for localization):
source install/setup.bash
install/fast_lio/lib/fast_lio/rtabmap_export_pcd \
--database /absolute/path/to/your_map.db \
--voxel-size 0.05 # optional, voxel downsampling of the point cloud
# Without --output, lands at <db-dir>/../pcd/<db-name>/<db-name>.pcd
Localization
ssh run@<robot-IP> # password 1
cd /home/agi/workspace
source install/setup.bash
ros2 launch fast_lio fastlio_rtabmap_rgb.launch.py mode:=localization \
database_path:=/absolute/path/to/your_map.db \
pcd_map_path:=/absolute/path/to/pcd/your_map.pcd
database_pathpoints to the db generated during mapping andpcd_map_pathto the exported PCD file.
Cold-start relocalization flow (fully automatic, no manual rotation needed)
The cold start is fully automatic: once the BBS candidate passes, waist_scan_helper autonomously performs a ±45° waist sweep to collect point clouds at multiple orientations. Judge progress by the following log sequence:
Waiting for a BBS candidate. Seeing
[PCD_BBS_CANDIDATE] ... accepting into multi-frame ICPmeans the BBS candidate passed the orientation check and was accepted (withpcd_expected_yaw_deg:=nan, the log showsaccepting BBS candidate without the expected-yaw gate, i.e. no orientation check). The waist sweep then starts automatically:[WAIST_SCAN] sweep start.Automatic sweep + multi-frame confirmation. The system assembles the point clouds collected at different orientations during the sweep and runs ICP; by default it requires about 90° of yaw coverage and 3 mutually independent, consistently valid results. You may see
waiting for yaw coverage ...looping until[WAIST_SCAN] sweep complete.Multi-frame confirmation complete. Seeing
cold-start confirmed; waiting for the robot to settle before handing off to RTAB-Mapmeans the cold start is confirmed and the system is waiting for the waist to return and the robot to stabilize.Handoff to RTAB-Map. Seeing
handed off to RTAB-Map: published initialpose ...means the initial pose has been published to RTAB-Map; only when the handoff bridge then prints... is no longer identity; switching anchor source to RTAB-Map's own TFhas RTAB-Map published a validmap->camera_initTF and taken over.
Attention
A BBS candidate or a single successful ICP frame does not mean RTAB-Map has taken over; judge strictly by the log sequence above. Until localization completes, RTAB-Map poses are not trustworthy.
Waist sweep and the motion-control input source
Warning
The cold-start waist sweep registers a temporary input source (pcd_waist_scan, priority 1) via SetMcInputSource to drive the waist. During the sweep the waist autonomously turns about ±45° to each side:
During the sweep make sure the robot stands stably with no obstacles or people around;
The temporary input source is unregistered automatically when the sweep ends; if the sweep is interrupted abnormally the source may remain, so restart the localization flow or unregister it manually and retry;
Do not send other motion-control commands during the sweep to avoid control conflicts.
Common launch parameters
The table lists common parameters; for all parameters and value details see the DeclareLaunchArgument descriptions inside the launch file:
Parameter |
Default |
Description |
|---|---|---|
|
|
|
|
|
rtabmap database path (must be absolute; mapping refuses to overwrite an existing file) |
|
|
Global PCD point cloud used for localization |
|
|
Whether to perform the autonomous ±45° waist sweep before cold-start confirmation; |
|
|
Optional expected cold-start heading (degrees); |
|
|
Low-battery startup gate switch (disable for offline replay / debugging) |
|
|
Battery percentage threshold; startup is refused at or below it |
|
|
Maximum number of |
|
|
Set |
|
|
FAST-LIO config file name (under |
Troubleshooting
Locate common problems by symptom; each entry gives what to check and how to handle it:
Localization stalls waiting for a BBS candidate: check that
pcd_map_pathis correct, that the 3D-BBS GPU library is built and installed (when missing the target is skipped with a WARNING and no BBS candidates are produced), or passpcd_expected_yaw_degat startup to narrow the candidate range.fastlio_bbs_localizationskips its target with a WARNING at build time: normal when the upstream 3D-BBS GPU library was not built; build and install it undersrc/3d_bbsper the README when BBS candidates are needed.SLAM fails to start with missing shared libraries after an OTA / firmware flash: replay
restore_deps.shandpatch_workspace_env.shas described in “Robot deployment”.The waist turns by itself after localization starts: normal behavior of the cold-start waist sweep (see “Waist sweep and the motion-control input source”); to disable it pass
waist_scan_enabled:=false(you then need to rotate the robot manually during the cold start).
Upstream projects and licenses
This stack uses or derives from the following open-source projects; keep their upstream licenses when using or redistributing:
Item |
Source |
License |
|---|---|---|
FAST-LIO2 / ikd-Tree |
GPL-2.0 |
|
3D-BBS |
MIT |
|
RTAB-Map / rtabmap_ros |
BSD-3-Clause |
|
Livox-SDK2 |
MIT |
The LICENSE files of FAST-LIO2, ikd-Tree and 3D-BBS are kept in the repository alongside the source; the stereo_sync modifications of rtabmap_ros are in the submodule patches/rtabmap_sync/.