mirror of
https://github.com/BroncBotz3481/YAGSL
synced 2026-06-19 06:21:40 +00:00
Added redundancy to prevent sending CAN messages too often, might interfere with PWM motors
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user