Skip to content

Support non-TSP route modes with field decomposition - #145

Merged
SteveMacenski merged 4 commits into
open-navigation:mainfrom
u33549:multi-cell-swath-order-routing
Aug 3, 2026
Merged

SteveMacenski merged 4 commits into
open-navigation:mainfrom
u33549:multi-cell-swath-order-routing

Conversation

@u33549

@u33549 u33549 commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Motivation

BOUSTROPHEDON, SNAKE, and SPIRAL were rejected whenever decomposition produced
multiple cells. The restriction came from #119, before this package had its own
per-cell stitching layer; #137 built that layer for TSP and the rejection was
never revisited. Since default_route_type is BOUSTROPHEDON, enabling
generate_decomp with stock parameters threw INVALID_MODE_SET.

Changes

Enable the swath-order modes for multi-cell fields. Flattening the per-cell
swaths before ordering collided their per-cell ids and interleaved the cells, so
each cell is now ordered on its own and handed to the same stitch layer TSP uses
(extracted from TspRouteMethod). CUSTOM stays rejected — its order vector
indexes swaths absolutely and cannot be split across cells.

Two connection bugs surfaced while validating this in RViz. Both predate the
branch and both affect TSP as well:

Cell-internal transitions ignored the boundary. Each cell's swaths were
wrapped in a single connection-less group, so every transition became a naked
Dubins turn and a SNAKE/SPIRAL skip cut across covered ground. Cells now route
through F2C's shortest-path graph, connecting every consecutive swath pair.

The detour test used a length ratio. A connection collapsed to a single turn
below 1.3x the direct distance, which cannot separate a u-turn from a detour —
rounding a long cell's corner is only ~20% longer than cutting its diagonal. One
measured 36.3 m of polyline against 30.7 m direct and became a 30 m diagonal.
Peak deviation from the straight hop is now the criterion.

Bridges trusted a half-resolved cell pair. getCellWherePoint can miss an
endpoint sitting on a cell border. The graph was still built from the single
remaining cell and reached the far endpoint by jumping off its border. Since the
result had ≥2 points it counted as a success and the whole-set fallback never ran.

Testing

Unit tests cover multi-cell ordering, SNAKE/SPIRAL planning, CUSTOM rejection,
and the unchanged single-cell path. Verified in RViz on concave E- and
zigzag-shaped fields across all modes.

u33549 added 4 commits August 1, 2026 12:41
BOUSTROPHEDON, SNAKE, and SPIRAL were rejected whenever field
decomposition produced multiple cells, because flattening per-cell
swaths before ordering collided their per-cell ids and interleaved
cells. They now order each cell independently and stitch the results
with the same nearest-neighbour, border-graph-bridging layer TSP
already used (extracted into stitchCellRoutes). CUSTOM stays rejected
for multi-cell: its order vector can't be split across cells.

Known issue: manual testing shows this can still produce swath
overlap in some multi-cell fields, likely on the F2C side. Parking
this branch as-is rather than chasing it now.
Multi-cell BOUSTROPHEDON, SNAKE, and SPIRAL wrapped each cell's swaths in a
single connection-less group, so every transition inside a cell became a
naked Dubins turn with no knowledge of the boundary. A SNAKE or SPIRAL skip
spans several swath widths, and that turn cut straight across ground the
route had already covered.

Each cell now routes through F2C's shortest-path graph over the cell
border, the machinery TSP's per-cell genRoute already used, so a cell route
carries a connection between every consecutive swath pair. A pair whose
endpoint is not a graph node falls back on its own.
A connection was replaced by a single turn when its polyline ran under 1.3x
the straight distance. That ratio cannot separate a u-turn from a detour:
rounding a long cell's corner is only ~20% longer than cutting its
diagonal, so real border-following connections were collapsing into
straight lines through the field. One measured 36.3 m of polyline against
30.7 m direct, a ratio of 1.18, and became a 30 m diagonal.

Compare the waypoints' peak deviation from the straight hop instead.
Headland u-turn waypoints are collinear with it, so they still get a curve,
while anything the graph routed around keeps its polyline.
getCellWherePoint can miss an endpoint that sits on a cell border, leaving
one cell in the pair. The graph was still built from that single cell, and
it reached the far endpoint by jumping off that cell's border, cutting
across whatever lay between. Because the result had two or more points it
counted as a success, so the whole-set fallback never ran.

Require both cells before trusting the pair graph; otherwise go straight to
the graph over every travel cell, which is connected along their shared
borders and routes around the gap.
Copilot AI review requested due to automatic review settings August 1, 2026 11:36
@u33549

u33549 commented Aug 1, 2026

Copy link
Copy Markdown
Contributor Author

Visual verification — concave E-shaped field

Decomposed into 4 cells (11 swaths each). All four route modes plan without
cutting across covered ground or leaving the field.

Goal used
ros2 action send_goal /compute_coverage_path opennav_coverage_msgs/action/ComputeCoveragePath "{
  generate_decomp: true, generate_headland: true, generate_route: true, generate_path: true,
  use_gml_file: false, frame_id: 'map',
  polygons: [{coordinates: [
    {axis1: 0.0, axis2: 0.0}, {axis1: 32.0, axis2: 0.0}, {axis1: 32.0, axis2: 8.0},
    {axis1: 8.0, axis2: 8.0}, {axis1: 8.0, axis2: 16.0}, {axis1: 32.0, axis2: 16.0},
    {axis1: 32.0, axis2: 24.0}, {axis1: 8.0, axis2: 24.0}, {axis1: 8.0, axis2: 32.0},
    {axis1: 32.0, axis2: 32.0}, {axis1: 32.0, axis2: 40.0}, {axis1: 0.0, axis2: 40.0},
    {axis1: 0.0, axis2: 0.0}]}],
  decomp_mode: {mode: 'TRAPEZOIDAL', split_angle: 1.5708},
  route_headland_width: 0.5,
  headland_mode: {mode: 'CONSTANT', width: 0.3},
  swath_mode: {objective: 'NUMBER', mode: 'BRUTE_FORCE'},
  route_mode: {mode: 'SPIRAL', spiral_n: 3},
  path_mode: {mode: 'DUBIN', continuity_mode: 'CONTINUOUS', turn_point_distance: 0.1}
}"

Only route_mode differs between the runs below.

BOUSTROPHEDON

BOUSTROPHEDON

SNAKE — note the skip pattern: consecutive passes sit two swath widths
apart, which is what the order modes offer over TSP and what TSP's
distance-only cost cannot produce.

SNAKE

SPIRAL (spiral_n: 3)

SPIRAL

TSP (tsp_time_limit: 3) — unchanged behaviour, included as the reference.

TSP

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 enables multi-cell (decomposed) coverage planning for the non-TSP swath-order route modes (BOUSTROPHEDON, SNAKE, SPIRAL) by ordering per-cell swaths independently and then stitching the per-cell routes together using the same multi-cell stitch layer previously used for TSP, while continuing to reject CUSTOM for decomposed fields.

Changes:

  • Update SwathOrderMethod to support multi-cell inputs by planning per-cell, routing transitions via the cell border graph, and stitching cell routes (start_pose-aware at the stitch level).
  • Fix/strengthen multi-cell connection behaviors: ensure intra-cell transitions respect the border graph; improve detour detection in path emission; harden bridge graph selection when endpoints lie on cell borders.
  • Add/adjust unit tests to cover multi-cell ordering, multi-cell SNAKE/SPIRAL planning, CUSTOM rejection, and preservation of the single-cell behavior.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
opennav_coverage/test/test_server.cpp Updates server test to specifically validate CUSTOM+decomposition rejection.
opennav_coverage/test/test_route.cpp Adds unit tests for multi-cell non-TSP ordering/stitching and keeps single-cell behavior guarded.
opennav_coverage/src/route_method.cpp Implements per-cell planning + stitching for non-TSP modes; adds intra-cell graph-based transitions; hardens bridge routing.
opennav_coverage/src/route_generator.cpp Passes logger into SwathOrderMethod and refines start_pose warning behavior for single-cell non-TSP modes.
opennav_coverage/src/path_generator.cpp Replaces length-ratio detour heuristic with a max-deviation heuristic for preserving meaningful polylines.
opennav_coverage/src/coverage_server.cpp Changes early rejection to only block CUSTOM+decomposition (allowing other non-TSP modes).
opennav_coverage/include/opennav_coverage/route_method.hpp Updates SwathOrderMethod documentation and constructor to carry a logger.
opennav_coverage/include/opennav_coverage/route_generator.hpp Renames/repurposes early-check helper to resolvesToCustom() with updated documentation.

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

Comment thread opennav_coverage/src/route_method.cpp Resolved
@u33549

u33549 commented Aug 1, 2026

Copy link
Copy Markdown
Contributor Author

Known limitation: unsmoothed corners on border-following connections

Worth flagging since this PR makes it visible. When a connection follows the
border graph, the polyline is emitted verbatim as HL_SWATH states with no
curvature smoothing, so a right-angle corner in the cell boundary becomes a
right-angle corner in the path:

PathState s;
s.point = pts[i];
s.angle = std::atan2(dy, dx);   // raw segment heading
s.type = f2c::types::PathSectionType::HL_SWATH;
corner 1 corner 2 corner 3

The rounded loops in these crops are createTurn output and respect the turning
radius; only the sharp vertices come from the polyline.

This is pre-existing behaviour from #137, not new here — but the old 1.3x length
ratio collapsed most of these connections into straight lines, so they rarely
surfaced. Switching to the deviation criterion keeps them, which is correct
geometrically and exposes the missing smoothing.

The corners are not followable at min_turning_radius (0.35 m in the demo), so
the controller will cut them. That is harmless where the cut falls inside the
cell, less so where the polyline hugs the field boundary.

I'm not sure this is worth fixing, or whether it causes a real problem in
practice — the controller may absorb it fine. Interested in your read. Unless
you say otherwise, I'll address it in a follow-up PR.

@u33549

u33549 commented Aug 1, 2026

Copy link
Copy Markdown
Contributor Author

Although this deviates from the plan in PR #141, it is one of the steps in resolving the overlap issue.

@SteveMacenski
SteveMacenski merged commit 29c96cf into open-navigation:main Aug 3, 2026
7 checks passed
@SteveMacenski

Copy link
Copy Markdown
Member

What's the fix to have the smoothing applied in that edge case?

@u33549

u33549 commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor Author

I'll apply a minimum turn angle to these corners, or I'll create them as turn objects within F2C.

@u33549
u33549 deleted the multi-cell-swath-order-routing branch August 3, 2026 20:47
@u33549
u33549 restored the multi-cell-swath-order-routing branch August 3, 2026 21:09
@u33549

u33549 commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

I just want to get some feedback. What do you think about how we are going?

@SteveMacenski

Copy link
Copy Markdown
Member

Good in general! this is just alot of changes very fast in a piece of code I don't use often, so I'm kind of just letting it go right now with your best judgement except if I see something in particular I think needs to be changed. I'm trusting you to check your work and test edge cases that what you're doing works well robustly :-)

@u33549

u33549 commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

Thank you I'm trying to do my best.

@u33549

u33549 commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author
image image image image image

I've done some work on anti-aliasing, and I'm a little confused, but these are the best results I've been able to get.

@SteveMacenski

Copy link
Copy Markdown
Member

Those seem good to me

SteveMacenski pushed a commit that referenced this pull request Nov 6, 2026
* Fix `ros2 param list` due to issue with default_custom_order (#151)

Before this patch, `ros2 param dump` and `rqt_reconfigure` would not
work:

```
  ros2 run opennav_coverage opennav_coverage
  ros2 lifecycle set /coverage_server configure
  ros2 lifecycle set /coverage_server activate
  ros2 param dump /coverage_server
  /coverage_server:
    ros__parameters: {}
```

After this patch, `ros2 param dump` works as expected:

```
  ros2 param dump /coverage_server
  /coverage_server:
    ros__parameters:
      /bond_disable_heartbeat_timeout: true
      action_server_result_timeout: 10.0
      ...
```

Signed-off-by: Ramon Wijnands <[email protected]>
Co-authored-by: Copilot <[email protected]>

* Add optional headland driving (perimeter loop or full band coverage) (#141)

* Add generateHeadlandSwaths to sweep the headland band with concentric rings

* Add toHeadlandPerimeterPath helper and densify HL_SWATH path states

* Visualize the headland pass as a distinct marker, clearing it when unused

* Add optional headland driving via goal fields and splice it onto the path

(cherry picked from commit 67f2c0f)

* Support non-TSP route modes with field decomposition (#145)

* Allow non-TSP route modes with field decomposition

BOUSTROPHEDON, SNAKE, and SPIRAL were rejected whenever field
decomposition produced multiple cells, because flattening per-cell
swaths before ordering collided their per-cell ids and interleaved
cells. They now order each cell independently and stitch the results
with the same nearest-neighbour, border-graph-bridging layer TSP
already used (extracted into stitchCellRoutes). CUSTOM stays rejected
for multi-cell: its order vector can't be split across cells.

Known issue: manual testing shows this can still produce swath
overlap in some multi-cell fields, likely on the F2C side. Parking
this branch as-is rather than chasing it now.

* Join swaths through the cell border graph in swath-order routes

Multi-cell BOUSTROPHEDON, SNAKE, and SPIRAL wrapped each cell's swaths in a
single connection-less group, so every transition inside a cell became a
naked Dubins turn with no knowledge of the boundary. A SNAKE or SPIRAL skip
spans several swath widths, and that turn cut straight across ground the
route had already covered.

Each cell now routes through F2C's shortest-path graph over the cell
border, the machinery TSP's per-cell genRoute already used, so a cell route
carries a connection between every consecutive swath pair. A pair whose
endpoint is not a graph node falls back on its own.

* Judge connection detours by deviation instead of length ratio

A connection was replaced by a single turn when its polyline ran under 1.3x
the straight distance. That ratio cannot separate a u-turn from a detour:
rounding a long cell's corner is only ~20% longer than cutting its
diagonal, so real border-following connections were collapsing into
straight lines through the field. One measured 36.3 m of polyline against
30.7 m direct, a ratio of 1.18, and became a 30 m diagonal.

Compare the waypoints' peak deviation from the straight hop instead.
Headland u-turn waypoints are collinear with it, so they still get a curve,
while anything the graph routed around keeps its polyline.

* Use the paired-cell bridge graph only when both cells resolve

getCellWherePoint can miss an endpoint that sits on a cell border, leaving
one cell in the pair. The graph was still built from that single cell, and
it reached the far endpoint by jumping off that cell's border, cutting
across whatever lay between. Because the result had two or more points it
counted as a success, so the whole-set fallback never ran.

Require both cells before trusting the pair graph; otherwise go straight to
the graph over every travel cell, which is connected along their shared
borders and routes around the gap.

(cherry picked from commit 29c96cf)

* Add a useful error if the headland is too large (#150)

Signed-off-by: Ramon Wijnands <[email protected]>
(cherry picked from commit 04858cf)

* Make visualizers transient_local (#155)

Signed-off-by: Alireza Moayyedi <[email protected]>
(cherry picked from commit aa04819)

* Fix dependencies missing from package.xml (#153)

(cherry picked from commit 2fb8254)

---------

Signed-off-by: Ramon Wijnands <[email protected]>
Signed-off-by: Alireza Moayyedi <[email protected]>
Co-authored-by: Ramon Wijnands <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Umut Can Cebbur <[email protected]>
Co-authored-by: Alireza Moayyedi <[email protected]>
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 multi-cell-swath-order-routing 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