Replace absolute stall threshold with delta-based detection

- Use exponential moving average (EMA) to track normal running current
- Detect stall when current spikes above average by STALL_DELTA_THRESHOLD (2.0A)
- Add stabilization period (500ms) after motor start to let EMA settle
- Stall confirmation requires spike to persist for STALL_CONFIRM_MS (100ms)
- EMA stops updating during stall to prevent threshold creep
- Removes dependency on absolute current threshold that varied with speed
This commit is contained in:
devdesk
2026-02-05 18:20:26 +02:00
parent 63ad41970c
commit 87a05fc80a
3 changed files with 66 additions and 17 deletions

View File

@@ -45,6 +45,11 @@ private:
int _adcOffsetRight = 0;
int _adcOffsetLeft = 0;
// Delta-based stall detection (rolling average tracking)
float _currentEMA = 0; // Exponential moving average of current
unsigned long _motorStartTime = 0; // When motor started (for stabilization period)
bool _emaInitialized = false; // EMA needs seeding on first reading
// Pingpong state
bool _pingpongActive = false;
int _pingpongBaseSpeed = 50;
@@ -61,6 +66,7 @@ private:
float readCurrentSense(int pin);
void calibrateCurrentOffset();
void checkStall();
void resetStallDetection();
void updatePingpong();
int applyRandomness(int baseValue, int randomPercent);
};