Short-circuit elevation>0 to LETHAL in s57_layer get_cost_from_grid#22
Merged
Conversation
Land / lethal S57 features (LNDARE, COALNE, CAUSWY, HULKES, PONTON, SLCONS, FSHFAC, GATCON, OBSTRN, PILPNT, PYLONS, DAMCON, DYKCON) are rasterized into the elevation channel with a constant 1.0 in marine_charts/src/s57_dataset.cpp, with the explicit comment "no min depth values, so lethal". That encoding worked while tide_offset_ was always 0 (depth = -1 + 0 = -1 < minimum_depth_ = 0 → LETHAL), but breaks the moment the chart_datum_frame / sea_surface_frame parameters are set: as soon as tide_offset_ exceeds ~minimum_depth_ + 1.0, the depth math (-elevation + tide_offset_) makes every coastline cell report a positive depth and become FREE / CAUTION. In Portsmouth field bag 2026-04-24T17.39.30 we observed tide_offset_ ramping smoothly from 1.67 m to 2.0 m during normal in-water operation — i.e., for the entire run, every land polygon in the S57 chart was navigable in the costmap. This is what was meant by "costmap no longer looks correct now that we are accounting for tides" (#21). Fix: short-circuit elevation > 0 to LETHAL_OBSTACLE before applying the tide-offset depth math. Anything above chart datum is shoreline / intertidal / built feature and should be lethal regardless of tide. The depth math then runs only for genuinely submerged cells, where it makes sense. Tests: - LandFeatureLethalAcrossAllTides — sweeps tide_offset across [-1, 0, 0.5, 1, 2, 3, 5, 7] m for an elevation = 1.0 cell and asserts LETHAL at every level. Would fail prior to this fix at any tide >= 1.0 m. - SubmergedCellUsesTideAdjustedDepth — guards the existing depth = -elevation + tide_offset_ behavior for negative-elevation cells: 5 m-deep at -1 m tide is not lethal, at +2 m tide it is FREE_SPACE; a 1 m-deep cell drained to -0.5 m at low tide is lethal. Visibility change: get_cost_from_grid moved from private to protected so the test fixture can subclass S57Layer. No external API change. Closes #21 --- **Authored-By**: \`Claude Code Agent\` **Model**: \`Claude Opus 4.7 (1M context)\`
There was a problem hiding this comment.
Pull request overview
Fixes an incorrect interaction between tide offset and how S57 land features are rasterized, ensuring land/shoreline remains non-navigable regardless of tide height.
Changes:
- Short-circuit
elevation > 0.0toLETHAL_OBSTACLEinS57Layer::get_cost_from_grid()before applying tide-adjusted depth math. - Add unit tests to validate land stays lethal across tides and submerged cells still use tide-adjusted depth behavior.
- Change
get_cost_from_gridaccess to enable direct testing via subclassing.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| s57_layer/src/s57_layer.cpp | Adds elevation > 0 early return to keep land lethal regardless of tide_offset_. |
| s57_layer/src/s57_layer.h | Changes member visibility to protected to support test subclass access. |
| s57_layer/test/test_tide_offset.cpp | Adds a test subclass + 1x1 grid helper and two unit tests covering land vs submerged behavior with tides. |
Comments suppressed due to low confidence (1)
s57_layer/src/s57_layer.h:47
- Changing the access specifier from
privatetoprotectedmakes all following helpers and internal state (e.g.,worldToLatLon, subscriptions/maps, tile cache, thresholds, etc.) part of the subclass API. That’s a broader encapsulation break than what the tests need (callingget_cost_from_grid+ settingtide_offset_). Consider keeping most membersprivateand exposing only a minimal protected surface (e.g., keepget_cost_from_gridprotected and add a protectedsetTideOffset()), or otherwise re-introduceprivate:after the specific items that must be testable.
protected:
using GetDatasetsClient =
rclcpp::Client<s57_msgs::srv::GetDatasets>;
unsigned char get_cost_from_grid(grid_map::GridMap &grid, const grid_map::Index &index);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+269
to
+279
| // Helper: build a 1x1 grid_map with all S57 channels initialized to NaN. | ||
| // Caller fills in only the channel(s) they want to test. | ||
| static grid_map::GridMap makeEmptyS57Grid() | ||
| { | ||
| grid_map::GridMap grid({"elevation", "overhead", "restricted", | ||
| "unsurveyed", "caution"}); | ||
| grid.setGeometry(grid_map::Length(1.0, 1.0), 1.0, | ||
| grid_map::Position(0.0, 0.0)); | ||
| for (const auto & name : grid.getLayers()) { | ||
| grid[name].setConstant(std::numeric_limits<float>::quiet_NaN()); | ||
| } |
There was a problem hiding this comment.
makeEmptyS57Grid() uses std::numeric_limits<float>::quiet_NaN() but this test file doesn’t include <limits>. Please add the missing standard header to avoid relying on transitive includes (which can break with different compilers / include order).
Two findings from Copilot review of e8e4ec0: - test_tide_offset.cpp uses std::numeric_limits<float>::quiet_NaN() but did not include <limits>; it worked via transitive includes. Add the explicit include. - s57_layer.h previously moved the entire private: block to protected:, exposing all internal helpers (worldToLatLon, llToWorld, callbacks) and member state (subscription / tile cache / thresholds, etc.) to any subclass. The tests only need get_cost_from_grid and tide_offset_. Tighten the protected surface to just those two; the rest goes back to private. No external API change. --- **Authored-By**: \`Claude Code Agent\` **Model**: \`Claude Opus 4.7 (1M context)\`
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
elevation > 0.0toLETHAL_OBSTACLEinget_cost_from_grid, before the tide-offset depth math runs.test_tide_offset.cpp:LandFeatureLethalAcrossAllTides(would fail prior to this fix) andSubmergedCellUsesTideAdjustedDepth(guards existing depth-from-tide behavior).get_cost_from_gridfromprivatetoprotectedso the test fixture can subclass. No external API change.Background and analysis in #21 (field bag
2026-04-24T17.39.30, BizzyBoat). The "land = elevation 1.0" trick inmarine_chartswas incompatible with non-zerotide_offset_— every coastline became navigable at any tide above ~1 m above MLLW.Test plan
colcon test --packages-select s57_layer— 25 tests, 0 failuresLandFeatureLethalAcrossAllTidesandSubmergedCellUsesTideAdjustedDepthran and passedCloses #21
Authored-By: `Claude Code Agent`
Model: `Claude Opus 4.7 (1M context)`