Skip to content

simplifyConnection discards the connection polyline based on endpoint distance alone #231

Open

Description

@u33549

Summary

PathPlanning::simplifyConnection decides whether to follow a connection's waypoints or cut straight across them using the straight-line distance between the connection's endpoints, without ever measuring how far the waypoints in between actually depart from that line. When a connection detours around real geometry but happens to start and end close together, the waypoints are discarded and the path is planned straight through the obstacle the connection existed to avoid.

Reported against v2.0.0, the released version we depend on. I checked main and the v3.0 branch as well — the condition is byte-identical in all three, so this is not something an upgrade resolves.

Where

src/fields2cover/path_planning/path_planning.cpp:

std::vector<std::pair<F2CPoint, double>> PathPlanning::simplifyConnection(
    const F2CRobot& robot,
    const F2CPoint& p1, double ang1,
    const F2CMultiPoint& mp,
    const F2CPoint& p2, double ang2) {
  const double safe_dist = getSmoothTurningRadius(robot);
  std::vector<std::pair<F2CPoint, double>> path;
  path.emplace_back(p1, ang1);

  if (p1.distance(p2) < 6.0 * safe_dist || mp.size() < 2) {
    path.emplace_back(p2, ang2);   // <-- mp is discarded entirely
    return path;
  }
  ...

p1.distance(p2) is the distance from the end of one swath to the start of the next. mp is the connection the route planner produced to get between them. The test relates the two endpoints to each other, but nothing in it looks at mp.

Why this is a problem

The two quantities are independent. A connection routed around a concave notch, or between two cells of a decomposed field, regularly has endpoints a few meters apart while the waypoints between them run for tens of meters around the boundary. Whenever that separation falls under 6 * safe_dist, mp is dropped and createTurn is asked for a direct maneuver between the two poses — straight across the ground the route deliberately went around.

A test on the deviation of mp from the segment p1–p2 would separate the two cases. The endpoint distance cannot, because a long detour and a short hop are indistinguishable by that measure.

Second issue in the same function

The corner test does not account for angle wrapping:

double ang_in  = (mp[i] - mp[i-1]).getAngleFromPoint();
double ang_out = (mp[i+1] - mp[i]).getAngleFromPoint();
if (fabs(ang_in - ang_out) > 0.1) {
  vp.emplace_back(mp[i]);
}

getAngleFromPoint() returns mod_2pi(...), so it lands in [0, 2π). On a straight run heading near 0, consecutive segments can read as 0.001 and 6.282, giving fabs(...) = 6.281 and registering a corner where the polyline is straight.

Geometry::getAngleDiffAbs(a, b) already exists in the library and computes exactly this difference correctly. This one also reads the same on v2.0.0, main, and v3.0.

Versions checked

endpoint-distance test angle comparison
v2.0.0 (released) present present
main @ 0ce7fcc present present
v3.0 @ 884d895 present present

Context

Found while using F2C from opennav_coverage, where coverage of concave and decomposed fields produces exactly this connection shape. We are pinned to v2.0.0.

We already handle this downstream, in open-navigation/opennav_coverage#149: we follow the connection's polyline and decide the straight-hop case on how far mp deviates from the segment p1–p2, rather than on the distance between the endpoints. It's been exercised on concave and decomposed fields across a range of implement widths and turning radii.

If you'd like to look over what we did there and it seems like the right shape for F2C, I'd be glad to port it up against the v2 line.

Activity

  1. SteveMacenski commented on Aug 6, 2026

    @SteveMacenski
    Contributor

    BTW @Gonzalo-Mier this came out of forward porting the Nav2 integration to V2

  2. Gonzalo-Mier commented on Aug 10, 2026

    @Gonzalo-Mier
    Member

    Hi @SteveMacenski, I'm in contact with @u33549 to achieve the integration of F2C v2 into Nav2

  3. u33549 commented on Aug 11, 2026

    @u33549
    ContributorAuthor

    @Gonzalo-Mier i have a series of fixes to bring up from opennav_coverage, where we have been working around F2C gaps downstream. This issue is the first; there are around ten, most small and self-contained. Several add API that is simply missing rather than only fixing behaviour — additive, nothing removed — so the shape is a minor release, not a patch.

    Could you open a v2.1.0-devel branch off v2.1.0?

  4. u33549 commented on Aug 11, 2026

    @u33549
    ContributorAuthor

    For visibility, the full list. Each links to where we did it downstream.

    Path planning

    • Connections are not followed — the polyline is discarded. This issue. #137, #145, #149
    • getSmoothTurningRadius is private, so we re-derived it. #149
    • TurningBase does not expose whether a curve is continuous-curvature. #149
    • The headland ring comes back as geometry, not as a drivable path. #141

    Types

    • Route has no reverse(), though Swath and Swaths do. #137
    • HL_SWATH has no producer and no consumer; discretizeSwath skips it. #113, #141
    • No point-along / polyline-simplify / deviation-from-track helpers. #145, #149

    Route planning

    • SingleCellSwathsOrderBase returns ordered swaths but no connections. #145
    • genSortedSwaths sorts by swath id, so flattened multi-cell input interleaves the cells. #145
    • createShortestGraph returns a plausible but invalid path when only one cell is in the graph. #137
    • shortestPath throws when an endpoint is not a node. #145
    • genRoute builds an all-pairs matrix and runs out of memory on multi-cell fields. #117
    • CustomOrder fails late and unhelpfully on decomposed fields. #145
    • The two route planners share no base class and no return type. #117
    • setStartAndEndPoint has no meaning in a per-cell solve. #120, #137
    • Nothing stitches per-cell routes together. #137, #145

    Headland / decomposition

    • ConstHL::generateHeadlands treats F2CCells as one piece, so decomposed cells get no corridor between them. #135
    • Multi-cell headland: a collapsed sub-cell throws, a split sub-cell loses pieces. #119
    • Decomposition computes its split lines, then drops the adjacency they imply.

    Coordinates

    • No API to re-add the reference point, or to transform a single point. #36, #120

    Not all of these are equally shaped for upstream — a few are workarounds where the
    right fix is elsewhere in F2C, and I would rather fix the cause than port the
    workaround.

  5. u33549 commented on Nov 21, 2026

    @u33549
    ContributorAuthor

    Hi @Gonzalo-Mier, with #255 and #259 merged, the list above is done. Where each item ended up:

    Merged

    Not needed in the library

    • The geometry helpers and re-adding the reference point were already there; we had written our own without knowing.
    • genRoute running out of memory was already fixed by Improvement: reduce memory usage #219; splitting per cell did not give better routes.
    • The multi-cell headland item turned out to be dead code on our side.
    • The headland ring as a drivable path: we are dropping that feature downstream instead of porting it.

    Along the way: #247, #249, #250, #252, #253.

    Everything from #250 on is only in develop so far. The Nav2 side (opennav_coverage) pins a release tag, so it can only drop its workarounds for #251, #254, #255 and #259 once they ship.

    Could you cut a new version from develop when you have a moment?

    Edit: I've changed my mind. For now, V2.1.1 is a good start, but it could be much better once the route-fix changes are merged into the next version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions