Skip to content

Route decomposed fields with per-cell TSP and entry-angle-aware stitching (jazzy) - #146

Merged
SteveMacenski merged 5 commits into
open-navigation:jazzy-v2from
u33549:Feature/umutc/f2c-enhancements-jazzy-v2/decomp-multi-cell-tsp
Aug 3, 2026
Merged

SteveMacenski merged 5 commits into
open-navigation:jazzy-v2from
u33549:Feature/umutc/f2c-enhancements-jazzy-v2/decomp-multi-cell-tsp

Conversation

@u33549

@u33549 u33549 commented Aug 1, 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 #142

Route corridors between decomposed cells (PR #142)
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

Ports rolling #137 to jazzy-v2, applied cleanly with no adaptation.

u33549 added 5 commits August 1, 2026 14:59
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.
Copilot AI review requested due to automatic review settings August 1, 2026 12:07

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.

Pull request overview

This PR improves coverage routing for decomposed (multi-cell) fields by solving TSP per sub-cell and stitching the per-cell routes together with border-aware bridge connections and heading-aware cell entry selection. It also adds early validation to reject non-TSP route modes when decomposition is enabled, and expands tests to cover multi-cell stitching and connection emission.

Changes:

  • Implement per-cell TSP planning for multi-cell inputs and stitch cells using nearest-neighbor selection with heading mismatch penalties and border-graph bridge paths.
  • Update path generation to explicitly assemble routes with inter-cell connections emitted as HL_SWATH path states.
  • Add early server-side validation for non-TSP + decomposition and add/adjust tests (including test server lifecycle cleanup).

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
opennav_coverage/test/test_server.cpp Adds teardown lifecycle cleanup in the shim to avoid worker-thread / destruction issues.
opennav_coverage/test/test_route.cpp Adds adjacent-cell fixture and tests for multi-cell TSP stitching and start-pose behavior.
opennav_coverage/test/test_path.cpp Adds coverage for multi-cell route connections making it through path generation.
opennav_coverage/src/route_method.cpp Implements multi-cell per-cell TSP + entry-angle-aware stitching and border-graph bridges.
opennav_coverage/src/route_generator.cpp Plumbs separate travel vs swath cell sets into route planning.
opennav_coverage/src/path_generator.cpp Switches to assembling the path explicitly and appends connection polylines as HL_SWATH.
opennav_coverage/src/coverage_server.cpp Adds early non-TSP+decomp rejection and passes travel/swath cells to routing.
opennav_coverage/include/opennav_coverage/route_method.hpp Updates route method API docs/signatures for travel vs swath cells.
opennav_coverage/include/opennav_coverage/route_generator.hpp Adds convenience overload and a resolvesToTsp() helper for early validation.
opennav_coverage/include/opennav_coverage/path_generator.hpp Declares assemblePath() and appendConnection() helpers used by the new path assembly.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +136 to +154
// The polyline detours (e.g. around a concave notch): follow it verbatim as
// HL_SWATH states so the vehicle stays on the planned border/corridor track.
for (size_t i = 0; i + 1 < pts.size(); ++i) {
const double dx = pts[i + 1].getX() - pts[i].getX();
const double dy = pts[i + 1].getY() - pts[i].getY();
const double len = std::hypot(dx, dy);
if (len < 1e-6) {
continue;
}
PathState s;
s.point = pts[i];
s.angle = std::atan2(dy, dx);
s.len = len;
s.dir = f2c::types::PathDirection::FORWARD;
s.type = f2c::types::PathSectionType::HL_SWATH;
s.velocity = robot.getCruiseVel();
path.addState(s);
}
}
@SteveMacenski
SteveMacenski merged commit c02a41e into open-navigation:jazzy-v2 Aug 3, 2026
7 checks passed
@u33549
u33549 deleted the Feature/umutc/f2c-enhancements-jazzy-v2/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