Fix motor not stopping on repeated faults by clearing fault code on the same tick as the stop time expires - #926
Merged
Merged
Conversation
Owner
|
Nice find, this looks like an important fix! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This fixes a bug where where the motor can end up running an old current command indefinitely while faulted, set-current 0 and brake commands are silently ignored, and only the estop in vesctool or erasing the lisp code would stop it.
It can be reproduced quite easily in 7.00 by setting "Absolute Maximum Current" lower than "Motor Current Max", in my case i set it to 1A. If you then run
The motor will spin up really fast, and it won't stop even when the set-current 0 loop starts.
The issues stems from:
bldc/motor/mc_interface.c
Lines 2579 to 2586 in 9ff7e2e
If m_ignore_iterations is 1 then it will get decreased to 0 but fault code in m_fault_now won't be cleared until the next time this runs. Now since m_ignore_iterations is 0 the motor can receive commands again, but the fault logic only stops the motor if it has a new fault code
bldc/motor/mc_interface.c
Lines 2969 to 2972 in 9ff7e2e
So the bug is if the motor faults (due to a too high current) and then receives a high set-current command right after m_ignore_iterations becomes 0 (i.e. when the first fault expires) that causes the motor to instantly fault again the set-current command won't be cleared by the fault logic and now the motor will get stuck in a loop where it continously faults and therefore never clears the problematic set-current.
The reason I added the lock is that if this thread somehow gets preempted by another thread that sets current after ignore_iterations has been set to 0 but before the fault code has been set we would get the same issue.