diff --git a/src/main/java/frc/robot/extras/TalonUtil.java b/src/main/java/frc/robot/extras/TalonUtil.java index 7786566..03c86e3 100644 --- a/src/main/java/frc/robot/extras/TalonUtil.java +++ b/src/main/java/frc/robot/extras/TalonUtil.java @@ -1,13 +1,12 @@ // somewhat inspired by 254 package frc.robot.extras; -import java.util.function.Supplier; - import com.ctre.phoenix.ErrorCode; import com.ctre.phoenix6.StatusCode; import com.ctre.phoenix6.configs.TalonFXConfiguration; import com.ctre.phoenix6.hardware.TalonFX; import edu.wpi.first.wpilibj.DriverStation; +import java.util.function.Supplier; public class TalonUtil { @@ -15,16 +14,16 @@ public static boolean applyAndCheckConfiguration( TalonFX talon, TalonFXConfiguration config, double timeoutSeconds, int numTries) { for (int i = 0; i < numTries; i++) { if (checkErrorAndRetry(() -> talon.getConfigurator().apply(config, timeoutSeconds))) { - return true; - } - } - DriverStation.reportError( - "Failed to apply config for talon after " + numTries + " attempts", false); - return false; + return true; + } } - + DriverStation.reportError( + "Failed to apply config for talon after " + numTries + " attempts", false); + return false; + } - public static boolean applyAndCheckConfiguration(TalonFX talon, TalonFXConfiguration config, double timeoutMs) { + public static boolean applyAndCheckConfiguration( + TalonFX talon, TalonFXConfiguration config, double timeoutMs) { boolean result = applyAndCheckConfiguration(talon, config, timeoutMs, 5); return result; } @@ -67,7 +66,7 @@ public static void checkStickyFaults(String subsystemName, TalonFX talon) { talon.clearStickyFaults(); } - /** + /** * checks the specified error code for issues * * @param errorCode error code diff --git a/src/main/java/frc/robot/subsystems/shooter/ShooterSubsystem.java b/src/main/java/frc/robot/subsystems/shooter/ShooterSubsystem.java index b775e5d..d37ebfd 100644 --- a/src/main/java/frc/robot/subsystems/shooter/ShooterSubsystem.java +++ b/src/main/java/frc/robot/subsystems/shooter/ShooterSubsystem.java @@ -59,8 +59,11 @@ public ShooterSubsystem() { private void configureTalons() throws RuntimeException { TalonFXConfiguration shooterConfig = new TalonFXConfiguration(); - TalonUtil.checkErrorAndRetry(() -> leaderFlywheel.getConfigurator().refresh(shooterConfig, HardwareConstants.TIMEOUT_S)); - TalonUtil.checkErrorAndRetry(() -> followerFlywheel.getConfigurator().refresh(shooterConfig, HardwareConstants.TIMEOUT_S)); + TalonUtil.checkErrorAndRetry( + () -> leaderFlywheel.getConfigurator().refresh(shooterConfig, HardwareConstants.TIMEOUT_S)); + TalonUtil.checkErrorAndRetry( + () -> + followerFlywheel.getConfigurator().refresh(shooterConfig, HardwareConstants.TIMEOUT_S)); shooterConfig.Slot0.kP = ShooterConstants.SHOOT_P; shooterConfig.Slot0.kI = ShooterConstants.SHOOT_I; @@ -77,12 +80,15 @@ private void configureTalons() throws RuntimeException { shooterConfig.CurrentLimits.SupplyCurrentLimit = ShooterConstants.SHOOTER_SUPPLY_LIMIT; shooterConfig.CurrentLimits.SupplyCurrentLimitEnable = ShooterConstants.SHOOTER_SUPPLY_ENABLE; - TalonUtil.applyAndCheckConfiguration(leaderFlywheel, shooterConfig, HardwareConstants.TIMEOUT_S); + TalonUtil.applyAndCheckConfiguration( + leaderFlywheel, shooterConfig, HardwareConstants.TIMEOUT_S); shooterConfig.MotorOutput.Inverted = InvertedValue.Clockwise_Positive; - TalonUtil.applyAndCheckConfiguration(followerFlywheel, shooterConfig, HardwareConstants.TIMEOUT_S); + TalonUtil.applyAndCheckConfiguration( + followerFlywheel, shooterConfig, HardwareConstants.TIMEOUT_S); TalonFXConfiguration rollerConfig = new TalonFXConfiguration(); - TalonUtil.checkErrorAndRetry(() -> leaderFlywheel.getConfigurator().refresh(rollerConfig, HardwareConstants.TIMEOUT_S)); + TalonUtil.checkErrorAndRetry( + () -> leaderFlywheel.getConfigurator().refresh(rollerConfig, HardwareConstants.TIMEOUT_S)); rollerConfig.MotorOutput.NeutralMode = NeutralModeValue.Brake; rollerConfig.MotorOutput.DutyCycleNeutralDeadband = HardwareConstants.MIN_FALCON_DEADBAND;