-
Notifications
You must be signed in to change notification settings - Fork 2
Run the dilation filter regardless of the traversability filter #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
deepanaishtaweera
merged 2 commits into
main
from
fix/normals-without-traversability-filter
Aug 10, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| """The normal layers must not depend on the traversability filter. | ||
|
|
||
| ``update_map_with_kernel`` feeds ``update_normal`` the ``traversability_input`` | ||
| buffer, which holds the dilated upper-bound surface. The learned traversability | ||
| filter reads that same buffer, so it is easy to guard the dilation that fills it | ||
| behind ``traversability_filter is not None`` -- which leaves the buffer all zeros | ||
| whenever the filter is unavailable, and every normal silently becomes (0, 0, 1) | ||
| regardless of terrain. | ||
|
|
||
| These tests drive the real pipeline with the filter deliberately disabled, which | ||
| is the configuration that regressed. | ||
| """ | ||
|
|
||
| import math | ||
| from pathlib import Path | ||
|
|
||
| import cupy as cp | ||
| import numpy as np | ||
| import pytest | ||
|
|
||
| from elevation_mapping_cupy import elevation_mapping, parameter | ||
|
|
||
| CONFIGS = Path(__file__).parent.parent / "configs" | ||
|
|
||
| RESOLUTION = 0.05 | ||
| MAP_LENGTH = 4.0 | ||
| #: Sample the plane finer than the grid so every interior cell gets several hits. | ||
| POINT_SPACING = 0.02 | ||
| POINT_HALF_EXTENT = 1.5 | ||
|
|
||
|
|
||
| def _make_map(weight_file: str): | ||
| """An ElevationMap over a plain geometric configuration. | ||
|
|
||
| ``weight_file=""`` is the supported way to run without the learned filter | ||
| (see ``ElevationMap.__init__``), and is what a host with no CUDA-capable | ||
| torch effectively falls back to. | ||
| """ | ||
| param = parameter.Parameter( | ||
| use_chainer=False, | ||
| weight_file=weight_file, | ||
| plugin_config_file=str(CONFIGS / "plugin_config.yaml"), | ||
| resolution=RESOLUTION, | ||
| map_length=MAP_LENGTH, | ||
| enable_visibility_cleanup=False, | ||
| enable_drift_compensation=False, | ||
| ) | ||
| # A purely geometric run never writes the default semantic layers. | ||
| param.subscriber_cfg = {} | ||
| param.update() | ||
| return elevation_mapping.ElevationMap(param) | ||
|
|
||
|
|
||
| def _plane_points(slope_deg: float) -> cp.ndarray: | ||
| """A dense point cloud on the plane ``z = x * tan(slope)``, in world frame.""" | ||
| axis = np.arange(-POINT_HALF_EXTENT, POINT_HALF_EXTENT, POINT_SPACING, dtype=np.float32) | ||
| x, y = np.meshgrid(axis, axis, indexing="ij") | ||
| z = x * math.tan(math.radians(slope_deg)) | ||
| points = np.stack([x.ravel(), y.ravel(), z.ravel()], axis=1) | ||
| return cp.asarray(points, dtype=cp.float32) | ||
|
|
||
|
|
||
| def _feed(em, slope_deg: float): | ||
| """Push one sweep of the plane through the full input path.""" | ||
| points = _plane_points(slope_deg) | ||
| R = cp.eye(3, dtype=em.param.data_type) | ||
| t = cp.zeros(3, dtype=em.param.data_type) | ||
| em.input_pointcloud(points, ["x", "y", "z"], R, t, 0.0, 0.0) | ||
|
|
||
|
|
||
| def _interior(em, layer: str) -> np.ndarray: | ||
| """A layer cropped to the well-covered middle, where normals have neighbours.""" | ||
| data = cp.asnumpy(em.get_map_with_name_ref(layer, return_cupy=True)) | ||
| margin = data.shape[0] // 4 | ||
| return data[margin:-margin, margin:-margin] | ||
|
|
||
|
|
||
| def _recovered_tilt_deg(em) -> float: | ||
| """Slope angle implied by the normal layers, in degrees.""" | ||
| nx, nz = _interior(em, "normal_x"), _interior(em, "normal_z") | ||
| valid = np.abs(nz) > 1e-6 | ||
| assert valid.sum() > 100, "too few cells carry a normal to measure a tilt" | ||
| return float(np.rad2deg(np.arctan2(-np.median(nx[valid]), np.median(nz[valid])))) | ||
|
|
||
|
|
||
| def test_traversability_filter_is_actually_disabled(): | ||
| """Guards the premise of the tests below.""" | ||
| assert _make_map("").traversability_filter is None | ||
|
|
||
|
|
||
| def test_normals_tilt_on_a_slope_without_the_traversability_filter(): | ||
| """The regression test: normals must track terrain with the filter absent. | ||
|
|
||
| Against the bug the dilated surface stays all zeros, so every normal is | ||
| (0, 0, 1) and this reads back 0 degrees rather than the true slope. | ||
| """ | ||
| em = _make_map("") | ||
| _feed(em, slope_deg=15.0) | ||
| assert _recovered_tilt_deg(em) == pytest.approx(15.0, abs=5.0) | ||
|
|
||
|
|
||
| def test_normals_point_up_on_flat_ground_without_the_traversability_filter(): | ||
| """The flat case cannot catch the bug on its own, but pins the sign convention. | ||
|
|
||
| (0, 0, 1) is the correct answer here, so this passes either way -- it is | ||
| what makes the slope result above meaningful rather than a scaling artefact. | ||
| """ | ||
| em = _make_map("") | ||
| _feed(em, slope_deg=0.0) | ||
| nx, ny, nz = (_interior(em, layer) for layer in ("normal_x", "normal_y", "normal_z")) | ||
| valid = np.abs(nz) > 1e-6 | ||
| assert valid.sum() > 100 | ||
|
|
||
| norm = np.sqrt(nx[valid] ** 2 + ny[valid] ** 2 + nz[valid] ** 2) | ||
| np.testing.assert_allclose(norm, 1.0, atol=1e-3) | ||
| assert np.median(nz[valid]) > 0.99 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.