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