Skip to content

Fix swath end points in coverage path message when generate_path is true - #161

Closed
ohauterville wants to merge 4 commits into
open-navigation:jazzy-v2from
ohauterville:fix/swath_end
Closed

ohauterville wants to merge 4 commits into
open-navigation:jazzy-v2from
ohauterville:fix/swath_end

Conversation

@ohauterville

Copy link
Copy Markdown

Summary

toCoveragePathMsg(const Path &, ...) fills swaths[i].end with the start point of
the last swath state, so every swath in the message has start == end when
generate_path is true.

Cause

A raw Fields2Cover path stores one state per swath (start point, heading, length).
path[i - 1].point / path.back().point is therefore the swath START. The end must
be point + len * (cos(angle), sin(angle)).

Fix

Compute the end point from the state's point, angle and length (cartesian case).

Test

Added TesttoCoveragePathMsgSwathEndPoints. It fails before the fix and passes after.

Reproduction (before the fix)

ros2 action send_goal on compute_coverage_path with the same field:

  • generate_route: true, generate_path: false -> swaths have distinct start/end.
  • generate_route: true, generate_path: true -> end == start for every swath.

Limitation

The formula is valid in cartesian coordinates. For GPS input the path is converted
back to the previous CRS before the loop, so lengths (meters) and points (degrees)
cannot be mixed. Suggestions welcome for the GPS case.

A raw F2C path stores one state per swath (point, heading, length), so the end point was taken from the state's point and start == end when generate_path is true.

Signed-off-by: ohauterville <[email protected]>

@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.

Replace revert the reformatting. I can hardly tell what you changed to give this a review 😉

Signed-off-by: ohauterville <[email protected]>
Signed-off-by: ohauterville <[email protected]>
@ohauterville

Copy link
Copy Markdown
Author

Yes ! My bad, now it should be ok !

@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.

Via Claude:

It re-implements PathState::atEnd() and drops dir. F2C v2’s version is point.getPointFromAngle(angle, len * static_cast(dir)). Today this doesn’t cause wrong output, because appendSwath and PathGenerator::appendConnection only emit FORWARD swath-like states. Switching to s.atEnd() is still cleaner. One catch: F2C’s transformPathWithFieldRef recomputes angle as “towards the next point” but keeps dir. So a BACKWARD state in the GPS branch would land on the wrong side with atEnd(), while the PR’s version would happen to be right. Either choice is fine for now; just leave a comment about the BACKWARD case.

@ohauterville

Copy link
Copy Markdown
Author

@SteveMacenski It now passes all the tests. Are you okay with the changes ?

@SteveMacenski

SteveMacenski commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Can you respond to this last point above?

Otherwise, it does look good to me but also needs to be in main so that new distributions also have this not only Jazzy. Can you open the backport (or actually forward-port hah!) PR?

Signed-off-by: ohauterville <[email protected]>
@ohauterville

Copy link
Copy Markdown
Author

Claude was right, the atEnd function does the same job, so now it works and it is simpler this way

@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.

Can you put on ros2 as well (and lyrical) so that current distros also have this fix if/when you upgrade?

@u33549

u33549 commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Hi, apologies, I hadn't seen this PR. While preparing #162 I ran into the same swath end point issue and fixed it on main with atEnd() as well. I'm currently backporting the main changes to the other distros, so the jazzy backport would carry the same fix. Sorry for the overlap, and thanks for catching it!

@SteveMacenski

SteveMacenski commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

So should this be closed in lieu of your backports?

PS Can you open for lyrical too?

@u33549

u33549 commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

It can be closed, though the fix isn't in a backport yet: I'd carry it in the next jazzy one (the Fields2Cover v2.1.1 backport). Or you can simply merge this, and I'll skip that part in my backport, so ohauterville's work lands as well.

And yes, I'm preparing the same backport for lyrical too.

@ohauterville

Copy link
Copy Markdown
Author

Can we merge this one and keep your backports @u33549 on the other branches?

@u33549

u33549 commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Yes, we can. I was going to include this fix in the next backport pr as well, so it's not currently in the repository. It is mergeable.

@u33549

u33549 commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

I've backported Humble and Lyrical; I'm waiting for a decision on jazzy.

@SteveMacenski

Copy link
Copy Markdown
Member

I believe #165 has already been merged. I would like to have the branches consistent, so if we have fixes already that have landed in all the other branches, then using the same in Jazzy for consistency I think is wise, unfortunately :(

@u33549

u33549 commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Thanks again for finding this and for iterating on it. To keep jazzy consistent with the other branches, the same swath end point fix lands on jazzy with #174, the jazzy counterpart of the humble Fields2Cover v2.1.1 backports (#166, #173). Once #174 is merged, this PR can be closed. I appreciate your work on it, and sorry again that it ended up overlapping.

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