fix: properly filter blanked RPLidar angles using any() in _path_processor#2141
fix: properly filter blanked RPLidar angles using any() in _path_processor#2141Ridwannurudeen wants to merge 3 commits intoOpenMind:mainfrom
Conversation
…cessor Closes OpenMind#2138 The angle blanking logic in _path_processor used a `continue` inside a nested `for b in self.angles_blanked` loop (lines 453-457). That `continue` only skipped to the next blanked range in the inner loop instead of skipping the outer `for angle, distance in data` iteration. As a result, readings from blanked angles were never actually filtered and always reached `complexes.append(...)`, sending phantom obstacles from fixed chassis reflections to the path planner. Replace the nested loop with `any(b[0] <= angle <= b[1] for ...)` which evaluates the blanking check as a single expression. When a match is found, the outer loop's `continue` fires correctly, skipping the reading. This approach: - Fixes the control flow bug in one line - Short-circuits on the first matching range (same as break) - Matches how rptest.py already handles blanking correctly (lines 276-282) Add two tests exercising _path_processor directly: - test_path_processor_filters_blanked_angles: verifies readings inside [-170, -150] are excluded while readings outside pass through - test_path_processor_no_blanking_when_empty: verifies no readings are lost when angles_blanked is empty Affected configs: turtlebot4.json5, turtlebot4_lidar.json5, turtlebot4_lidar_gps.json5, test_lidar.json5 — any robot with non-empty angles_blanked was seeing phantom obstacles.
|
#2139 |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
Hi @Ridwannurudeen |
Ruff split the long single-line `if` statement across multiple lines, which moved the `# type: ignore` comment to the closing parenthesis (line 20) instead of the line where `_singleton_instance` is actually accessed (line 19). Pyright could not see the suppression and reported reportAttributeAccessIssue. Moved the comment to the attribute access line and narrowed the suppression to `attr-defined` for specificity.
Sorry, but i already mentioned this issue in my PR and got approve |
|
Thanks @Wanbogang — good catch. The pyright failure was due to a |
Sorry, why you ignoring me? |
|
Hey @letmehateu — apologies for not acknowledging your PR first, that was my oversight. I should have engaged with #2139 before opening a separate one. My PR takes a slightly different approach (single |
for public 1 issues multiple developer can open PRs , the best one will merge after approve with multiple reviewers. |
Hi @letmehateu |
Summary
Fixes #2138
A
continuestatement inside a nested loop caused the RPLidar angle blanking logic to silently fail. Readings from blanked angle ranges (fixed chassis reflections) passed through to the path planner as phantom obstacles, potentially triggering unnecessary stops or evasive maneuvers on any robot with non-emptyangles_blanked.Root cause
In
_path_processor(line 453), the blanking check was structured as:The
continuetargets the innerfor b in self.angles_blankedloop, not the outerfor angle, distance in dataloop. So regardless of whether an angle matched a blanked range, execution always fell through tocomplexes.append(...)at line 472.Notably, the standalone test script
system_hw_test/rptest.py(lines 276-282) already implements this correctly using a flag + break pattern, confirming this was a regression when the logic was ported into the provider class.Fix
Replace the broken nested loop with a single
any()expression:This works because
any()collapses the inner loop into a boolean expression, socontinuenow operates on the outerfor angle, distance in dataloop as intended. The generator insideany()short-circuits on the first match, preserving the same early-exit behavior asbreak.Affected configurations
Any robot with non-empty
angles_blankedwas impacted:config/turtlebot4.json5— blanks[-180, -160]and[110, 180]config/turtlebot4_lidar.json5config/turtlebot4_lidar_gps.json5config/test_lidar.json5Robots with
angles_blanked: [](all Go2 configs) were unaffected since the inner loop never executed.Tests added
test_path_processor_filters_blanked_angles: Feeds 4 sensor readings through_path_processorwithangles_blanked=[[-170, -150]]. Verifies that the 2 readings landing inside the blanked range are excluded and the 2 outside it survive. Each test angle is traced through the mounting offset and coordinate conversion to confirm correctness.test_path_processor_no_blanking_when_empty: Feeds 3 valid readings withangles_blanked=[]and verifies all 3 pass through, ensuring the fix doesn't introduce false positives.Test plan
ruff check— 0 errorsruff format --check— already formattedrptest.pyany()short-circuits on first match (no performance regression)