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

Aim motor adjustments in case of failure #154

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Conversation

minhnguyenbhs
Copy link
Contributor

I added checking for both motor disconnection + disparities in current: what else should I add?

…h velocity as well as stator current when i was using current to see if the motor was dead but convienently wpilib has an "isalive" function that hopefully works
@minhnguyenbhs minhnguyenbhs requested a review from jkleiber March 7, 2024 01:02
Copy link
Member

@jkleiber jkleiber left a comment

Choose a reason for hiding this comment

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

First pass comments, we will need to test this on the robot before merging as well

Comment on lines 144 to 158
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
Member

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?

Comment on lines 201 to 202
if (!motorLeftFailure || motorCheckOverriden) aimerLeft.setVoltage(overrideVolts);
else aimerRight.setVoltage(overrideVolts);
Copy link
Member

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?

Comment on lines 204 to 206
if (!motorLeftFailure || motorCheckOverriden)
aimerLeft.setControl(controller.withPosition(goalAngleRad));
else aimerRight.setControl(controller.withPosition(goalAngleRad));
Copy link
Member

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?

Comment on lines 134 to 141
/*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
Member

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

motorRightFailure = true;
}

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

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.aimSupplyCurrentAmps = aimerLeft.getSupplyCurrent().getValueAsDouble();
}

checkForAimMotorFailure();
Copy link
Member

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)?

@minhnguyenbhs minhnguyenbhs linked an issue Mar 9, 2024 that may be closed by this pull request
3 tasks
@minhnguyenbhs minhnguyenbhs requested a review from jkleiber March 11, 2024 22:34
Copy link
Member

@jkleiber jkleiber left a comment

Choose a reason for hiding this comment

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

One bigger comment, but once addressed I think we should test this on the robot

Comment on lines 159 to 168
> 1
&& Math.abs(check.getMotorVoltage().getValueAsDouble()) > 0.5) {
// motor voltage is really small when it shouldn't be
return true;
}

if (Math.abs(check.getStatorCurrent().getValueAsDouble())
- Math.abs(compare.getStatorCurrent().getValueAsDouble())
> 1
&& Math.abs(check.getMotorVoltage().getValueAsDouble()) < 0.5) {
Copy link
Member

Choose a reason for hiding this comment

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

Some points of feedback here:

  1. These thresholds should be set as constants in Constants.java
  2. These are really tight thresholds. 1 A or 0.5 V is common to see as a difference between two motors. Would recommend a much bigger value for amps, but this should be pulled from match/robot data where the aimer motor was not connected most likely.
  3. We should add a time aspect to this. "If the motors disagree by X current for 1 cycle" will yield many false positives. Let's add that they must disagree for T time
  4. Some of this logic looks duplicated?

Copy link
Member

@jkleiber jkleiber left a comment

Choose a reason for hiding this comment

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

We should test this (with single and double motors) before merging

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Gracefully handle arm rotation motor failure
2 participants