diff --git a/src/motor.cpp b/src/motor.cpp index 46fed8c..f0f505c 100644 --- a/src/motor.cpp +++ b/src/motor.cpp @@ -329,19 +329,19 @@ void MotorController::checkStall() { } unsigned long now = millis(); - - // Skip stall detection during stabilization period after motor start/change - if ((now - _motorStartTime) < STALL_STABILIZE_MS) { - return; - } - float activeCurrent = getCurrentActive(); - // Initialize or update EMA (exponential moving average) + // Initialize EMA on first reading if (!_emaInitialized) { - _currentEMA = activeCurrent; // Seed with first reading + _currentEMA = activeCurrent; _emaInitialized = true; - return; // Need more samples before detecting + } + + // During stabilization: update EMA but don't detect stalls + // This lets EMA track normal running current before detection starts + if ((now - _motorStartTime) < STALL_STABILIZE_MS) { + _currentEMA = (STALL_EMA_ALPHA * activeCurrent) + ((1.0f - STALL_EMA_ALPHA) * _currentEMA); + return; } // Calculate delta from average