Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 25 additions & 12 deletions src/main/java/xbot/common/trajectory/SimpleTimeInterpolator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Comment thread
trisceptre marked this conversation as resolved.
Outdated

SwerveKinematicsCalculator calculator;

Expand All @@ -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;

Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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) {
Comment thread
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);
Comment thread
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());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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();

Comment thread
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) {
Expand Down
Loading