Repository navigation
Support non-TSP route modes with field decomposition - #145
Conversation
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.
There was a problem hiding this comment.
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
SwathOrderMethodto 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.
Known limitation: unsmoothed corners on border-following connectionsWorth flagging since this PR makes it visible. When a connection follows the PathState s;
s.point = pts[i];
s.angle = std::atan2(dy, dx); // raw segment heading
s.type = f2c::types::PathSectionType::HL_SWATH;
The rounded loops in these crops are This is pre-existing behaviour from #137, not new here — but the old 1.3x length The corners are not followable at I'm not sure this is worth fixing, or whether it causes a real problem in |
|
Although this deviates from the plan in PR #141, it is one of the steps in resolving the overlap issue. |
|
What's the fix to have the smoothing applied in that edge case? |
|
I'll apply a minimum turn angle to these corners, or I'll create them as |
|
I just want to get some feedback. What do you think about how we are going? |
|
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 :-) |
|
Thank you I'm trying to do my best. |
|
Those seem good to me |
* 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]>
* 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]>
* 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]>












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_typeis BOUSTROPHEDON, enablinggenerate_decompwith stock parameters threwINVALID_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 vectorindexes 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.
getCellWherePointcan miss anendpoint 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.