Added redundancy to prevent sending CAN messages too often, might interfere with PWM motors

This commit is contained in:
thenetworkgrinch
2023-03-06 20:55:49 -06:00
parent 5fd00878d2
commit 1bebe8a5fd

View File

@@ -47,6 +47,10 @@ public class SwerveModule
* Last angle set for the swerve module.
*/
public double lastAngle;
/**
* Last velocity set for the swerve module.
*/
public double lastVelocity;
/**
* Simulated swerve module.
*/
@@ -161,7 +165,11 @@ public class SwerveModule
} else
{
double velocity = desiredState.speedMetersPerSecond;
driveMotor.setReference(velocity, feedforward.calculate(velocity));
if (velocity != lastVelocity)
{
driveMotor.setReference(velocity, feedforward.calculate(velocity));
}
lastVelocity = velocity;
}
// Prevents module rotation if speed is less than 1%
@@ -169,8 +177,11 @@ public class SwerveModule
(Math.abs(desiredState.speedMetersPerSecond) <= (configuration.maxSpeed * 0.01)
? lastAngle
: desiredState.angle.getDegrees());
angleMotor.setReference(
angle, Math.toDegrees(desiredState.omegaRadPerSecond) * configuration.angleKV);
if (angle != lastAngle)
{
angleMotor.setReference(
angle, Math.toDegrees(desiredState.omegaRadPerSecond) * configuration.angleKV);
}
lastAngle = angle;
if (SwerveDriveTelemetry.isSimulation)