Skip to content

Route decomposed fields along headlands - #119

Merged
SteveMacenski merged 5 commits into
open-navigation:mainfrom
u33549:Feature/umutc/f2c-enhancements-main/4-route-decomp
Jul 9, 2026
Merged

SteveMacenski merged 5 commits into
open-navigation:mainfrom
u33549:Feature/umutc/f2c-enhancements-main/4-route-decomp

Conversation

@u33549

@u33549 u33549 commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Completes decomposition-with-route support: routes decomposed (multi-cell)
fields along their headlands so inter-cell connections follow the shared
headland, and fixes a multi-cell headland crash. Builds on #112, #113, #117.

Changes

Route decomposed fields along headlands

  • Previously a decomposed field applied the headland per sub-cell first, leaving
    each cell a disconnected island; per-cell TSP then stitched routes with
    straight-line bridges that cut across the field. Non-TSP modes flattened the
    multi-cell swaths into a single-cell orderer, fanning connections across the field.
  • Now: shrink the whole field to a travel ring, decompose it, then shrink each
    sub-cell again for the swath area. genRoute is fed the border-sharing travel
    cells so inter-cell connections follow the headlands.
  • generateRouteTSP takes separate travel_cells and swath_cells: small fields
    use a single global genRoute; large fields (swath count above a cap) fall back
    to per-cell TSP to avoid the O(N²) all-pairs OOM.
  • Non-TSP route modes combined with decomposition are rejected with a clear
    INVALID_MODE_SET error.
  • Decomposed cells and swaths are reused across the swath and TSP branches.

Fix multi-cell headland crash on collapsed sub-cells

  • The multi-cell generateHeadlands(F2CCells) overload applied the headland to
    each sub-cell through the single-Field overload (ending in .getGeometry(0)).
    ConstHL is a negative buffer, so a sub-cell narrower than ~2×width collapses to
    empty and getGeometry(0) threw "Geometry does not contain point 0" on
    decomposed fields.
  • Buffer each sub-cell directly, skip cells that collapse to empty, add every
    resulting polygon (a negative buffer may split one cell into several), and throw
    a clear CoverageException if every sub-cell collapses. Generator/width
    resolution extracted into a shared resolveGenerator() helper.

u33549 added 2 commits July 8, 2026 22:48
A sub-cell narrower than ~2x the headland width collapsed to an empty
geometry under the inward buffer, and getGeometry(0) then threw instead
of being handled.

Buffer each sub-cell directly, skip empty results, and keep every
polygon a split may produce; throw a clear error only if every cell
collapses. Adds regression tests for both cases.
Decomposed fields applied the headland per sub-cell first, isolating
each cell; routes then bridged cells with straight lines cutting
across the field.

Shrink the field to a travel ring first, decompose that, then shrink
each sub-cell again for its swaths, so connections follow the shared
headland instead. TSP planning uses a single global genRoute for small
fields and falls back to per-cell TSP above a swath-count cap, avoiding
an all-pairs OOM. Non-TSP route modes are rejected with decomposition,
since they only support a single cell.
Copilot AI review requested due to automatic review settings July 8, 2026 20:52

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@u33549

u33549 commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

In the next PR, or once everything is complete, can I update opennav_coverage_demo to showcase the new system?

I tried symbols like a balloon or a navigation icon, but they didn't look very good. I'll probably try a simpler letter or shape.

@u33549

u33549 commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

It also works well with simple shapes, but as the shape becomes more complex, for example, as gaps are added or the concavity increases, it can sometimes produce different results. Once the integration is complete, I’ll try to set aside some time specifically for making improvements.

Comment thread opennav_coverage/src/route_method.cpp Outdated

// Above this many total swaths, TspRouteMethod falls back to per-cell TSP to avoid
// F2C's O(N^2) all-pairs path matrix that OOMs on large decompositions.
static constexpr size_t kMaxSwathsForGlobalRoute = 300;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did you determine this value and what computer did you test it against that caused memory issues?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly the value is approximate — I hit an actual out-of-memory crash (blue-screen) while testing a very large field on my own machine, so I set a conservative cap below where that happened rather than a precisely-tuned number. The root cause is algorithmic: F2C v2.0.0's RoutePlannerBase materializes the all-pairs shortest-path matrix (~N² with N ≈ 4× total swaths), so it blows up on large decompositions regardless of the machine. However, it might be helpful to make this parametric.

This is fixed upstream in F2C commit 0ce7fcc, but that landed on main after the v2.0.0 release and we depend on the released v2, so we can't pull it in yet.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. How about stating a warning in the docs instead of setting an arbitrary limit?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But wouldn’t that eliminate its usability in these large areas? Wouldn’t it make more sense to convert it to a parameter and add a warning?

Also, the per-cell fallback isn't only a theoretical guard, it's what keeps large decomposed fields returning a valid (if less-optimal) route instead of crashing. Concretely, testTSPDecompHeadlandPath already exercises it: test_field.xml has enough swaths to cross the threshold, so removing the fallback would send that test through a single genRoute over the whole swath set ,exactly the case that risks the OOM/timeout in CI.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK - parameterize then :-)

@SteveMacenski

Copy link
Copy Markdown
Member

Can I update opennav_coverage_demo to showcase the new system?

Sure! That'd be great. Maybe mention some of the new features too in the readme that this adds if there's a logical place for it

Comment thread opennav_coverage/src/route_method.cpp Resolved
u33549 added 2 commits July 9, 2026 22:52
default_max_swaths_for_global_route replaces the hard-coded threshold, with a note
on when to tune it; drop the redundant show_log argument comments.
@SteveMacenski
SteveMacenski merged commit 03979cc into open-navigation:main Jul 9, 2026
7 checks passed
@u33549

u33549 commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

There are probably just a few PRs left before this development is complete. After that, I’ll entegrate to other distros. I also asked the F2C developer to add commit 0ce7fcc to v2.0.0

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.

3 participants