Add branch plan documentation and sample current log data

- plans/remove-stall-detection-branch.md: Documents what was removed, data analysis, and next steps
- src/current_loggin.log: Sample current data showing clear stall signatures
This commit is contained in:
devdesk
2026-02-05 21:10:07 +02:00
parent dd274202bb
commit 3aec7250c9
2 changed files with 232 additions and 0 deletions

View File

@@ -0,0 +1,104 @@
# Branch: feature/remove-stall-detection
## Summary
Removed all stall detection logic to collect clean current data with new beefy PSU before reimplmenting simpler stall detection.
## Problem
The original stall detection was overly complex with:
- Delta-based spike detection with EMA averaging
- Under-current detection
- Repeated spike detection for oscillating patterns
- Multiple timing thresholds and stabilization periods
- 16 configuration parameters
This complexity was trying to compensate for a weak PSU that couldn't provide enough current, causing unreliable stall detection.
## What Was Removed
### config.h
- `STALL_DELTA_THRESHOLD`
- `STALL_EMA_ALPHA`
- `STALL_EMA_BASELINE`
- `STALL_STABILIZE_MS`
- `STALL_CONFIRM_MS`
- `DISABLE_STALL_DETECT`
- `STALL_UNDERCURRENT_THRESHOLD`
- `STALL_UNDERCURRENT_MS`
- `STALL_CANDIDATE_COUNT`
- `STALL_CANDIDATE_WINDOW_MS`
### motor.h / motor.cpp
- `checkStall()` function (~115 lines)
- `resetStallDetection()` function
- `isStalled()` method
- `setStallCallback()` method
- `getPingpongStallReturn()` method
- All stall-related member variables
### webserver.cpp
- Stall warning UI banner
- "Return on stall only" checkbox
- `stalled` and `ppStallReturn` from status JSON
### main.cpp
- `onMotorStall()` callback function
## What Was Added
- `CURRENT_LOG_INTERVAL_MS` config (100ms)
- Frequent current logging: `CURRENT: R=%.2fA L=%.2fA dir=%d spd=%d`
- "Motor: STOPPED (manual)" message
## Current Data Analysis
See [src/current_loggin.log](../src/current_loggin.log) for sample data.
### Running Current (motor moving freely)
- **Range:** 0.67A - 2.64A
- **Average:** ~1.5-2.0A
### Stall Current (motor blocked at end stop)
- **Range:** 16.8A - 21.0A
- **Average:** ~17-18A
### Key Observations
1. **Clear separation:** Running ~2A vs Stall ~17A = 8.5x difference
2. **Fast transition:** Stall spike happens within 1-2 samples (100-200ms)
3. **Initial spike:** Can see 3.77A or 5.35A briefly before full stall current
4. **Gradual decay:** Stall current trends down slightly over time (~21A → ~17A)
## Next Step: Simple Stall Detection
Based on the clean data, implement a simple threshold-based stall detection:
### Proposed Algorithm
```
IF motor is running (dir != 0 AND speed > 0):
IF active_current > STALL_THRESHOLD for STALL_CONFIRM_SAMPLES:
STALL DETECTED
```
### Proposed Config (much simpler)
```c
#define STALL_THRESHOLD 8.0f // Amps - midpoint between 2A run and 17A stall
#define STALL_CONFIRM_SAMPLES 3 // Debounce: 3 samples = 300ms at 100ms interval
```
### Why This Should Work
- With beefy PSU, running current is stable ~2A
- Stall current is clearly ~17A+
- No need for EMA averaging or complex spike detection
- Simple threshold + debounce is enough
## Files Changed
| File | Lines Removed | Lines Added |
|------|---------------|-------------|
| config.h | 16 | 2 |
| motor.h | 26 | 0 |
| motor.cpp | 180 | 1 |
| webserver.cpp | 50 | 5 |
| main.cpp | 12 | 1 |
| **Total** | **284** | **9** |

128
src/current_loggin.log Normal file
View File

@@ -0,0 +1,128 @@
CURRENT: R=0.00A L=0.00A dir=0 spd=0
CURRENT: R=0.00A L=0.00A dir=0 spd=0
CURRENT: R=0.00A L=0.00A dir=0 spd=0
CURRENT: R=0.00A L=0.00A dir=0 spd=0
CURRENT: R=0.00A L=0.00A dir=0 spd=0
CURRENT: R=0.00A L=0.00A dir=0 spd=0
CURRENT: R=0.00A L=0.00A dir=0 spd=0
CURRENT: R=0.00A L=0.00A dir=0 spd=0
Motor: dir=1, speed=0%, pwm=0
CURRENT: R=0.00A L=0.00A dir=1 spd=0
CURRENT: R=0.00A L=0.00A dir=1 spd=0
CURRENT: R=0.00A L=0.00A dir=1 spd=0
CURRENT: R=0.00A L=0.00A dir=1 spd=0
CURRENT: R=0.00A L=0.00A dir=1 spd=0
CURRENT: R=0.00A L=0.00A dir=1 spd=0
CURRENT: R=0.00A L=0.00A dir=1 spd=0
CURRENT: R=0.00A L=0.00A dir=1 spd=0
CURRENT: R=0.00A L=0.00A dir=1 spd=0
CURRENT: R=0.00A L=0.00A dir=1 spd=0
Motor: dir=-1, speed=0%, pwm=0
CURRENT: R=0.00A L=0.00A dir=-1 spd=0
CURRENT: R=0.00A L=0.00A dir=-1 spd=0
CURRENT: R=0.00A L=0.00A dir=-1 spd=0
CURRENT: R=0.00A L=0.00A dir=-1 spd=0
CURRENT: R=0.00A L=0.00A dir=-1 spd=0
CURRENT: R=0.00A L=0.00A dir=-1 spd=0
CURRENT: R=0.00A L=0.00A dir=-1 spd=0
CURRENT: R=0.00A L=0.00A dir=-1 spd=0
Motor: dir=-1, speed=100%, pwm=255
CURRENT: R=0.00A L=0.88A dir=-1 spd=100
CURRENT: R=0.00A L=2.07A dir=-1 spd=100
CURRENT: R=0.00A L=1.49A dir=-1 spd=100
CURRENT: R=0.00A L=2.56A dir=-1 spd=100
CURRENT: R=0.00A L=1.25A dir=-1 spd=100
Motor: dir=-1, speed=100%, pwm=255
CURRENT: R=0.00A L=1.10A dir=-1 spd=100
CURRENT: R=0.00A L=2.18A dir=-1 spd=100
CURRENT: R=0.00A L=1.36A dir=-1 spd=100
CURRENT: R=0.00A L=1.28A dir=-1 spd=100
CURRENT: R=0.00A L=2.39A dir=-1 spd=100
CURRENT: R=0.00A L=1.47A dir=-1 spd=100
CURRENT: R=0.00A L=1.25A dir=-1 spd=100
CURRENT: R=0.00A L=1.31A dir=-1 spd=100
CURRENT: R=0.00A L=2.02A dir=-1 spd=100
CURRENT: R=0.00A L=1.36A dir=-1 spd=100
CURRENT: R=0.00A L=2.35A dir=-1 spd=100
CURRENT: R=0.00A L=1.24A dir=-1 spd=100
CURRENT: R=0.00A L=1.57A dir=-1 spd=100
CURRENT: R=0.00A L=2.64A dir=-1 spd=100
CURRENT: R=0.00A L=1.32A dir=-1 spd=100
CURRENT: R=0.00A L=2.52A dir=-1 spd=100
CURRENT: R=0.00A L=3.77A dir=-1 spd=100
CURRENT: R=0.00A L=21.04A dir=-1 spd=100
CURRENT: R=0.00A L=18.61A dir=-1 spd=100
CURRENT: R=0.00A L=19.38A dir=-1 spd=100
CURRENT: R=0.00A L=17.53A dir=-1 spd=100
CURRENT: R=0.00A L=17.53A dir=-1 spd=100
CURRENT: R=0.00A L=17.50A dir=-1 spd=100
CURRENT: R=0.00A L=17.41A dir=-1 spd=100
CURRENT: R=0.00A L=17.30A dir=-1 spd=100
CURRENT: R=0.00A L=17.28A dir=-1 spd=100
CURRENT: R=0.00A L=17.21A dir=-1 spd=100
CURRENT: R=0.00A L=17.17A dir=-1 spd=100
CURRENT: R=0.00A L=17.06A dir=-1 spd=100
CURRENT: R=0.00A L=16.99A dir=-1 spd=100
Motor: dir=1, speed=100%, pwm=255
CURRENT: R=0.00A L=0.00A dir=1 spd=100
CURRENT: R=1.77A L=0.00A dir=1 spd=100
CURRENT: R=1.36A L=0.00A dir=1 spd=100
CURRENT: R=2.19A L=0.00A dir=1 spd=100
CURRENT: R=2.10A L=0.00A dir=1 spd=100
CURRENT: R=1.18A L=0.00A dir=1 spd=100
CURRENT: R=1.36A L=0.00A dir=1 spd=100
CURRENT: R=1.24A L=0.00A dir=1 spd=100
CURRENT: R=1.50A L=0.00A dir=1 spd=100
CURRENT: R=1.45A L=0.00A dir=1 spd=100
CURRENT: R=2.01A L=0.00A dir=1 spd=100
CURRENT: R=1.64A L=0.00A dir=1 spd=100
CURRENT: R=2.10A L=0.00A dir=1 spd=100
CURRENT: R=1.31A L=0.00A dir=1 spd=100
CURRENT: R=2.34A L=0.00A dir=1 spd=100
CURRENT: R=1.90A L=0.00A dir=1 spd=100
CURRENT: R=1.46A L=0.00A dir=1 spd=100
CURRENT: R=1.60A L=0.00A dir=1 spd=100
CURRENT: R=2.27A L=0.00A dir=1 spd=100
CURRENT: R=1.96A L=0.00A dir=1 spd=100
CURRENT: R=3.08A L=0.00A dir=1 spd=100
CURRENT: R=15.12A L=0.00A dir=1 spd=100
CURRENT: R=18.53A L=0.00A dir=1 spd=100
CURRENT: R=20.75A L=0.00A dir=1 spd=100
CURRENT: R=19.59A L=0.00A dir=1 spd=100
CURRENT: R=18.54A L=0.00A dir=1 spd=100
CURRENT: R=17.88A L=0.00A dir=1 spd=100
CURRENT: R=17.35A L=0.00A dir=1 spd=100
CURRENT: R=17.06A L=0.00A dir=1 spd=100
CURRENT: R=16.99A L=0.00A dir=1 spd=100
CURRENT: R=16.85A L=0.00A dir=1 spd=100
CURRENT: R=16.90A L=0.00A dir=1 spd=100
CURRENT: R=16.84A L=0.00A dir=1 spd=100
CURRENT: R=16.81A L=0.00A dir=1 spd=100
Motor: dir=-1, speed=100%, pwm=255
CURRENT: R=0.00A L=5.35A dir=-1 spd=100
CURRENT: R=0.00A L=0.46A dir=-1 spd=100
CURRENT: R=0.00A L=2.29A dir=-1 spd=100
CURRENT: R=0.00A L=0.86A dir=-1 spd=100
CURRENT: R=0.00A L=2.22A dir=-1 spd=100
CURRENT: R=0.00A L=1.90A dir=-1 spd=100
CURRENT: R=0.00A L=1.00A dir=-1 spd=100
CURRENT: R=0.00A L=1.33A dir=-1 spd=100
CURRENT: R=0.00A L=1.42A dir=-1 spd=100
CURRENT: R=0.00A L=1.27A dir=-1 spd=100
CURRENT: R=0.00A L=1.25A dir=-1 spd=100
CURRENT: R=0.00A L=2.21A dir=-1 spd=100
CURRENT: R=0.00A L=0.67A dir=-1 spd=100
CURRENT: R=0.00A L=0.85A dir=-1 spd=100
Motor: STOPPED (manual)
CURRENT: R=0.00A L=0.00A dir=0 spd=100
CURRENT: R=0.00A L=0.00A dir=0 spd=100
CURRENT: R=0.00A L=0.00A dir=0 spd=100
CURRENT: R=0.00A L=0.00A dir=0 spd=100
CURRENT: R=0.00A L=0.00A dir=0 spd=100
CURRENT: R=0.00A L=0.00A dir=0 spd=100
CURRENT: R=0.00A L=0.00A dir=0 spd=100
CURRENT: R=0.00A L=0.00A dir=0 spd=100
CURRENT: R=0.00A L=0.00A dir=0 spd=100
CURRENT: R=0.00A L=0.00A dir=0 spd=100
CURRENT: R=0.00A L=0.00A dir=0 spd=100
CURRENT: R=0.00A L=0.00A dir=0 spd=100