Skip to content

Fix motor not stopping on repeated faults by clearing fault code on the same tick as the stop time expires - #926

Merged
vedderb merged 1 commit into
vedderb:masterfrom
Jakowz:master
Jul 29, 2026
Merged

Fix motor not stopping on repeated faults by clearing fault code on the same tick as the stop time expires#926
vedderb merged 1 commit into
vedderb:masterfrom
Jakowz:master

Conversation

@Jakowz

@Jakowz Jakowz commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

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

(define start-time (systime))

(loopwhile (< (secs-since start-time) 10) {
    (set-current 10)
    (sleep 0.001)
})

(loopwhile t {
    (set-current 0)
    (sleep 0.01)
})

The motor will spin up really fast, and it won't stop even when the set-current 0 loop starts.

The issues stems from:

// Decrease fault iterations
if (motor->m_ignore_iterations > 0) {
    motor->m_ignore_iterations--;
} else {
    if (!(is_motor_1 ? IS_DRV_FAULT() : IS_DRV_FAULT_2())) {
        motor->m_fault_now = FAULT_CODE_NONE;
    }
}

bldc/motor/mc_interface.c

Lines 2579 to 2586 in 9ff7e2e

// Decrease fault iterations
if (motor->m_ignore_iterations > 0) {
motor->m_ignore_iterations--;
} else {
if (!(is_motor_1 ? IS_DRV_FAULT() : IS_DRV_FAULT_2())) {
motor->m_fault_now = FAULT_CODE_NONE;
}
}

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

if (motor->m_fault_now == fault_data_copy.fault_code) {
motor->m_ignore_iterations = motor->m_conf.m_fault_stop_time_ms;
continue;
}
.

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.

@vedderb

vedderb commented Jul 29, 2026

Copy link
Copy Markdown
Owner

Nice find, this looks like an important fix!

@vedderb
vedderb merged commit 781ce45 into vedderb:master Jul 29, 2026
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.

2 participants