Fix EMA chasing spike during detection window

Freeze EMA updates when any spike candidate is detected (delta > threshold),
not just after stall is confirmed. This prevents EMA from rising to meet
the spike before the confirmation time elapses.
This commit is contained in:
devdesk
2026-02-05 18:23:10 +02:00
parent 87a05fc80a
commit 80ce8ff63d

View File

@@ -347,13 +347,16 @@ void MotorController::checkStall() {
// Calculate delta from average
float delta = activeCurrent - _currentEMA;
// Update EMA (only when not in stall to prevent average rising during stall)
if (!_stalled) {
// Check if current spike exceeds delta threshold
bool spikeDetected = (delta > STALL_DELTA_THRESHOLD);
// Update EMA only when no spike is being investigated
// This prevents EMA from "chasing" up to the spike during detection window
if (!spikeDetected && !_stalled) {
_currentEMA = (STALL_EMA_ALPHA * activeCurrent) + ((1.0f - STALL_EMA_ALPHA) * _currentEMA);
}
// Check if current spike exceeds delta threshold
if (delta > STALL_DELTA_THRESHOLD) {
if (spikeDetected) {
if (_stallStartTime == 0) {
// Start timing potential stall
_stallStartTime = now;