Skip to content

Extract road from lidar scan - #34

Merged
m3d merged 21 commits into
masterfrom
feature/lidarroad
Jul 31, 2026
Merged

m3d merged 21 commits into
masterfrom
feature/lidarroad

Conversation

@m3d

@m3d m3d commented Jul 30, 2026

Copy link
Copy Markdown
Member

Find smooth section with given tolerance for expected road width

@m3d
m3d requested a review from tajgr July 30, 2026 17:27
m3d and others added 5 commits July 31, 2026 06:43
 1. Critical Off-by-One Bug in Sliding Window Logic
  Both slow_get_best_match and the vectorized get_best_match implementations contain an identical off-by-one error. They
  skip the very last possible window of the array.
   * In slow_get_best_match: The loop for i in range(0, len(mask) - window_size): stops one element early. It should be
     range(0, len(mask) - window_size + 1).
   * In get_best_match: The window_sums array allocation np.empty(len(mask) - window_size) is one element too small.
     Additionally, the slice cum[window_size:-1] drops the last element. The correct vectorized form should be:

   1     window_sums = np.empty(len(mask) - window_size + 1, dtype=cum.dtype)
   2     window_sums[0] = cum[window_size - 1]
   3     window_sums[1:] = cum[window_size:] - cum[:-window_size]
   * Test Masking the Bug: The test_get_best_match passes because both the slow and fast implementations share this
     exact same bug, so their outputs match. If you add a test case where the optimal window is exactly at the end of
     the array (e.g., mask = [0, 0, 1, 1, 1] with window_size = 3), both algorithms will incorrectly return index 1
     instead of 2.
2. Redundant Aliasing in __init__.py
  The lidarroad/__init__.py file uses explicit aliases like analyze_scan as analyze_scan. While this syntax is
  occasionally used to explicitly re-export symbols for strict type checkers (like pyright), this codebase doesn't use
  type hints. This makes the imports overly verbose. A clean from .lidarroad import analyze_scan, batch_processing, ...
  would be more idiomatic.
3. Missing Test Coverage for Window Boundary Edge Case
  In test_lidarroad.py, the test_get_best_match test loops over multiple arrays and window sizes but intentionally skips
  testing when the sizes are equal: if len(m) > window_size:.
  While the implementations do currently handle len(m) == window_size without crashing (they correctly return 0,
  window_size), it is best practice to remove that if constraint in the test to ensure this edge case remains explicitly
  covered and doesn't regress in the future.
@m3d

m3d commented Jul 31, 2026

Copy link
Copy Markdown
Member Author

OK, I am going to merge this as "version 0". In particular there is missing OSGAR Node, which would handle navigation, but as it will be part of "Dobyvani hradu 2026" integration, it should be mix of GPS, lidar, obstacle detection and maybe redroad, so could be more complex and hard to tell at the moment.

Another "issue" is that the road width may change and it is not taken into account. Also if the window size is wrong then local minima does not have strong "anchor". With this I would play later once we collect new data on the Divci kamen castle :).

@m3d
m3d merged commit 11a86a1 into master Jul 31, 2026
2 checks passed
@m3d
m3d deleted the feature/lidarroad branch July 31, 2026 07:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant