Skip to content

feat: add distance-based sampling to PathPlannerTrajectory#1169

Open
JosephTLockwood wants to merge 1 commit into
mjansen4857:mainfrom
JosephTLockwood:feat/sample-by-distance
Open

feat: add distance-based sampling to PathPlannerTrajectory#1169
JosephTLockwood wants to merge 1 commit into
mjansen4857:mainfrom
JosephTLockwood:feat/sample-by-distance

Conversation

@JosephTLockwood

Copy link
Copy Markdown
Contributor

Summary

Adds a way to query PathPlannerTrajectory by arc length instead of elapsed time. Purely additive -- no existing behavior changes.

  • PathPlannerTrajectoryState.distanceAlongPath -- cumulative arc length from trajectory start. Populated in both constructors; preserved through interpolate, flip, reverse, copyWithTime.
  • PathPlannerTrajectory.sampleByDistance(double) -- binary search on distanceAlongPath, then lerp via existing interpolate. Mirrors sample(double time)'s structure.
  • PathPlannerTrajectory.getTotalArcLength() -- chord-summed total.

Why

Projection-based path followers track progress from odometry rather than a timer. This lets the follower query "where should I be at arc length s?" without converting s->t. Useful when the robot is held up (obstacle, disturbance) and a time-based reference would race ahead, or when cross-track error is measured perpendicular to tangent at the robot's actual progress.

Test plan

  • 11 new unit tests in PathPlannerTrajectoryTest.java (population, monotonicity, clamping, interpolation, agreement with sample(time) on straight + arc, preservation through flip/copy)
  • Existing test suite passes
  • spotlessJavaCheck clean

Adds:
- PathPlannerTrajectoryState.distanceAlongPath: cumulative arc length
  from the trajectory start, populated automatically in both
  constructors and preserved through interpolate/flip/reverse/copy.
- PathPlannerTrajectory.sampleByDistance(double): query the trajectory
  by arc length instead of elapsed time. Useful for projection-based
  path following where progress is tracked from odometry rather than
  a timer.
- PathPlannerTrajectory.getTotalArcLength(): total chord-summed length.

Purely additive -- no existing behavior changes. 11 new unit tests
cover population, monotonicity, clamping, interpolation, agreement
with sample(time), and preservation through flip/copy.
@github-actions github-actions Bot added the PathPlannerLib Changes to PathPlannerLib label May 17, 2026
@codecov

codecov Bot commented May 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.58%. Comparing base (e02bbf3) to head (1be2701).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1169      +/-   ##
==========================================
- Coverage   84.59%   84.58%   -0.02%     
==========================================
  Files          95       95              
  Lines        9750     9750              
==========================================
- Hits         8248     8247       -1     
- Misses       1502     1503       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Labels

PathPlannerLib Changes to PathPlannerLib

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant