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:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user