FixTheRobot Explore Robotics / Systems Engineering / Engineering Guides / Module 08

Engineering Guides · Module 08

Point-cloud processing workflow

Reduce the data early, in a known order, and measure what each step costs and what it removes.

  • Intermediate
  • Module 08: Robotics Perception & Sensor Integration
  • Written for ROS 2 Jazzy where ROS 2 is used
  • Sources checked 2026-11-06

Assumptions: Numbers in the examples are illustrative and the code is executed by the site’s tests. Facts taken from a cited source are marked; other statements are general engineering knowledge and must be confirmed on the datasheet of the part you use.

1. Engineering problem

A 3D LiDAR can produce hundreds of thousands of points per second. Most algorithms do not need all of them, and processing them all can saturate a CPU. A fixed, measured workflow keeps the data useful and the load predictable.

2. When is this needed?

  • Before any LiDAR algorithm (mapping, detection) on an embedded computer.
  • When CPU load tracks the point count.
  • When changing sensors or resolution.

3. Selection and design decisions

Typical order: validate the message (frame, stamp, fields, is_dense), crop, remove invalid points (NaN), downsample with a voxel grid, remove outliers, then run the task algorithm. The voxel grid keeps one representative per cell; the cell size sets the resolution you keep.

Overview
StepEffectCostRisk
ValidateRejects malformed cloudsNegligibleNone
CropRemoves irrelevant points earlyLowCropping needed objects
Remove NaNAvoids propagating invalid valuesLowNone
Voxel downsampleCuts the count and evens densityMediumLoses small details
Outlier removalRemoves isolated noise pointsMedium to highRemoves thin real structures

4. Advantages and disadvantages

  • Larger voxels reduce load and lose detail; choose from the smallest feature the algorithm needs.
  • Order matters: crop and downsample before expensive filters.
  • Keeping the first point per cell is fast; averaging the points in the cell is smoother and costs more.

5. Requirements and constraints

  • Voxel size is derived from the smallest feature of interest.
  • The workflow runs within the frame period with margin.
  • Stamp and frame_id of the output equal those of the input (or the transformed frame is stated).

6. Architecture

PointCloud2 ─▶ validate ─▶ crop ─▶ drop NaN ─▶ voxel downsample ─▶ outlier removal ─▶ algorithm

7. Implementation

  1. Check header, fields and is_dense of each cloud.
  2. Crop and drop invalid points.
  3. Choose the voxel size from the smallest feature and measure the remaining point count (below).
  4. Measure per-step time on the target computer.
  5. Check the output against the input visually and with a metric (for example the nearest-obstacle distance).
import numpy as np
rng = np.random.default_rng(0)
pts = np.concatenate([rng.uniform(-1, 1, (5000, 3)) * [10, 10, 1], rng.normal([5, 0, 0.5], 0.05, (500, 3))])
def voxel(points, size):
    keys = np.floor(points / size).astype(np.int64)
    _, idx = np.unique(keys, axis=0, return_index=True)
    return points[np.sort(idx)]
for size in (0.1, 0.5, 1.0):
    d = voxel(pts, size)
    print(f"voxel {size} m: {len(pts)} -> {len(d)} points ({len(d) / len(pts) * 100:.0f} %)")

Printed (checked by the site’s tests):

voxel 0.1 m: 5500 -> 5015 points (91 %)
voxel 0.5 m: 5500 -> 3454 points (63 %)
voxel 1.0 m: 5500 -> 800 points (15 %)

Reading it: a synthetic cloud of 5 500 points (a large sparse volume plus a small dense object) keeps 91 % of its points with 0.1 m voxels, 63 % with 0.5 m and 15 % with 1.0 m. The dense object collapses first, which is the loss of detail the trade-off describes. This implementation keeps the first point per cell. The data are random and illustrative.

8. Real examples

  • Mapping on an embedded computer: 0.2 m voxels before scan matching to keep the front end under 50 ms per sweep.

9. Failure scenarios

  • A voxel size larger than the smallest obstacle, so it vanishes.
  • Outlier removal that deletes thin poles.
  • Downsampling after an expensive filter, which wastes the saving.

10. Troubleshooting

  1. Plot point count after each step.
  2. Compare nearest-obstacle distance before and after.
  3. Profile each step’s time.

11. Validation

  • The example prints the lines shown (executed by the site tests).
  • The task result (detections or map quality) is unchanged within tolerance after downsampling.
  • Processing time per frame is within budget on the target computer.

12. Engineering checklist

13. Further references

  • ROS 2 sensor_msgs/PointCloud2 (Jazzy): PointCloud2.msg, read 2026-11-06.
  • Library documentation for your point-cloud tool (for example PCL or Open3D) for the exact filter and clustering functions and parameters; the algorithms here are written out in plain Python so they can be checked.

Related on FixTheRobot