-
Notifications
You must be signed in to change notification settings - Fork 3
refactor: increment multiple keypoints if needed #667
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
4471281
7ce6e96
b669966
2e09b52
e4c8b78
bd3be2b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,7 +26,9 @@ public class SimpleTimeInterpolator { | |
| double previousTimestamp; | ||
| ProvidesInterpolationData baseline; | ||
| int index; | ||
| double maximumDistanceFromChasePointInMeters = 0.3; | ||
| // We don't care if the chase point is too far away from us, it causes problems when it freezes. | ||
| // A non-optimal but working solution is changing it from 0.3 to 3 for more tolerance. | ||
| double maximumDistanceFromChasePointInMeters = 3; | ||
|
|
||
| SwerveKinematicsCalculator calculator; | ||
|
|
||
|
|
@@ -37,7 +39,7 @@ public class SimpleTimeInterpolator { | |
| RobotAssertionManager assertionManager; | ||
| private boolean usingKinematics; | ||
|
|
||
| public class InterpolationResult { | ||
| public static class InterpolationResult { | ||
| public Translation2d chasePoint; | ||
| public boolean isOnFinalPoint; | ||
|
|
||
|
|
@@ -127,7 +129,7 @@ public InterpolationResult calculateTarget(Translation2d currentLocation) { | |
| accumulatedProductiveSeconds += secondsSinceLastExecute; | ||
|
|
||
| // If we somehow have no points to visit, don't do anything. | ||
| if (keyPoints == null || keyPoints.size() == 0) { | ||
| if (keyPoints == null || keyPoints.isEmpty()) { | ||
| log.warn("No key points to visit!"); | ||
| return new InterpolationResult(currentLocation, true, Rotation2d.fromDegrees(0)); | ||
| } | ||
|
|
@@ -158,24 +160,35 @@ public InterpolationResult calculateTarget(Translation2d currentLocation) { | |
|
|
||
|
|
||
| // If the fraction is above 1, it's time to set a new baseline point and start LERPing on the next point | ||
| if (lerpFraction >= 1 && index < keyPoints.size()-1) { | ||
| // What was our target now becomes our baseline. | ||
| while (index < keyPoints.size() - 1) { | ||
|
trisceptre marked this conversation as resolved.
|
||
| double segmentTime = targetKeyPoint.getSecondsForSegment(); | ||
| if (segmentTime <= 0) { | ||
| log.warn("Cannot have a keypoint with a time of 0 or less! Skipping to next point."); | ||
| index++; | ||
| if (index >= keyPoints.size()) { | ||
| break; | ||
| } | ||
| targetKeyPoint = keyPoints.get(index); | ||
|
trisceptre marked this conversation as resolved.
|
||
| continue; | ||
| } | ||
|
|
||
| if (accumulatedProductiveSeconds < segmentTime) { | ||
| break; | ||
| } | ||
|
|
||
| accumulatedProductiveSeconds -= segmentTime; | ||
| baseline = targetKeyPoint; | ||
| accumulatedProductiveSeconds = 0; | ||
| lerpFraction = 0; | ||
| log.debug("LerpFraction is above one, so advancing to next keypoint"); | ||
| index++; | ||
|
|
||
| // And set our new target to the next element of the list | ||
| targetKeyPoint = keyPoints.get(index); | ||
| log.debug("Baseline is now " + baseline.getTranslation2d() | ||
| + " and target is now " + targetKeyPoint.getTranslation2d()); | ||
|
|
||
| log.info("Advancing to next keypoint, new baseline is {} and new target is {}", baseline.getTranslation2d(), targetKeyPoint.getTranslation2d()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❔ would we ever have so many keypoints that this logline would become spammy?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Most likely not, the regular Simple Interpolator contains a similar line and there were no complaints about log spamming there, at least not to my knowledge. |
||
| if (usingKinematics) { | ||
| calculator = newCalculator(targetKeyPoint.getTranslation2d(), targetKeyPoint.getKinematics()); | ||
| } | ||
| } | ||
|
|
||
| lerpFraction = accumulatedProductiveSeconds / targetKeyPoint.getSecondsForSegment(); | ||
|
|
||
|
trisceptre marked this conversation as resolved.
Outdated
|
||
| // Most of the time, the fraction will be less than one. | ||
| // In that case, we want to interpolate between the baseline and the target. | ||
| if (lerpFraction < 1) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.