fixed web-control path and watchdog stoping
This commit is contained in:
parent
f75c654a39
commit
4b040391da
|
|
@ -9,7 +9,7 @@ SERIAL_PORT = "/dev/serial/by-id/usb-1a86_USB2.0-Serial-if00-port0" # ggf. /de
|
|||
BAUD = 115200
|
||||
|
||||
# Safety: if websocket stops sending, we also stop.
|
||||
STOP_AFTER_SEC = 0.35
|
||||
STOP_AFTER_SEC = 0.5
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
|
|
@ -30,11 +30,14 @@ def send_lr(l: int, r: int):
|
|||
def health():
|
||||
return {"ok": True, "serial": SERIAL_PORT}
|
||||
|
||||
@app.websocket("/drive-ws")
|
||||
@app.websocket("/ws")
|
||||
async def ws(websocket: WebSocket):
|
||||
global last_msg_ts
|
||||
await websocket.accept()
|
||||
|
||||
last_msg_ts = time.time()
|
||||
send_lr(0, 0)
|
||||
|
||||
async def watchdog():
|
||||
while True:
|
||||
await asyncio.sleep(0.05)
|
||||
|
|
|
|||
|
|
@ -265,7 +265,22 @@
|
|||
lastL = L; lastR = R;
|
||||
readoutEl.textContent = `T ${throttle.toFixed(2)} | Turn ${turn.toFixed(2)} → L ${L} | R ${R}`;
|
||||
|
||||
sendLR(L, R, force);
|
||||
// sendLR(L, R, force);
|
||||
|
||||
// ---- Heartbeat: keep sending current values while driving ----
|
||||
setInterval(() => {
|
||||
// wenn nicht verbunden -> nix
|
||||
if (!connected) return;
|
||||
|
||||
// Wenn du NUR beim aktiven Fahren senden willst:
|
||||
const driving = (Math.abs(throttle) > 0.02) || (Math.abs(turn) > 0.02);
|
||||
|
||||
if (driving) {
|
||||
// erzwinge Senden auch wenn sich nichts geändert hat
|
||||
sendLR(lastL, lastR, true);
|
||||
}
|
||||
}, 400); // 40 Hz
|
||||
|
||||
}
|
||||
|
||||
function hardStop() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue