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.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user