Skip to content

Fix closed-loop path_s corruption and Frenet corner false CTE - #21

Merged
majid-khonji merged 3 commits into
devfrom
cursor/critical-bug-inspection-197b
Jul 31, 2026
Merged

Fix closed-loop path_s corruption and Frenet corner false CTE#21
majid-khonji merged 3 commits into
devfrom
cursor/critical-bug-inspection-197b

Conversation

@cursor

@cursor cursor Bot commented Jul 31, 2026

Copy link
Copy Markdown

Bug and impact

  1. Closed race tracks corrupt path_s — When first==last (bundled Yas Marina race line, closed RaceMap centerlines), KD-tree Frenet re-projection of the reference snapped the final waypoint to index 0, yielding non-monotonic path_s with path_s[-1] == 0 (lattice already worked around this via path_s[-2]).
  2. Pure Pursuit aimed at start/finish for the whole lapfind_path_lookahead clamped with min(s+Ld, path_s[-1]). With path_s[-1]==0, every mid-lap lookahead jumped ~1.2 km to the origin on Yas Marina.
  3. False CTE after corners — XY→SD always projected onto the segment ending at the nearest waypoint, so an on-path point after a 90° turn could report d≈segment_length instead of d≈0, yanking Stanley/PID/PP.

Root cause

  • Reference path_s was computed by re-projecting waypoints through convert_xy_path_to_sd_path instead of using cumulative arc-length.
  • Frenet segment selection ignored the outgoing segment around the nearest vertex; SD→XY used nearest-waypoint rather than arc-length bracketing.

Fix

  • Initialize path_s / path_d from __cumulative_distances.
  • XY→SD scores both adjacent segments (clamped distance); SD→XY brackets by searchsorted on arc-length; 1-point paths handled safely.
  • Pure Pursuit clamps with max(path_s).

Validation

PYTHONPATH=/workspace python3 -m pytest \
  test/c50_common/test_c54_closed_loop_path_s.py \
  test/c30_control/test_c35_pure_pursuit.py \
  test/c50_common/test_c54_trajectory_horizon_slice.py \
  test/c50_common/test_c54_trajectory_waypoint_update.py \
  test/c50_common/test_c54_trajectory_tracker_concatenate.py \
  test/c30_control/test_c33_pid.py -v

42 passed.

Not re-reporting already-tracked PR #18 (1-point Frenet / Control Step) or merged PR #16.

Open in Web View Automation 

cursoragent and others added 2 commits July 31, 2026 11:08
Initialize TrajectoryTracker path_s from cumulative arc-length so closed
tracks with first==last (Yas Marina race line) stay monotonic. Score both
adjacent segments for XY→SD and bracket SD→XY by arc-length so on-path
points after corners no longer pick up false CTE. Pure Pursuit clamps
lookahead with max(path_s).

Co-authored-by: Majid Khonji <majid-khonji@users.noreply.github.com>
After path_s became cumulative arc-length, the old path_s[-2]
workaround truncated the final closed-track segment, treated
2-point tracks as ended at s=0, and IndexError'd on 1-point paths.
Use TrajectoryTracker.track_end_s (path_s[-1]) instead.

Co-authored-by: Majid Khonji <majid-khonji@users.noreply.github.com>
@majid-khonji
majid-khonji marked this pull request as ready for review July 31, 2026 17:09
@cursor

cursor Bot commented Jul 31, 2026

Copy link
Copy Markdown
Author

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

Keep closed-loop path_s / adjacent-segment Frenet fixes from this PR and
PR #18's 1-point convert_sd_to_xy lateral-offset handling; retain both
CHANGELOG Fixed entries.

Co-authored-by: Majid Khonji <majid-khonji@users.noreply.github.com>
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.

2 participants