Skip to content

Commit

Permalink
Anti-Jitter should go before cosine compensation. Fixes many issues.
Browse files Browse the repository at this point in the history
Signed-off-by: thenetworkgrinch <thenetworkgrinch@users.noreply.github.com>
  • Loading branch information
thenetworkgrinch committed Feb 17, 2024
1 parent 6cbb07b commit 8aaf39d
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/main/java/swervelib/SwerveModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,14 @@ public void queueSynchronizeEncoders()
public void setDesiredState(SwerveModuleState desiredState, boolean isOpenLoop, boolean force)
{
desiredState = SwerveModuleState.optimize(desiredState, Rotation2d.fromDegrees(getAbsolutePosition()));

// If we are forcing the angle
if (!force)
{
// Prevents module rotation if speed is less than 1%
SwerveMath.antiJitter(desiredState, lastState, Math.min(maxSpeed, 4));
}

// Cosine compensation.
double velocity = configuration.useCosineCompensator
? getCosineCompensatedVelocity(desiredState)
Expand All @@ -263,13 +271,6 @@ public void setDesiredState(SwerveModuleState desiredState, boolean isOpenLoop,
desiredState.speedMetersPerSecond = velocity;
}

// If we are forcing the angle
if (!force)
{
// Prevents module rotation if speed is less than 1%
SwerveMath.antiJitter(desiredState, lastState, Math.min(maxSpeed, 4));
}

// Prevent module rotation if angle is the same as the previous angle.
// Synchronize encoders if queued and send in the current position as the value from the absolute encoder.
if (absoluteEncoder != null && synchronizeEncoderQueued)
Expand Down

0 comments on commit 8aaf39d

Please sign in to comment.