SLAM & Localization example using CLI
- 1 Prerequisites
- 2 Mapping
- 2.1 SLAM
- 2.1.1 MAP generation
- 2.1.1.1 1st_pass
- 2.1.2 Crop and refine Map using Cloud-Compare
- 2.1.2.1 2nd_Pass
- 2.1.1 MAP generation
- 2.2 Localization
- 2.3 [Optional] Compare slam and localization trajectories
- 2.4 Related articles
- 2.1 SLAM
Prerequisites
ouster_sdk 0.15.1
pip install ouster-sdkData capture (pcap, osf, bag) of environment/facility
OSW link for this example
Original data recorded at customer site. Do not share publicly. For internal purposes only
For information on optimizing data captures and general best practices, see article .
Mapping
Review original capture and determine what can be modified to improve the subsequent SLAM map quality.
Most common operations include:
Removal of frames with no movement
Eliminate nearby measurements that should not exist in the final map
(e.g. Removal of the vehicle)
ouster-cli source original_mapping_capture.pcap vizFile size:
original_mapping_capture.pcap: 4.47 GB
Identify and remove frames (via
slice) where the vehicle is not moving for long durations.Commonly found at start and stop of the recording.
Frames without vehicle movement
Beginning of capture: 0:280
End of capture: 2708:2804
Apply
sliceand view for correctness
ouster-cli source original_mapping_capture.pcap slice 280: slice :2708 vizRemove the vehicle (via
clip)Start with
clip RANGEin 1m increments until the vehicle is completely removed and review changes in the visualizer. In this example,1mwas not sufficient.
ouster-cli source original_mapping_capture.pcap clip RANGE 3m: vizclip not applied
clip applied
Review the
sliceandclipmodifications for correctness
ouster-cli source original_mapping_capture.pcap slice 280: slice :2708 clip RANGE 3m: vizSave
sliceandclipmodifications into a newosffile.
ouster-cli source original_mapping_capture.pcap slice 280: slice :2708 clip RANGE 3m: save modified_mapping_capture.osfFile sizes:
original_mapping_capture.pcap: 4.47 GBmodified_mapping_capture.osf: 1.48 GB
SLAM
Now utilize slam to create the map from the modified capture.
Review
slamin the visualizer
ouster-cli source modified_mapping_capture.osf slam --voxel-size 0.5 viz --accum-num 100 --accum-every-m 1 --map-ratio 0.005 -e stopGeneral recommendations for voxel-size based on the use case.
Outdoor: 1.4 - 2.2
Large indoor: 1.0 - 1.8
Small indoor: 0.4 - 0.8
Save
slammodifications into a newosffile.In this example, we can reduce the resultant file size significantly by slicing out every 5th frame from the
modfied_mapping_capture.osfinto a new osf. Thedownsampled_modified_mapping_capture.osf.
ouster-cli source modified_mapping_capture.osf slam --voxel-size 0.5 slice ::5 save downsampled_modified_mapping_capture.osfThe save command (when used after slam command) stores both the lidar data and the lidar movement trajectory into the result osf file.
File sizes:
original_mapping_capture.pcap: 4.47 GB
modified_mapping_capture.osf: 1.48 GB
downsampled_modified_mapping_capture.osf: 363 MB
The slam process will take time. Appx 6 minutes in my case (MacBook pro M1 13”). To reduce this time, increase the voxel-size parameter (e.g. 1.0-1.8).
MAP generation
1st_pass
Save
downsampled_modified_mapping_capture.osfas PLY/PCD/LAS
ouster-cli source downsampled_modified_mapping_capture.osf save first_pass_map.plyThe filename will automatically include a numerical suffix attached the end.
first_pass_map-000.ply
File Size: 76.4 MB
Crop and refine Map using Cloud-Compare
2nd_Pass
Import
first_pass_map-000.plyinto CloudCompare, and select REFLECTIVITY as scalar field.
Highlight the PLY “Cloud” in the DB tree, then select the Cross Selection tool
Use the RGB handles to rotate the cloud and crop unnecessary points. Export the changes as new Cloud entity in the DB Tree. Save as second_pass_map-000.ply
File sizes:
original_mapping_capture.pcap: 4.47 GBmodified_mapping_capture.osf: 1.48 GBdownsampled_modified_mapping_capture.osf: 363 MBsecond_pass_map-000.ply: 75 MB
Localization
Try out localization with the original capture (input source) and the new PLY map created
ouster-cli source original_mapping_capture.pcap localize second_pass_map-000.ply viz
Change map view displayed in the viz from 2D (global-map-flatten) to 3D
ouster-cli source original_mapping_capture.pcap localize second_pass_map-000.ply viz --global-map-flatten FALSEThe examples above work fine when the input source begins from the same place as the origin of the map, however, this is not always the case.
If the input source’s start position differs from the map origin, you must add the initial pose information in the command line. PX,PY,PZ represent the position and R,P,Y represent orientation in Euler angles (roll, pitch, yaw) specified in degrees.
ouster-cli source --initial-pose PX,PY,PZ,R,P,Y <SOURCE_URL> localize <map.ply> viz
[Optional] Compare slam and localization trajectories
--
pip install evo
Extract the
slamtrajectory and save ascsvfile
ouster-cli source downsampled_modified_mapping_capture.osf save_trajectory --tum example_slam_traj.csv
Extract the
localizationtrajectory and save ascsvfile
ouster-cli source downsampled_modified_mapping_capture.osf localize second_pass_map-000.ply save_trajectory --tum example_localization_traj.csv
Plot the
slamandlocalizationtrajectories and compare the differencesevo_traj tum --plot --plot_mode xy --project_to_plane xy --ref example_localization_traj.csv example_slam_traj.csv -p --t_max_diff 1.0
In the above example, both the slam and localization are computed using the same data capture. This is not very useful in practice, however, it is fine as a means to show the procedure.
Related articles
Filter by label
There are no items with the selected labels at this time.