Skip to content

Small API additions: Route::reverse, TurningBase::hasContinuousCurvature, public getSmoothTurningRadius - #233

Merged
Gonzalo-Mier merged 4 commits into
Fields2Cover:mainfrom
u33549:dev/umutc/v2.1.0-devel/api-gaps
Aug 18, 2026
Merged

Gonzalo-Mier merged 4 commits into
Fields2Cover:mainfrom
u33549:dev/umutc/v2.1.0-devel/api-gaps

Conversation

@u33549

@u33549 u33549 commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Motivation

Three pieces of information the library already has internally but does not offer to
callers: the radius a continuous-curvature turn sweeps, whether a turn planner keeps the
curvature continuous, and reversing a route.

Each one currently forces the caller into something worse — duplicating a formula it
cannot compute exactly, branching on concrete planner types, or rebuilding a Route by
hand. All three are additive, none changes behavior, and each is one commit.

They are prerequisites for the planPathForConnection fix (#231), but they are gaps in
their own right, and sending them first keeps that fix reviewable as a single concern.

1. Make PathPlanning::getSmoothTurningRadius public

Moved the declaration from the private block to the public one. Body untouched.

The value cannot be computed outside the library: the function calls end_of_clothoid
from steering_functions/utilities/utilities.hpp, and those headers are not part of the
install (only fields2cover and matplot land in the install prefix). We currently
approximate it downstream with a different formula, which drifts from what F2C itself
plans.

2. Add TurningBase::hasContinuousCurvature()

Added virtual bool hasContinuousCurvature() const returning false, overridden to
true in DubinsCurvesCC and ReedsSheppCurvesHC.

Choosing the radius to round a corner with depends on whether the turn planner ramps the
curvature or steps it. A caller holding a TurningBase& has no way to ask, so it would
have to branch on the concrete type and silently pick wrong for any planner added later.

Querying the robot instead is not equivalent: tutorials/6_path_planning.cpp drives
plain DubinsCurves with a robot that has MaxDiffCurv set. Continuity is a property of
the planner, not of the robot.

Left non-pure so that TurningBase subclasses outside this repo keep compiling.

3. Add Route::reverse()

Reverses the group order, each Swaths, each Swath, and the point order of each
connection.

Swath::reverse() and Swaths::reverse() already exist — Route was the missing one,
so anything that needs a route driven backwards has to rebuild it by hand.

One detail worth a look during review: connections are stored before the swaths they
lead into and the trailing one is optional, so connections_.size() is either
v_swaths_.size() or one more. Reversing both vectors on their own shifts the
connections by one whenever there is no trailing connection. The implementation appends
an empty connection first when needed and drops a trailing empty one afterwards, so
reversing twice returns the exact original, connection count included.

Two smaller things: Swaths::reverse() only reverses the swath order and not the driving
direction of each swath, so Swath::reverse() is called per swath as well; and
MultiPoint has no reversePoints() (unlike LineString/LinearRing), so connections
are rebuilt.

Note

Adding a virtual method changes the vtable layout, so this is an ABI break.

Copilot AI lite review requested due to automatic review settings August 14, 2026 10:41

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 Aug 17, 2026

Copy link
Copy Markdown
Contributor Author

@Gonzalo-Mier Is there anything need to change here

@Gonzalo-Mier
Gonzalo-Mier merged commit aa4fc2d into Fields2Cover:main Aug 18, 2026
60 checks passed
@Gonzalo-Mier

Copy link
Copy Markdown
Member

Hi @u33549, Thank you for the PR! Seems great

@u33549
u33549 deleted the dev/umutc/v2.1.0-devel/api-gaps branch August 18, 2026 08:14
Gonzalo-Mier pushed a commit that referenced this pull request Aug 22, 2026
* Discretize HL_SWATH sections in Path::discretizeSwath

discretizeSwath() only densified SWATH states; HL_SWATH stayed a
single waypoint, so headland/corridor legs stored with that type
couldn't be subdivided. Neither type has ever been produced by F2C
itself (HL_SWATH has been dead since the v2.0.0 initial commit), so
no existing call path changes behavior.

* Add appendSwath overload to set PathSectionType

The only public way to produce an HL_SWATH state was building a
PathState by hand and calling addState. appendSwath always hardcoded
SWATH. New overload takes the type explicitly; the 2-argument version
now delegates to it with SWATH, so the existing signature and ABI are
unchanged.

* Follow and smooth connection polylines instead of a raw corner turn

planPathForConnection routed every consecutive waypoint pair through
the turn planner, including straight legs, and simplifyConnection's
angle-wrap bug (fabs on a raw angle difference) mis-simplified
sharply-turning tracks. Replace both with a corner-by-corner planner:
straight runs become HL_SWATH legs, only genuine corners go through
createTurn, and corners too tight or too close together are folded or
left sharp rather than plotting a shortcut across ground the route
routed around.

Four details the geometry needs:

- The approach to a corner is sized from the radius the turn actually
  sweeps, which is the wider of two effects: the clothoid ramps spend
  part of the deflection (getSmoothTurningRadius, public since #233),
  and a shallow corner never reaches full curvature at all, peaking at
  sqrt(rate * sweep). Take only the first and a shallow corner is
  planned from a radius it never drives, which starts the turn a metre
  early and cuts ground the legs either side of it are covering.
- A candidate turn is judged by how far it turns, not how long it is.
  A loop costs an extra 2*pi*R, which at a small turning radius is a
  couple of metres and hides inside any length budget, but it cannot
  hide in the turning itself.
- cut_tol is floored in turning radii and capped at the operation
  width, so a compact implement still gets room for a fillet while a
  wide-turning one keeps the corners it should leave square.
- The tangent margin is room for a clothoid lead-in, so it applies
  only to a continuous-curvature turn; a discontinuous one needs the
  plain tangent length and cutting more would only cut corner.

At a pinned route end taking a single corner there is no outgoing leg
-- the reference point is the corner itself -- so the lateral-offset
bound collapses to zero and would refuse a corner the tangent bound
allows. Skip it there.

Enables the fields2cover_pp_pp.planPathForConnection test, dead since
v2.0.0's first commit.

* Add connection corner regression tests

Nine tests over the corner-rounding path, which had no coverage before:
detour corners, tight jogs folded into one S, neighbour u-turns, curved
tracks that must not be flattened, corners left sharp because no turn
fits, corners taken from the swath's heading rather than the track's,
open-ended route connections, shallow-corner approach floors, and
corners too close to round one at a time.

Each bound here was checked by reverting the code it covers and
confirming the test goes red, so none of them is decorative. Two are
worth naming: the shallow-corner test bounds the approach on both
sides, because starting a turn too early cuts ground the covering legs
either side of it need; and maxTurnSweep is what catches a turn planner
answering with a loop, which is smooth, barely longer, and invisible to
every other measure here.

distanceToPath measures to the polyline through the states, not to the
states themselves: a straight run is one state, so measuring to states
alone would miss the track between them.

* Add the geometry helpers the corner planner needs to their own types

Following a connection's track needs a handful of plain geometry that has
nothing to do with path planning: a point a given way along a ray, the
points of a geometry as a vector, appending a straight leg to a path, and
how far a path strays from a line.

Point::getPointAlong, MultiPoint::toVectorPoint, LineString::toVectorPoint,
Path::appendStraight and Path::maxDistanceTo. appendStraight takes a speed
rather than a Robot, matching appendSwath -- Robot.h already includes
Path.h, so the dependency cannot run the other way.

* Move turn geometry and its tuning onto Robot

getSmoothTurningRadius computes a property of the robot, and the corner
planner needs two more of the same kind: the radius a turn of a given
deflection is driven at, and the tolerances and thresholds that decide
whether a corner is rounded at all.

Robot::getSmoothTurningRadius and Robot::getTurnRadius, plus settable
parameters for the corner planner. The four that scale with the machine
are stored in real units and derived from the robot when unset -- an
operator sets "at most 1.25 m of corner may be cut", not a fraction --
following the turn_vel_ precedent already in the class.

* Use the type-level helpers in the connection planner

The anonymous namespace was carrying general-purpose geometry and a block
of tuning constants that callers had no way to reach. Both now live on the
types they describe, so this file keeps only the cornering logic.

getSmoothTurningRadius stays on PathPlanning as a forwarder: it was made
public one release ago, and moving it outright would break callers.

* Split appendRoundedTrack into its named steps

At 185 lines the reasoning was hard to follow. Same logic, in the four
steps it was already doing: the deflection at each corner, the fold of
corners too close to take one at a time, the room a span leaves for a
maneuver, and the search for a turn that fits it.

No behaviour change.

* Drop the addStraight wrapper, call Path::appendStraight directly

The wrapper still took F2CPath& and mutated it, the exact pattern the
review asked to move off of -- moving the logic onto Path only helped
if callers actually called the member function.

* Fix the reason a wide-radius corner stays sharp in the test comment

* Move doc comments off the public getters onto their members
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