Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
6 changes: 6 additions & 0 deletions src/main/java/frc/robot/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,12 @@ public static final class ScoringConstants {
public static final double aimerkV = 1.51;
public static final double aimerkA = 0.01;

// TODO: find real values
public static final double aimerFaultkS = 0.4;
public static final double aimerFaultkG = 0.2;
public static final double aimerFaultkV = 3;
public static final double aimerFaultkA = 0.02;

public static final double shooterkP = 0.05;
public static final double shooterkI = 0.2;
public static final double shooterkD = 0.0;
Expand Down
90 changes: 85 additions & 5 deletions src/main/java/frc/robot/subsystems/scoring/AimerIOTalon.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public class AimerIOTalon implements AimerIO {
double lastPosition = 0.0;
double lastTime = Utils.getCurrentTimeSeconds();

boolean motorLeftFailure = false, motorRightFailure = false;
boolean motorCheckOverriden = false;

public AimerIOTalon() {
aimerRight.setControl(new Follower(ScoringConstants.aimLeftMotorId, true));

Expand Down Expand Up @@ -126,12 +129,81 @@ public void setFF(double kS, double kV, double kA, double kG) {
aimerRight.getConfigurator().apply(slot0);
}

private boolean checkForAimMotorFailure() {

/*if (!aimerLeft.isAlive() || !aimerRight.isAlive()) {
if (!motorCheckOverriden) setFF(ScoringConstants.aimerFaultkS, ScoringConstants.aimerFaultkV, ScoringConstants.aimerFaultkA, ScoringConstants.aimerFaultkG);
motorFailure = true;
} else if (motorFailure) {
if (!motorCheckOverriden) setFF(ScoringConstants.aimerkS, ScoringConstants.aimerkV, ScoringConstants.aimerkA, ScoringConstants.aimerkG);
motorFailure = false;
}
return motorFailure;*/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it can be removed


// LEFT MOTOR
if ((!aimerLeft.isAlive())
|| // if motor disconnected
(Math.abs(aimerRight.getStatorCurrent().getValueAsDouble())
- Math.abs(aimerLeft.getStatorCurrent().getValueAsDouble())
> 1
&& Math.abs(aimerLeft.getMotorVoltage().getValueAsDouble()) > 0.5)
|| // if motor voltage is really small when it shouldn't be
(Math.abs(aimerLeft.getStatorCurrent().getValueAsDouble())
- Math.abs(aimerRight.getStatorCurrent().getValueAsDouble())
> 1
&& Math.abs(aimerLeft.getMotorVoltage().getValueAsDouble())
< 0.5) // if motor voltage is really large when it shouldn't be
) {
motorLeftFailure = true;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are duplicating a lot of this code below, could we make this into a function that returns a boolean on if the motor is faulty or not?


// RIGHT MOTOR
if ((!aimerRight.isAlive())
|| // if motor disconnected
(Math.abs(aimerLeft.getStatorCurrent().getValueAsDouble())
- Math.abs(aimerRight.getStatorCurrent().getValueAsDouble())
> 1
&& Math.abs(aimerRight.getMotorVoltage().getValueAsDouble()) > 0.5)
|| // if motor voltage is really small when it shouldn't be
(Math.abs(aimerRight.getStatorCurrent().getValueAsDouble())
- Math.abs(aimerLeft.getStatorCurrent().getValueAsDouble())
> 1
&& Math.abs(aimerRight.getMotorVoltage().getValueAsDouble())
< 0.5) // if motor voltage is really large when it shouldn't be
) {
motorRightFailure = true;
}

if (!motorCheckOverriden) shutOffFaultyAimMotors();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use curly braces on if/else statements?


return motorLeftFailure || motorRightFailure;
}

private void shutOffFaultyAimMotors() {
if (motorLeftFailure) {
aimerLeft.setVoltage(0);
}
if (motorRightFailure) {
aimerRight.setVoltage(0);
}
if (motorLeftFailure || motorRightFailure) {
setFF(
ScoringConstants.aimerFaultkS,
ScoringConstants.aimerFaultkV,
ScoringConstants.aimerFaultkA,
ScoringConstants.aimerFaultkG);
}
}

@Override
public void updateInputs(AimerIOInputs inputs) {
if (override) {
aimerLeft.setVoltage(overrideVolts);
if (!motorLeftFailure || motorCheckOverriden) aimerLeft.setVoltage(overrideVolts);
else aimerRight.setVoltage(overrideVolts);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use curly braces on if/else statements?

} else {
aimerLeft.setControl(controller.withPosition(goalAngleRad));
if (!motorLeftFailure || motorCheckOverriden)
aimerLeft.setControl(controller.withPosition(goalAngleRad));
else aimerRight.setControl(controller.withPosition(goalAngleRad));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use curly braces on if/else statements?

}

inputs.aimGoalAngleRad = goalAngleRad;
Expand All @@ -146,8 +218,16 @@ public void updateInputs(AimerIOInputs inputs) {
lastPosition = encoder.getAbsolutePosition();
inputs.aimVelocityRadPerSec = 0.0;

inputs.aimAppliedVolts = aimerLeft.getMotorVoltage().getValueAsDouble();
inputs.aimStatorCurrentAmps = aimerLeft.getStatorCurrent().getValueAsDouble();
inputs.aimSupplyCurrentAmps = aimerLeft.getSupplyCurrent().getValueAsDouble();
if (!motorLeftFailure || motorCheckOverriden) {
inputs.aimAppliedVolts = aimerLeft.getMotorVoltage().getValueAsDouble();
inputs.aimStatorCurrentAmps = aimerLeft.getStatorCurrent().getValueAsDouble();
inputs.aimSupplyCurrentAmps = aimerLeft.getSupplyCurrent().getValueAsDouble();
} else {
inputs.aimAppliedVolts = aimerRight.getMotorVoltage().getValueAsDouble();
inputs.aimStatorCurrentAmps = aimerLeft.getStatorCurrent().getValueAsDouble();
inputs.aimSupplyCurrentAmps = aimerLeft.getSupplyCurrent().getValueAsDouble();
}

checkForAimMotorFailure();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we check for motor failure at the top of this function (that way we can detect failure on the same frame we set the motor values)?

}
}