Skip to content
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

Integrate x and y swerve sample values #1142

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
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
36 changes: 32 additions & 4 deletions choreolib/src/main/java/choreo/trajectory/SwerveSample.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ public ChassisSpeeds getChassisSpeeds() {
@Override
public SwerveSample interpolate(SwerveSample endValue, double timestamp) {
double scale = (timestamp - this.t) / (endValue.t - this.t);
var interp_pose = getPose().interpolate(endValue.getPose(), scale);

double[] interp_fx = new double[4];
double[] interp_fy = new double[4];
Expand All @@ -156,11 +155,40 @@ public SwerveSample interpolate(SwerveSample endValue, double timestamp) {
MathUtil.interpolate(this.moduleForcesY()[i], endValue.moduleForcesY()[i], scale);
}

// Integrate the field speeds to get the pose for this interpolated state, since linearly
// interpolating the pose gives an inaccurate result if the speeds are changing between states
double lerpedTimestamp = timestamp;
double lerpedVXPos = vx;
double lerpedVYPos = vy;
double lerpedXPos = x;
double lerpedYPos = y;
double intTime = t + 0.01;
calcmogul marked this conversation as resolved.
Show resolved Hide resolved

while (true) {
double intT = (intTime - getTimestamp()) / (lerpedTimestamp - getTimestamp());
double intAX = MathUtil.interpolate(ax, endValue.ax, intT);
double intAY = MathUtil.interpolate(ay, endValue.ax, intT);

if (intTime >= lerpedTimestamp - 0.01) {
double dt = lerpedTimestamp - intTime;
lerpedVXPos += intAX * dt;
lerpedVYPos += intAY * dt;
lerpedXPos += lerpedVXPos * dt;
lerpedYPos += lerpedVYPos * dt;
Comment on lines +176 to +177
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This using the velocity of the next timestep instead of the current one is suspicious.

break;
}

lerpedVXPos += intAX * 0.01;
lerpedVYPos += intAY * 0.01;

intTime += 0.01;
}

return new SwerveSample(
MathUtil.interpolate(this.t, endValue.t, scale),
interp_pose.getX(),
interp_pose.getY(),
interp_pose.getRotation().getRadians(),
lerpedXPos,
lerpedYPos,
MathUtil.interpolate(heading, endValue.heading, t),
MathUtil.interpolate(this.vx, endValue.vx, scale),
MathUtil.interpolate(this.vy, endValue.vy, scale),
MathUtil.interpolate(this.omega, endValue.omega, scale),
Expand Down
Loading