- 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
51 lines
2.0 KiB
C
51 lines
2.0 KiB
C
#ifndef CONFIG_H
|
|
#define CONFIG_H
|
|
|
|
// WiFi Configuration
|
|
#define WIFI_SSID "tami"
|
|
#define WIFI_PASSWORD ""
|
|
|
|
// Static IP Configuration
|
|
#define STATIC_IP IPAddress(10, 81, 2, 185)
|
|
#define GATEWAY IPAddress(10, 81, 2, 1)
|
|
#define SUBNET IPAddress(255, 255, 255, 0)
|
|
#define DNS IPAddress(10, 81, 2, 1)
|
|
|
|
// BTS7960 Pin Definitions
|
|
#define RPWM_PIN 25 // Right PWM (Forward)
|
|
#define LPWM_PIN 26 // Left PWM (Reverse)
|
|
#define R_EN_PIN 27 // Right Enable
|
|
#define L_EN_PIN 14 // Left Enable
|
|
#define R_IS_PIN 34 // Right Current Sense (ADC input only)
|
|
#define L_IS_PIN 35 // Left Current Sense (ADC input only)
|
|
|
|
// PWM Configuration
|
|
#define PWM_FREQ 20000 // 20kHz - reduces motor noise
|
|
#define PWM_RESOLUTION 8 // 8-bit resolution (0-255)
|
|
#define PWM_CHANNEL_R 0 // LEDC channel for RPWM
|
|
#define PWM_CHANNEL_L 1 // LEDC channel for LPWM
|
|
#define MIN_PWM_PERCENT 20 // Minimum PWM when motor is running (%)
|
|
|
|
// Current Sense Configuration
|
|
// BTS7960 current sense ratio: 8500:1 (kilo-amps)
|
|
// With 1kΩ resistor on IS pin: V = I_motor / 8500
|
|
// ESP32 ADC: 12-bit (0-4095), 0-3.3V
|
|
#define CURRENT_SENSE_RATIO 8500.0f // Amps to sense current ratio
|
|
#define SENSE_RESISTOR 1000.0f // 1kΩ sense resistor (ohms)
|
|
#define ADC_MAX 4095.0f // 12-bit ADC max value
|
|
#define ADC_VREF 3.3f // ADC reference voltage
|
|
#define CURRENT_CALIBRATION 0.33f // Calibration factor (measured current / reported current)
|
|
|
|
// Stall Detection Configuration (delta-based)
|
|
// Detects sudden current spikes above the rolling average
|
|
#define STALL_DELTA_THRESHOLD 2.0f // 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_STABILIZE_MS 500 // Ignore stalls for this long after motor starts/changes
|
|
#define STALL_CONFIRM_MS 100 // Current must exceed threshold for this long to confirm stall
|
|
#define DISABLE_STALL_DETECT false // Set to true to disable stall detection
|
|
|
|
// Web Server
|
|
#define HTTP_PORT 80
|
|
|
|
#endif
|