Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added logging for talon configuration failures #153

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/com/team1701/robot/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import edu.wpi.first.wpilibj.DriverStation.Alliance;

public final class Configuration {
private static final RobotType kRobot = RobotType.SIMULATION_BOT;
private static final RobotType kRobot = RobotType.COMPETITION_BOT;

private static boolean mInvalidRobotAlerted = false;

Expand Down
16 changes: 15 additions & 1 deletion src/main/java/com/team1701/robot/util/TalonFxMotorFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import com.ctre.phoenix6.hardware.TalonFX;
import com.ctre.phoenix6.signals.InvertedValue;
import com.ctre.phoenix6.signals.NeutralModeValue;
import com.team1701.lib.alerts.Alert;
import com.team1701.lib.drivers.motors.MotorIOTalonFX;
import com.team1701.lib.drivers.motors.MotorIOTalonFXFOC;
import com.team1701.robot.Constants;
import org.littletonrobotics.junction.Logger;

public class TalonFxMotorFactory {
private static final InvertedValue kInverted = InvertedValue.Clockwise_Positive;
Expand Down Expand Up @@ -90,10 +92,22 @@ public static MotorIOTalonFXFOC createSteerMotorIOTalonFxFoc(int deviceId) {
}

private static void configureWithRetry(TalonFX motor, TalonFXConfiguration config) {
StatusCode statusCode = null;
for (int i = 0; i < 4; i++) {
if (motor.getConfigurator().apply(config, 0.1) == StatusCode.OK) {
statusCode = motor.getConfigurator().apply(config, 0.1);
if (statusCode == StatusCode.OK) {
break;
}
}

if (statusCode != StatusCode.OK) {
Alert.error("TalonFX configuration failed: id=" + motor.getDeviceID() + ",status=" + statusCode.toString())
.enable();

var actualConfig = new TalonFXConfiguration();
motor.getConfigurator().refresh(actualConfig, 0.1);
Logger.recordOutput("Motor/" + motor.getDeviceID() + "/Config", config.toString());
Logger.recordOutput("Motor/" + motor.getDeviceID() + "/ActualConfig", actualConfig.toString());
}
}
}