Skip to content

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

Merged
SteveMacenski merged 4 commits into
open-navigation:mainfrom
u33549:Feature/umutc/f2c-enhancements-main/headland-driving
Jul 28, 2026
Merged

SteveMacenski merged 4 commits into
open-navigation:mainfrom
u33549:Feature/umutc/f2c-enhancements-main/headland-driving

Conversation

@u33549

@u33549 u33549 commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds an optional "drive the headland" mode: normally the headland is just a
margin the swaths leave alone, but some operations need to cover that ring area
too. When enabled, a headland pass is generated and spliced onto the coverage
path. Off by default — no behavior change unless the new goal fields are set.

New goal fields (ComputeCoveragePath)

Field Default Meaning
generate_headland_swaths False Also cover the headland ring area
headland_first False Drive the headland before (True) or after (False) the inner coverage
headland_full_coverage False False = one perimeter pass; True = concentric passes sweeping the whole band

Needs generate_route and generate_path (the pass is spliced onto the planned
path); otherwise it is skipped with a warning.

How it works

  • Single pass (headland_full_coverage = False): one loop along the
    headland's inner boundary (toHeadlandPerimeterPath over field_no_headland).
  • Full band (headland_full_coverage = True): generateHeadlandSwaths
    produces concentric rings spaced by the operation width
    (count = round(headland_width / operation_width), min 1), each emitted as a
    perimeter pass from outer to inner.
  • Each pass starts at the boundary point nearest the route to minimize the
    connecting jump, and is emitted as HL_SWATH path states. discretizeSwathLike
    now densifies HL_SWATH too (F2C's discretizeSwath only split SWATH), so
    the headland pass is a dense, followable path with per-pose velocity/direction.
  • The pass is prepended or appended to the coverage path per headland_first.

Visualization

The headland pass is published as a dedicated coverage_server/headland_swaths
marker (distinct color) so it isn't confused with the identically-shaped
planning-field boundary.

Copilot AI review requested due to automatic review settings July 27, 2026 21:13

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 27, 2026

Copy link
Copy Markdown
Contributor Author

Visual comparison of the headland driving modes on an 18×18 m field with a 4 m headland:

Off (baseline) — generate_headland_swaths: false
The headland stays an uncovered margin; only the inner area is swathed.
image

Single perimeter pass — headland_full_coverage: false
One loop is driven along the headland's inner boundary (red headland_swaths marker), spliced onto the coverage path.
image

Full band coverage — headland_full_coverage: true
Concentric passes spaced by the operation width sweep the entire headland band (count = round(headland_width / operation_width)), from outer to inner.
image

The pass is emitted as dense HL_SWATH states, so it's a followable path with per-pose velocity/direction.

As I mentioned in a previous pr, paths can sometimes overlap in the navigation path; I’ve encountered this issue a few times, but I’m not sure if it’s our fault or F2C’s. In any case, v1 is still usable and offers a useful feature. Once everything is done, I’ll work on this issue separately.

@SteveMacenski

Copy link
Copy Markdown
Member

How many more PRs do you have lined up?

@u33549

u33549 commented Jul 27, 2026

Copy link
Copy Markdown
Contributor Author

I think this is the final feature integration. After that, one for overlap fix and maybe one for readme and tutorial. Also for other distoros. I wondered why you asked?

@SteveMacenski SteveMacenski left a comment

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.

You have added alot in these PRs; I think some documentation explaining these new options and example uses of the feature to visualize the outcomes would be necessary (as well as a simple "here's how you do the basic from v1" workflow)

@SteveMacenski
SteveMacenski merged commit 67f2c0f into open-navigation:main Jul 28, 2026
7 checks passed
@u33549

u33549 commented Jul 28, 2026

Copy link
Copy Markdown
Contributor Author

Don't worry, I will. I just want to finish the features and optimizations. I worked really these improvements and I'm sure there may be bugs in it that I missed. I will also deal with future issues related to these parts in the future.

@u33549

u33549 commented Jul 28, 2026

Copy link
Copy Markdown
Contributor Author

I believe that the documentation process will help me identify some issues.

@u33549

u33549 commented Jul 28, 2026

Copy link
Copy Markdown
Contributor Author

I'll check to see if there's anything else on my checklist that needs to be done. If you want, I can start documenting instead of solving the overlap problem later.

@u33549

u33549 commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor Author

Remaining work I have planned:

  • Path overlap fix — on some fields the generated nav_path doubles back over ground it
    has already covered. I haven't isolated yet whether it comes from our stitching layer or from
    F2C's path planner.

    • Build a minimal, deterministic reproduction
    • Identify the origin, then fix on our side or report
  • Expose route connections in the coverage message — F2CRoute carries connections
    (getConnections()) next to the swath groups, but they never reach the action result:
    toCoveragePathMsg(F2CRoute, ...) only flattens getVectorSwaths(), and PathComponents has
    no field for them. With generate_path=true they aren't lost, but they are indistinguishable —
    emitted as HL_SWATH states and folded into msg.swaths, so a consumer can't tell an
    inter-cell bridge from a real swath, which matters for anything computing covered area. The BT
    node's coverage_path port already advertises its output as "swaths and route connections",
    so this closes that gap too.

    • Add nav_msgs/Path[] connections to PathComponents (additive, backward compatible)
    • Populate it from getConnections() in the route overload
    • Publish connections as their own RViz marker, separate from swaths
  • Decomposition extras (on request — not scheduled, I don't think these are important
    unless someone asks)

    • Render decomposed sub-cells as their own RViz marker
    • Expose F2C's DecompObjective (currently default-constructed) through DecompMode
  • Micro-swath fragments (may share a root cause with the overlap issue above — I'll look
    at both together)
    — very short leftover swaths at corridor and notch ends produce a
    "turn → fragment → turn" artifact. A min_swath_length filter would remove them, but I rejected
    it because it can leave a ~0.35 m strip uncovered, and coverage guarantee comes first.

  • Documentation — the new options with example uses and visualized outcomes, plus a short
    "here's the basic v1 workflow" walkthrough.

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 27, 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 humble: humble-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 humble: 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 humble.

(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 humble: 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 humble.

(cherry picked from commit e7eb93b, part of #162)
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/headland-driving 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