diff --git a/readme.md b/readme.md index 6844a50..ddee4e7 100644 --- a/readme.md +++ b/readme.md @@ -2,6 +2,15 @@ ESP32-based DC motor controller with web interface, using BTS7960 dual H-bridge driver with current sensing and stall protection. +## Features + +- Web-based control panel with real-time current monitoring +- Forward/Reverse/Stop motor control with speed slider (20-100%) +- Current sensing on both H-bridge sides (R_IS and L_IS) +- Sample-based stall detection with automatic motor shutoff +- ADC offset calibration at startup for accurate current readings +- Stall warning displayed on web interface + ## Hardware ### Components @@ -77,9 +86,12 @@ Key settings in [`include/config.h`](include/config.h): | Setting | Default | Description | |---------|---------|-------------| -| `STALL_CURRENT_THRESHOLD` | 4.0A | Current triggering stall detection | -| `STALL_DETECT_TIME_MS` | 500ms | Duration before stall confirmed | +| `STALL_THRESHOLD` | 8.0A | Current threshold for stall detection | +| `STALL_CONFIRM_SAMPLES` | 3 | Number of consecutive samples to confirm stall (~300ms) | +| `STALL_STABILIZE_MS` | 500ms | Ignore current spikes after direction change | | `PWM_FREQ` | 20kHz | PWM frequency (reduces motor noise) | +| `MIN_PWM_PERCENT` | 20% | Minimum PWM when motor is running | +| `CURRENT_LOG_INTERVAL_MS` | 100ms | Current sampling/logging interval | | `CURRENT_SENSING_ENABLED` | true | Enable/disable in [`src/motor.cpp`](src/motor.cpp) | ## Network @@ -98,11 +110,38 @@ pio run -t upload # Build and upload pio device monitor # Serial monitor (115200 baud) ``` +## Web Interface + +Access the control panel at `http://10.81.2.185` (or the IP shown on serial monitor). + +### Features + +- **Current Display**: Real-time left (L) and right (R) current readings in amps +- **Direction Status**: Shows FORWARD, REVERSE, or STOPPED +- **Speed Slider**: Adjustable from 20% to 100% (minimum PWM prevents motor stalling at low speeds) +- **Stall Warning**: Red banner appears when stall is detected + +### API Endpoints + +| Endpoint | Method | Parameters | Description | +|----------|--------|------------|-------------| +| `/` | GET | - | Control panel HTML page | +| `/status` | GET | - | JSON: `{speed, direction, currentR, currentL, stalled}` | +| `/speed` | POST | `value` (0-100) | Set motor speed percentage | +| `/direction` | POST | `value` (-1, 0, 1) | Set direction (reverse/stop/forward) | +| `/stop` | POST | - | Emergency stop | + ## Stall Protection -When motor current exceeds 4.0A for 500ms continuously: -1. Stall is detected -2. Motor stops immediately -3. Serial log: `STALL PROTECTION: Stopping motor (current: X.XXA)` +The stall detection uses a sample-based approach for reliability: -To resume operation, send a new speed/direction command via the web interface. +1. **Threshold**: Current above 8.0A indicates potential stall (based on observed ~2A running vs ~17A stalled) +2. **Debounce**: 3 consecutive samples above threshold confirms stall (~300ms at 100ms intervals) +3. **Stabilization**: Ignores current spikes for 500ms after direction changes + +When stall is confirmed: +1. Motor stops immediately +2. Serial log: `STALL PROTECTION: Stopping motor (current: X.XXA)` +3. Web interface shows red "STALL DETECTED" warning + +To resume operation, send a new direction command via the web interface.