Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
Ishan1522 committed Aug 9, 2024
1 parent 51f121e commit b64d75a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
21 changes: 10 additions & 11 deletions src/main/java/frc/robot/extras/TalonUtil.java
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
// 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 {

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;
}
Expand Down Expand Up @@ -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
Expand Down
16 changes: 11 additions & 5 deletions src/main/java/frc/robot/subsystems/shooter/ShooterSubsystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit b64d75a

Please sign in to comment.