Fix closed-loop Frenet wrap snap to s≈0 on last lap meters - #24
Draft
cursor[bot] wants to merge 1 commit into
Draft
Fix closed-loop Frenet wrap snap to s≈0 on last lap meters#24cursor[bot] wants to merge 1 commit into
cursor[bot] wants to merge 1 commit into
Conversation
On first==last race lines the KD-tree ties the finish to index 0, so XY→SD only scored the outgoing start segment and reported s≈0 with a huge false CTE on the last lap meters. Score the wrap segment (n-2,n-1) when closest_wp==0. Co-authored-by: Majid Khonji <majid-khonji@users.noreply.github.com>
This was referenced Aug 2, 2026
Draft
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug and impact
On closed race lines with duplicated endpoints (
first==last, e.g. bundled Yas Marina), ego on the last segment got Frenets≈0(or slightly negative) instead ofs≈track_end. Lattice sampling / lap detection then acted as if the car were at the start/finish while it was still meters before the line — wrong local plans and premature lap counts every lap.Trigger: Load a closed race line → drive (or place ego) onto the final polyline segment before S/F. Reproduced on Yas Marina: true
s≈5250.7reported ass≈-0.3.Root cause
PR #21 fixed
path_sinit and open-path corner segment scoring, but XY→SD still only scored segments adjacent to the KD nearest waypoint. At the finish,first==lastmakes the tree return index0, so only segment(0,1)was considered — never the wrap segment(n-2, n-1).Fix
__closed_duplicated_endpointsat init._frenet_segment_candidatesalso scores(n-2, n-1)whenclosest_wp==0on those paths.Validation
7 passed (includes new square + Yas Marina wrap-segment regressions).
Broader
test/c50_common+ lattice/velocity/PP: 127 passed (2 failures are envtkintermissing, unrelated).Memory cleanup