Skip to content

Route decomposed fields with per-cell TSP and entry-angle-aware stitching - #137

Merged
SteveMacenski merged 6 commits into
open-navigation:mainfrom
u33549:Feature/umutc/f2c-enhancements-main/decomp-multi-cell-tsp
Jul 27, 2026
Merged

SteveMacenski merged 6 commits into
open-navigation:mainfrom
u33549:Feature/umutc/f2c-enhancements-main/decomp-multi-cell-tsp

Conversation

@u33549

@u33549 u33549 commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Summary

Routes decomposed fields by solving TSP per sub-cell and stitching results with
optimized corridor transitions. Enables coverage planning on multi-cell fields
with correct per-cell ordering. Rejects non-TSP route modes early.

The Problem

Decomposed fields split into multiple sub-cells that share borders. A global
route planner (F2C's genRoute) can't optimize across cells — it processes the
entire multi-cell geometry at once and produces poor orderings or OOM errors on
large fields. A per-cell approach lets each sub-cell be solved independently at
TSP scale, then stitched together with optimized corridor transitions.

The Solution

Per-Cell TSP with Optimized Entry/Exit Selection:

  • Each decomposed sub-cell's swaths are solved independently via TSP (avoiding
    the all-in-one F2C genRoute that OOMs on large multi-cell fields)
  • Each cell can be entered from two ends (start or reversed-end), each with
    its own entry heading angle
  • After per-cell TSP, cells are connected via nearest-neighbor selection:
    for the current cell's end point, pick the next unvisited cell AND entry end
    that minimize: distance + swath_width * (heading_mismatch_penalty)
    • This avoids sharp-angle S-maneuvers between cells
    • Each unvisited cell is evaluated both forward and reversed
  • Bridge paths between cells run along the travel-cell pair border graph
    (not straight lines that could cut voids), so routing stays within valid regions
  • Result: globally-ordered swaths across all cells with entry-angle-aware,
    border-aware transitions

Stitch Turn Optimization:

  • Heading-aware entry: corridor entry point chosen to minimize heading
    mismatch (perpendicular entry preferred over sharp angles)
  • Spike filtering: bridge polylines drop attachment points that double back
    at junctions (numerical artifacts from geometry operations)

Path Emissions:

  • Route connections (inter-cell jumps, boundary transitions) are now emitted as
    HL_SWATH states in nav_path so visualization and debugging tools can render
    the stitch points

Early Validation:

  • Non-TSP route modes (BOUSTROPHEDON, SPIRAL, SNAKE, CUSTOM) rejected before
    geometry work; clear error message guides user to TSP or disable decomposition

Decomposition Connection: PR #135

Route corridors between decomposed cells (PR #135)
fixed the double-headland gaps. This PR builds on that foundation by routing
cells optimally with entry-angle-aware connections.

Test Coverage

  • test_server heap corruption fixed (action worker cleanup in teardown)
  • Per-cell route ordering validated with multi-cell test scenarios
  • Stitch maneuvers tested on synthetic bridge cases

Copilot AI review requested due to automatic review settings July 25, 2026 08:14

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 25, 2026 •

Copy link
Copy Markdown
Contributor Author

Algorithm: Per-Cell TSP + Entry-Angle-Aware Cell Connection

Input: Decomposed field (travel_cells, swath_cells A/B/C)

STEP 1: Solve each cell independently via TSP
Cell A         Cell B         Cell C
───────────    ───────────    ───────────
[S1,S2,S3] →   [S4,S5,S6] →   [S7,S8,S9] →
genRoute       genRoute       genRoute
│              │              │
Route_A:       Route_B:       Route_C:
S1→S2→S3       S4→S5→S6       S7→S8→S9
(can enter     (can enter     (can enter
 from start    from start     from start
 or end)       or end)        or end)

STEP 2: Nearest-neighbor selection with entry angle cost
unvisited = {A, B, C}
current = A (or nearest to start_pose — distance only, no angle yet)

while unvisited:
  for each unvisited_cell:
    for entry in [cell.start, cell.reversed_end]:
      cost = distance(current.end, entry.point)
      if from_angle known (i.e. not the first pick):
        cost += swath_width * (angle_diff1 + angle_diff2)
  pick (cell, entry) with min_cost
  current = best_cell   // reversed if entry == reversed_end

STEP 3: Build bridges via travel-cell pair border graph
connect current.end → next.entry:   // entry = start or reversed-end
  bridge = shortestPath(current_end, next_entry) on the two cells' borders
  // stays on cell borders, doesn't cut voids

Result: A(S1→S2→S3) ╌bridge╌ B(S4→S5→S6) ╌bridge╌ C(S7→S8→S9)
        (entry-optimized, border-aware routing)

STEP 4: Clean up spikes in polylines
• Remove attachment points that double back at junctions

Why this approach:

  • Per-cell TSP avoids F2C's all-pairs matrix OOM on large decomposed fields
  • Entry angle cost minimizes S-maneuvers and sharp turns between cells
  • Each cell can be traversed forward or reversed to optimize the overall path
  • Border graph bridges stay within valid regions, never cutting voids
  • Result: globally-ordered swaths with smooth, efficient inter-cell transitions

u33549 added 5 commits July 25, 2026 11:25
Global genRoute interleaved cells and criss-crossed the field. Each cell is
now solved alone (paired 1:1 with its carved swath cell), visited in
nearest-neighbor order entering from the closer route end (reversing when
needed), and bridged along the adjacent travel-cell pair's border graph
with whole-set and straight-line fallbacks.
F2C planPath drops connection waypoints when endpoints are close, cutting
straight across concave voids. Connections with a detour ratio above 1.3
are now emitted verbatim as HL_SWATH states; near-straight hops keep the
single Dubins/RS curve that produces the usual u-turns.
…ilter

Cell entry choice now weighs heading mismatch alongside distance, and
bridge polylines drop attachment points that double back at the junctions.
@u33549
u33549 force-pushed the Feature/umutc/f2c-enhancements-main/decomp-multi-cell-tsp branch from 57d8cb9 to d118cd1 Compare July 25, 2026 08:25
Comment thread opennav_coverage/src/route_method.cpp Resolved
@SteveMacenski
SteveMacenski merged commit dd1e0ed into open-navigation:main Jul 27, 2026
7 checks passed
SteveMacenski pushed a commit that referenced this pull request Nov 30, 2026
* Let Fields2Cover plan the swath connections

Fields2Cover 2.1.1 follows a connection track and rounds its corners
(Fields2Cover#234). The local appendConnection drove a detour verbatim,
turning 90 degrees at every corner. Use F2C's route planPath instead.

Adapted for humble: the connection handling removed here is #137's, with its 1.3 length-ratio rule; the deviation rule and distanceToSegment from #145 are not on humble.

(cherry picked from commit 5b95534, part of #171)
Signed-off-by: u33549 <[email protected]>

* Reverse cell routes with Fields2Cover's Route::reverse

Adapted for humble: the anonymous namespace held only these two helpers here, so it goes too.

(cherry picked from commit 2909e11, part of #171)
Signed-off-by: u33549 <[email protected]>

* Drop guards Fields2Cover 2.1.1 no longer needs

shortestPath returns an empty path for a non-node endpoint instead of
throwing, and createShortestGraph leaves out swath ends outside every
cell (Fields2Cover#239). Use F2CPoint::getAngleDiffAbs for the heading
cost.

Adapted for humble: the bridge guard here was the earlier pair_cells.size() > 0 check (the two-cell check came with #145). The per-pair try/catch in routeThroughCell is #145 code and is not on humble.

(cherry picked from commit 4fd8f6b, part of #171)
Signed-off-by: u33549 <[email protected]>

---------

Signed-off-by: u33549 <[email protected]>
SteveMacenski pushed a commit that referenced this pull request Nov 30, 2026
* Pin Fields2Cover to v2.1.1 for the upstreamed fixes

Fields2Cover v2.1.1 carries the fixes and APIs this package used to work
around: HL_SWATH densification, the corridor headland and the
degenerate-polygon guard.

Adapted for jazzy: jazzy-v2 only pins Fields2Cover in deps.repos, so only its version changes; the README note is updated to match.

(cherry picked from commit 2ef1796, part of #162)
Signed-off-by: u33549 <[email protected]>

* Drop the unused multi-cell headland overload

The server only calls the Field overload; the F2CCells one had no
callers left after the headland-first decomposition rework.

(cherry picked from commit 93915e2, part of #162)
Signed-off-by: u33549 <[email protected]>

* Carve the inter-cell corridor with Fields2Cover

CorridorHL finds the borders cells really share and carves the corridor
from the smaller cell. route_headland_width is now the total corridor
width; the previous code could carve it from both cells, or miss a
partially shared border.

(cherry picked from commit 8ecb2f4, part of #162)

Also drops the sliver filter Fields2Cover no longer needs:
CorridorHL already removes the zero-width pieces carving leaves, and the
degenerate-polygon crash the filter guarded against is fixed upstream.

(cherry picked from commit a4f3a87, part of #162)
Signed-off-by: u33549 <[email protected]>

* Remove the unused default_max_swaths_for_global_route parameter

It has had no effect since multi-cell TSP routing moved to a per-cell
solve; the threshold it set is no longer read.

(cherry picked from commit 852e0f1, part of #162)
Signed-off-by: u33549 <[email protected]>

* Report where a swath ends in the coverage path message

With Fields2Cover v2 a straight swath is a single path state, so taking
the end from that state's start point gave every swath start == end.
Use PathState::atEnd() instead.

Adapted for jazzy: only the swath end test is added; the HL_SWATH and headland perimeter tests next to it on main belong to #141, which is not on jazzy.

(cherry picked from commit af70ccf, part of #162)
Signed-off-by: u33549 <[email protected]>

* Densify GPS paths before leaving the field frame

The densification step is in meters, but it ran after the path was
converted to the GPS frame, so swath lengths were in degrees and no
state was ever split.

Adapted for jazzy: the densify call takes main's zero-step guard (pt_dist <= 0 falls back to 0.1 m). On main it came with the headland driving change, which is not on jazzy.

(cherry picked from commit e7eb93b, part of #162)
Signed-off-by: u33549 <[email protected]>

* Let Fields2Cover plan the swath connections

Fields2Cover 2.1.1 follows a connection track and rounds its corners
(Fields2Cover#234). The local appendConnection drove a detour verbatim,
turning 90 degrees at every corner. Use F2C's route planPath instead.

Adapted for jazzy: the connection handling removed here is #137's, with its 1.3 length-ratio rule; the deviation rule and distanceToSegment from #145 are not on jazzy.

(cherry picked from commit 5b95534, part of #171)
Signed-off-by: u33549 <[email protected]>

* Reverse cell routes with Fields2Cover's Route::reverse

Adapted for jazzy: the anonymous namespace held only these two helpers here, so it goes too.

(cherry picked from commit 2909e11, part of #171)
Signed-off-by: u33549 <[email protected]>

* Drop guards Fields2Cover 2.1.1 no longer needs

shortestPath returns an empty path for a non-node endpoint instead of
throwing, and createShortestGraph leaves out swath ends outside every
cell (Fields2Cover#239). Use F2CPoint::getAngleDiffAbs for the heading
cost.

Adapted for jazzy: the bridge guard here was the earlier pair_cells.size() > 0 check (the two-cell check came with #145). The per-pair try/catch in routeThroughCell is #145 code and is not on jazzy.

(cherry picked from commit 4fd8f6b, part of #171)
Signed-off-by: u33549 <[email protected]>

---------

Signed-off-by: u33549 <[email protected]>
@u33549
u33549 deleted the Feature/umutc/f2c-enhancements-main/decomp-multi-cell-tsp branch November 30, 2026 10:20
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