Remove all stall detection logic, add 100ms current logging
- Removed all STALL_* configuration parameters from config.h - Simplified motor.h: removed stall-related methods and member variables - Simplified motor.cpp: deleted checkStall(), resetStallDetection() - Added frequent current logging (100ms) for data collection - Removed stall callback system from main.cpp - Simplified pingpong mode: time-based only, removed stall-return option - Updated webserver: removed stall warning UI, removed stallReturn checkbox - Updated status JSON: removed stalled and ppStallReturn fields This version is for testing with new beefy PSU to collect current data before designing new stall detection algorithm.
This commit is contained in:
@@ -37,22 +37,8 @@
|
||||
#define ADC_VREF 3.3f // ADC reference voltage
|
||||
#define CURRENT_CALIBRATION 1.0f // Calibration factor (measured current / reported current)
|
||||
|
||||
// Stall Detection Configuration (delta-based)
|
||||
// Detects sudden current spikes above the rolling average
|
||||
#define STALL_DELTA_THRESHOLD 1.2f // Current spike above average that indicates stall (amps)
|
||||
#define STALL_EMA_ALPHA 0.1f // EMA smoothing factor (0.1 = slow, 0.5 = fast response)
|
||||
#define STALL_EMA_BASELINE 2.0f // Expected running current baseline for EMA seeding (amps)
|
||||
#define STALL_STABILIZE_MS 300 // Ignore stalls for this long after motor starts/changes
|
||||
#define STALL_CONFIRM_MS 50 // Current must exceed threshold for this long to confirm stall
|
||||
#define DISABLE_STALL_DETECT false // Set to true to disable stall detection
|
||||
|
||||
// Under-current stall detection: motor commanded but drawing no current
|
||||
#define STALL_UNDERCURRENT_THRESHOLD 0.5f // If current below this for too long = stall (amps)
|
||||
#define STALL_UNDERCURRENT_MS 1000 // Under-current must persist this long to confirm stall
|
||||
|
||||
// Repeated spike stall detection: catches oscillating stall (driver protection cycling)
|
||||
#define STALL_CANDIDATE_COUNT 5 // Number of stall candidates in window to confirm stall
|
||||
#define STALL_CANDIDATE_WINDOW_MS 2000 // Time window for counting stall candidates
|
||||
// Current logging interval for data collection
|
||||
#define CURRENT_LOG_INTERVAL_MS 100 // Log current readings every 100ms
|
||||
|
||||
// Web Server
|
||||
#define HTTP_PORT 80
|
||||
|
||||
@@ -10,53 +10,33 @@ public:
|
||||
void setSpeed(int speed); // 0-100 percentage
|
||||
void setDirection(int dir); // -1=reverse, 0=stop, 1=forward
|
||||
void stop();
|
||||
void update(); // Call in loop() for stall detection
|
||||
void update(); // Call in loop() for current monitoring
|
||||
|
||||
int getSpeed();
|
||||
int getDirection();
|
||||
float getCurrentRight(); // Current in amps (forward direction)
|
||||
float getCurrentLeft(); // Current in amps (reverse direction)
|
||||
float getCurrentActive(); // Current from active direction
|
||||
bool isStalled(); // True if stall detected
|
||||
|
||||
// Callback for stall events
|
||||
void setStallCallback(void (*callback)(float current));
|
||||
|
||||
// Pingpong mode
|
||||
void startPingpong(int speed, int timeMs, int speedRandomPercent, int timeRandomPercent, bool useStallReturn);
|
||||
// Pingpong mode (time-based only)
|
||||
void startPingpong(int speed, int timeMs, int speedRandomPercent, int timeRandomPercent);
|
||||
void stopPingpong();
|
||||
bool isPingpongActive();
|
||||
int getPingpongSpeed();
|
||||
int getPingpongTime();
|
||||
int getPingpongSpeedRandom();
|
||||
int getPingpongTimeRandom();
|
||||
bool getPingpongStallReturn();
|
||||
|
||||
private:
|
||||
int _speed = 0;
|
||||
int _direction = 0;
|
||||
float _currentRight = 0;
|
||||
float _currentLeft = 0;
|
||||
bool _stalled = false;
|
||||
unsigned long _stallStartTime = 0;
|
||||
void (*_stallCallback)(float current) = nullptr;
|
||||
|
||||
// ADC zero-current offset (calibrated at startup)
|
||||
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
|
||||
|
||||
// Under-current stall detection
|
||||
unsigned long _undercurrentStartTime = 0; // When under-current condition started
|
||||
|
||||
// Repeated spike detection (oscillating stall pattern)
|
||||
int _stallCandidateCount = 0; // Number of stall candidates in current window
|
||||
unsigned long _stallCandidateWindowStart = 0; // When current counting window started
|
||||
|
||||
// Pingpong state
|
||||
bool _pingpongActive = false;
|
||||
int _pingpongBaseSpeed = 50;
|
||||
@@ -67,13 +47,10 @@ private:
|
||||
int _pingpongCurrentTime = 2000;
|
||||
unsigned long _pingpongLastSwitch = 0;
|
||||
int _pingpongDirection = 1;
|
||||
bool _pingpongUseStallReturn = false; // Return only after stall detection
|
||||
|
||||
void applyMotorState();
|
||||
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