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

Add fault detection and auto-shutoff to shooter if encoder is unplugged #198

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
add basic fault detection
aidnem committed Apr 30, 2024
commit acba94c98c4b0fbeaa0395acca5798829222d403
5 changes: 4 additions & 1 deletion src/main/java/frc/robot/Constants.java
Original file line number Diff line number Diff line change
@@ -53,7 +53,7 @@ public static final class FeatureFlags {
public static final boolean runLocalizer = true;

public static final boolean runIntake = false;
public static final boolean runScoring = false;
public static final boolean runScoring = true;
public static final boolean runEndgame = false;
public static final boolean runDrive = true;

@@ -480,6 +480,9 @@ public static final class ScoringConstants {
public static final double aimerkI = 10.0; // 5.0
public static final double aimerkD = 0.0;

public static final double aimerMovementThresholdRadPerSec = 0.05;
public static final double maxAimUnresponsiveTimeSeconds = 0.1;

public static final double aimerkS = 0.265;
public static final double aimerkG = 0.1;
public static final double aimerkV = 1.51;
Original file line number Diff line number Diff line change
@@ -213,7 +213,7 @@ public void updateInputs(AimerIOInputs inputs) {
feedforward.calculate(controlSetpoint, velocitySetpoint) + controllerVolts;
}

appliedVolts = MathUtil.clamp(appliedVolts, -12.0, 12.0);
appliedVolts = MathUtil.clamp(appliedVolts, -4.0, 4.0);
if (!motorDisabled || override) {
aimerRight.setVoltage(appliedVolts);
} else {
2 changes: 2 additions & 0 deletions src/main/java/frc/robot/subsystems/scoring/AimerIOSim.java
Original file line number Diff line number Diff line change
@@ -126,6 +126,8 @@ public void updateInputs(AimerIOInputs inputs) {
sim.setInputVoltage(appliedVolts);
}

sim.setInputVoltage(0.0);

inputs.aimGoalAngleRad = goalAngleRad;
inputs.aimProfileGoalAngleRad = trapezoidSetpoint.position;
inputs.aimAngleRad = sim.getAngleRads();
30 changes: 30 additions & 0 deletions src/main/java/frc/robot/subsystems/scoring/ScoringSubsystem.java
Original file line number Diff line number Diff line change
@@ -111,6 +111,12 @@ public enum ScoringAction {

private boolean readyToShoot = false;

// Keep track of the amount of time the arm has been unresponsive for
private Timer armUnresponsiveTime = new Timer();

// Something has gone wrong: disable the arm until code is restarted
private boolean faulted = false;

public ScoringSubsystem(ShooterIO shooterIo, AimerIO aimerIo, HoodIO hoodIo) {

this.shooterIo = shooterIo;
@@ -169,6 +175,8 @@ private void idle() {

Logger.recordOutput("scoring/aimGoal", 0.0);

Logger.recordOutput("scoring/faulted", faulted);

SmartDashboard.putBoolean("Has Note", shooterInputs.bannerSensor);
SmartDashboard.putNumber("Aimer Location", aimerInputs.aimAngleRad);

@@ -479,6 +487,8 @@ public void enabledInit() {

@Override
public void periodic() {
Logger.recordOutput("scoring/faulted", faulted);

if (!SmartDashboard.containsKey("Aimer Offset")) {
SmartDashboard.putNumber("Aimer Offset", ScoringConstants.aimerStaticOffset);
}
@@ -591,7 +601,27 @@ && willHitStage()) {
}

shooterIo.updateInputs(shooterInputs);

if (faulted && DriverStation.isEnabled()) {
aimerIo.setOverrideMode(true);
aimerIo.setOverrideVolts(0.0);
}
aimerIo.updateInputs(aimerInputs);

if (DriverStation.isEnabled()
&& (aimerInputs.aimAppliedVolts > ScoringConstants.aimerkS * 2
&& aimerInputs.aimVelocityRadPerSec
< ScoringConstants.aimerMovementThresholdRadPerSec)) {
armUnresponsiveTime.start();

if (armUnresponsiveTime.get() > ScoringConstants.maxAimUnresponsiveTimeSeconds) {
faulted = true;
}
} else {
armUnresponsiveTime.reset();
armUnresponsiveTime.stop();
}

hoodIo.updateInputs(hoodInputs);

Logger.processInputs("scoring/shooter", shooterInputs);