Skip to content

Conversation

@minhlpnguyen
Copy link
Collaborator

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
@minhlpnguyen minhlpnguyen requested a review from jkleiber March 7, 2024 01:02
Copy link
Collaborator

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

Comment on lines 201 to 202
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?

Comment on lines 204 to 206
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?

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

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?

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

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

@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
Collaborator

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
Collaborator

@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

3 participants