Add alerts to PWMDutyCycleEncoder and SparkMax

This commit is contained in:
Alex Sirota
2024-03-24 11:46:53 -07:00
parent 9a2eb4e74f
commit 20a8c990aa
2 changed files with 19 additions and 1 deletions

View File

@@ -26,6 +26,10 @@ public class PWMDutyCycleEncoderSwerve extends SwerveAbsoluteEncoder
* An {@link Alert} for if the encoder cannot report accurate velocities.
*/
private Alert inaccurateVelocities;
/**
* An {@link Alert} for if the encoder is disconnected.
*/
private Alert disconnected;
/**
* Constructor for the PWM duty cycle encoder.
@@ -39,6 +43,10 @@ public class PWMDutyCycleEncoderSwerve extends SwerveAbsoluteEncoder
"Encoders",
"The PWM Duty Cycle encoder may not report accurate velocities!",
Alert.AlertType.WARNING_TRACE);
inaccurateVelocities = new Alert(
"Encoders",
"The swerve encoder on port " + pin + "is disconnected!",
Alert.AlertType.ERROR_TRACE);
}
@@ -61,6 +69,7 @@ public class PWMDutyCycleEncoderSwerve extends SwerveAbsoluteEncoder
@Override
public double getAbsolutePosition()
{
disconnected.set(!encoder.isConnected());
return (isInverted ? -1.0 : 1.0) * encoder.getAbsolutePosition() * 360;
}
@@ -83,6 +92,7 @@ public class PWMDutyCycleEncoderSwerve extends SwerveAbsoluteEncoder
@Override
public double getVelocity()
{
disconnected.set(!encoder.isConnected());
inaccurateVelocities.set(true);
return encoder.get();
}