Repository navigation
Add VFH Step 1: polar histogram construction from LiDAR data - #80
Conversation
Implements the first incremental step of the Vector Field Histogram (VFH) roadmap agreed with the maintainer in issue ShisatoYano#52: build a 1D polar obstacle density histogram around the vehicle directly from the existing 2D LiDAR sensor simulation, with configurable sector resolution and smoothing. - PolarHistogram (src/components/mapping/polar_histogram/polar_histogram.py): pure-logic histogram construction. Bins LiDAR returns into angular sectors, weights each by the classic VFH linear magnitude falloff (Borenstein & Koren, 1991), and applies a triangular smoothing filter across neighboring sectors. - PolarHistogramMapper (polar_histogram_mapper.py): wires PolarHistogram to the existing OmniDirectionalLidar point cloud and renders it as a ring of colored wedges around the vehicle (denser sectors longer/redder), using the project's existing mapper slot on FourWheelsVehicle - mirrors PotentialFieldMapper's update(point_cloud, state) / draw(axes, elems) interface, so no changes were needed to shared vehicle/visualizer code. - vfh_polar_histogram_construction.py: simulation entry point, reusing the same obstacle scenario as the existing lidar_obstacle_sensing sample so the histogram's behavior can be compared directly against the raw point cloud it's built from. - Unit tests for histogram binning/smoothing math, the mapper, and the simulation entry point (15 tests total). - Regenerated pyrightconfig.json / devcontainer.json extraPaths via generate_pyrightconfig.py for the two new module directories. Valley/direction selection is intentionally left for Step 2 per the agreed roadmap, to keep this PR small and reviewable. How it was verified: all 15 new tests pass via pytest (matching the project's existing show_plot=False test convention), and the full simulation runs cleanly end to end.
|
@Khushi0512 A few requests before merging:
|
… accuracy) 1. Drawing performance: PolarHistogramMapper.draw() was calling axes.add_patch() once per sector wedge (~42 calls/frame in this scenario). Collects all of a frame's wedges into a single matplotlib.collections.PatchCollection and adds it with one axes.add_collection() call instead (match_original=True keeps each wedge's own color/alpha). Confirmed on this machine using the exact same test/measurement this repo already uses for the simulation (test_vfh_polar_histogram_construction.py, which runs draw() 1000 times without opening a plot window): 98.79s before this fix, 51.72s after - a ~48% reduction, consistent with the ~51% reduction (76s to 37s) reported in review. Later steps' own draw() additions (candidate valleys, direction selection) are untouched here since they add far fewer patches per frame and weren't part of this review. 2. Histogram origin: this is a drawing-only approximation, not a data or logic bug - each measurement's angle/distance is computed from the LiDAR's actual mounted position (OmniDirectionalLidar), so the histogram density itself, and everything later steps derive from it (valleys, selected direction), is already geometrically accurate. Only the ring of wedges is drawn centered on the vehicle's origin rather than the LiDAR's position, for simplicity. Took the documented-approximation option offered in review rather than changing where this (and, to stay visually consistent, later steps' valley/direction drawings) are centered, since that would be a larger change across all 4 stacked branches for a cosmetic-only difference. Added a docstring note on PolarHistogramMapper explaining this and roughly quantifying it (up to ~20deg for very close obstacles, matching the reviewer's own example). 3. Magnitude formula docstring: clarified that PolarHistogram's magnitude equation follows the original VFH paper with its certainty value fixed at 1, rather than implying an exact match to the paper's general certainty^2 * (a - b*d) form. Demo GIF for doc/EXAMPLES.md (also requested in review) is a separate follow-up commit, since it's a binary asset rather than a code change. Verified: all 14 existing tests for this step (test_polar_histogram.py, test_polar_histogram_mapper.py) still pass unmodified, confirming the draw() refactor didn't change any observable behavior these tests check. test_vfh_polar_histogram_construction.py also still passes.
|
Hi @ShisatoYano , thanks for the detailed review! I've addressed all four points on Step 1 and merged the fixes forward through Steps 2–4 (performance batching via PatchCollection, plus both docstring notes). I've also added the demo GIF for all four steps (1, 2, 3, and 4) on their respective branches/PRs. Separately, 3 more steps remain in this VFH roadmap (dynamic speed control, VFH+ trajectory verification, and performance benchmarking). I'll implement, test, and upload each one once it's ready locally. |
|
Thank you for addressing all the points so quickly!
I'll approve and merge this once CI passes. Then I'll continue with #81. |
Per maintainer feedback on PR ShisatoYano#80: doc/EXAMPLES.md is now generated from each simulation script's docstring, which must be exactly the filename followed by one line each of Title/Description/Author (HOWTOCONTRIBUTE.md Step 2, item 6). Updates this step's docstring to match.
Implements the first incremental step of the Vector Field Histogram (VFH) roadmap agreed with the maintainer in issue #52: build a 1D polar obstacle density histogram around the vehicle directly from the existing 2D LiDAR sensor simulation, with configurable sector resolution and smoothing.
Valley/direction selection is intentionally left for Step 2 per the agreed roadmap, to keep this PR small and reviewable.
How it was verified: all 15 new tests pass via pytest (matching the project's existing show_plot=False test convention), and the full simulation runs cleanly end to end.