From 568339367e0000e257ee0a45884eb29c1e5ef4cc Mon Sep 17 00:00:00 2001 From: devdesk Date: Thu, 5 Feb 2026 18:29:33 +0200 Subject: [PATCH] Update EMA during stabilization period to track startup current Instead of seeding EMA with first reading after stabilization, now continuously update EMA during the 500ms stabilization window. This ensures EMA represents normal running current rather than potentially high stall current if motor hits end stop immediately. --- src/motor.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) 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