Update stall detection params and expand documentation

- Adjust stall current threshold to 4A and detection time to 2500ms
- Add comprehensive README with hardware specs, wiring diagrams
- Include current sensing circuit documentation and math
- Improve motor and webserver implementations
This commit is contained in:
devdesk
2026-02-05 16:59:47 +02:00
parent 6ccbc7faf5
commit e2fe9aa495
5 changed files with 203 additions and 25 deletions

View File

@@ -33,6 +33,12 @@ void setupWiFi() {
}
}
// Stall protection callback - stops motor immediately when stall detected
void onMotorStall(float current) {
Serial.printf("STALL PROTECTION: Stopping motor (current: %.2fA)\n", current);
motor.stop();
}
void setup() {
Serial.begin(115200);
delay(1000);
@@ -44,6 +50,9 @@ void setup() {
// Initialize motor controller
motor.begin();
// Register stall protection callback
motor.setStallCallback(onMotorStall);
// Connect to WiFi
setupWiFi();

View File

@@ -1,7 +1,7 @@
#include "motor.h"
// Set to true to enable current sensing (requires R_IS and L_IS connected)
#define CURRENT_SENSING_ENABLED false
#define CURRENT_SENSING_ENABLED true
MotorController motor;
@@ -62,10 +62,19 @@ void MotorController::stop() {
void MotorController::update() {
#if CURRENT_SENSING_ENABLED
static unsigned long lastPrintTime = 0;
// Read current sensors
_currentRight = readCurrentSense(R_IS_PIN);
_currentLeft = readCurrentSense(L_IS_PIN);
// Log current readings every 500ms when motor is running
if ((_direction != 0 || _speed != 0) && (millis() - lastPrintTime > 500)) {
lastPrintTime = millis();
Serial.printf("Current: R=%.2fA L=%.2fA Active=%.2fA (threshold=%.1fA)\n",
_currentRight, _currentLeft, getCurrentActive(), STALL_CURRENT_THRESHOLD);
}
// Check for stall condition
checkStall();
#endif

View File

@@ -28,17 +28,44 @@ const char index_html[] PROGMEM = R"rawliteral(
text-align: center;
}
h1 { color: #00d9ff; margin-bottom: 30px; }
.status {
background: #16213e;
padding: 15px;
border-radius: 10px;
.status {
background: #16213e;
padding: 15px;
border-radius: 10px;
margin-bottom: 20px;
}
.status span {
font-size: 24px;
font-weight: bold;
.status span {
font-size: 24px;
font-weight: bold;
color: #00d9ff;
}
.current-display {
background: #16213e;
padding: 15px;
border-radius: 10px;
margin-bottom: 20px;
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
}
.current-value {
font-size: 28px;
font-weight: bold;
color: #00d9ff;
}
.current-label {
font-size: 12px;
color: #888;
}
.stall-warning {
background: #ff5252;
color: white;
padding: 10px;
border-radius: 5px;
margin-bottom: 20px;
display: none;
}
.stall-warning.active { display: block; }
.slider-container {
background: #16213e;
padding: 20px;
@@ -92,6 +119,21 @@ const char index_html[] PROGMEM = R"rawliteral(
<div class="container">
<h1>Motor Control</h1>
<div class="stall-warning" id="stallWarning">
STALL DETECTED - Motor Stopped
</div>
<div class="current-display">
<div>
<div class="current-label">CURRENT (Active)</div>
<div class="current-value"><span id="currentActive">0.00</span>A</div>
</div>
<div>
<div class="current-label">THRESHOLD</div>
<div class="current-value" style="color:#ff9100;">4.0A</div>
</div>
</div>
<div class="status">
Direction: <span id="dirStatus">STOPPED</span>
</div>
@@ -147,15 +189,33 @@ const char index_html[] PROGMEM = R"rawliteral(
else dirStatus.textContent = 'STOPPED';
}
// Get initial state
fetch('/status')
.then(r => r.json())
.then(data => {
slider.value = data.speed;
speedVal.textContent = data.speed;
currentDir = data.direction;
updateStatus();
});
function pollStatus() {
fetch('/status')
.then(r => r.json())
.then(data => {
slider.value = data.speed;
speedVal.textContent = data.speed;
currentDir = data.direction;
updateStatus();
// Update current display
const active = data.direction > 0 ? data.currentR :
data.direction < 0 ? data.currentL : 0;
document.getElementById('currentActive').textContent = active.toFixed(2);
// Show/hide stall warning
const stallWarning = document.getElementById('stallWarning');
if (data.stalled) {
stallWarning.classList.add('active');
} else {
stallWarning.classList.remove('active');
}
});
}
// Poll status every 500ms
pollStatus();
setInterval(pollStatus, 500);
</script>
</body>
</html>