Skip to content

Better handling of motor faults #3425

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

Open
wants to merge 59 commits into
base: master
Choose a base branch
from

Conversation

GrayHoang
Copy link
Contributor

@GrayHoang GrayHoang commented Feb 8, 2025

Please fill out the following before requesting review on this PR

Description

See #3408
https://github.com/user-attachments/assets/a77848b3-ee4a-4df8-ad6d-0fa36bc76db8

Changes motor fault handling to a per motor control.
Allows for faulty motors to be disabled without crashing thunderloop.
Disabled motors freewheel and are no longer checked for further issues. They will not be given commands to run.

Testing Done

Tested on robot. When fault is detected, movement halts and motors attempt to restart three times before disabling the affected motor and reinitializing all other motors.

Resolved Issues

Resolves #3408

Length Justification and Key Files to Review

Review Checklist

It is the reviewers responsibility to also make sure every item here has been covered

  • Function & Class comments: All function definitions (usually in the .h file) should have a javadoc style comment at the start of them. For examples, see the functions defined in thunderbots/software/geom. Similarly, all classes should have an associated Javadoc comment explaining the purpose of the class.
  • Remove all commented out code
  • Remove extra print statements: for example, those just used for testing
  • Resolve all TODO's: All TODO (or similar) statements should either be completed or associated with a github issue

@GrayHoang GrayHoang changed the title [WIP] Handle motor faults Better handling of motor faults Mar 2, 2025
@GrayHoang GrayHoang requested review from a team, suchirss and ericlim0329 and removed request for a team March 2, 2025 02:43
@GrayHoang
Copy link
Contributor Author

Need to do some final cleanup. I think I left some debugging stuff and I need to make sure all motors restart 3 times before failing (in the video you can see the affected motor only attempt restart twice).

Copy link
Contributor

@itsarune itsarune left a comment

Choose a reason for hiding this comment

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

almost there!

Comment on lines +202 to +207
/*
* Get the motor faults encountered so far.
*
* @return the mapping of motors to the object describing their faults.
*/
std::unordered_map<int, MotorFaultIndicator> getCachedMotorFaults();
Copy link
Contributor

Choose a reason for hiding this comment

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

can this be private:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was wondering if it would be useful for other files to use, perhaps if we wanted per-motor reports of motor faults in thunderscope/robot diag?

Copy link
Contributor

Choose a reason for hiding this comment

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

this is communicated through the RobotStatus proto. Other modules should be getting motor status info from RobotStatus rather than calling this function directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

image I think we do have one issue with robot auto test, what should I do?

* @param velocity the current velocity of the motor
* @param target target rpm
*/
void readThenWriteToEnabledMotor(uint8_t motor_chip, double& velocity, int target);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why use a reference to velocity here? Why not return the velocity?

You should also document that the velocity is an output argument that the function will modify

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't remember changing this line of code... It looks like deleting the reference should be fine, if you make it return and change around the dependent code?

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah i think that returning the velocity here makes this code more understandable to the layperson

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wait so if I make the change to return the velocity from reading then the parameter velocity shouldn't be changed, so I wouldn't need to change docs, right?

Copy link
Contributor

@itsarune itsarune left a comment

Choose a reason for hiding this comment

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

left some more comments

@GrayHoang
Copy link
Contributor Author

I'm going to need someone to test this in the mezz, or I can do it in about 2 weeks.

Copy link
Contributor

@itsarune itsarune left a comment

Choose a reason for hiding this comment

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

left a few comments

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.

Make motor fault handling safer
4 participants