-
Notifications
You must be signed in to change notification settings - Fork 0
Aim motor adjustments in case of failure #154
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
589faf8
a670979
447bfe6
406a1db
9e28133
957d66e
df284dd
0ccde55
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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)); | ||
|
|
||
|
|
@@ -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;*/ | ||
|
|
||
| // 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; | ||
| } | ||
|
||
|
|
||
| // 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(); | ||
|
||
|
|
||
| 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); | ||
|
||
| } else { | ||
| aimerLeft.setControl(controller.withPosition(goalAngleRad)); | ||
| if (!motorLeftFailure || motorCheckOverriden) | ||
| aimerLeft.setControl(controller.withPosition(goalAngleRad)); | ||
| else aimerRight.setControl(controller.withPosition(goalAngleRad)); | ||
|
||
| } | ||
|
|
||
| inputs.aimGoalAngleRad = goalAngleRad; | ||
|
|
@@ -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(); | ||
|
||
| } | ||
| } | ||
There was a problem hiding this comment.
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