Compare commits

..

2 Commits

Author SHA1 Message Date
Helva 4b040391da fixed web-control path and watchdog stoping 2026-02-08 14:04:31 +01:00
Helva f75c654a39 remote control problem 2026-02-08 13:23:02 +01:00
6 changed files with 52 additions and 7 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
drive/opt/drive-ctl/__pycache__/

View File

@ -192,12 +192,26 @@ For Web-UI-Controller you need to have access to the raspberry-pi i.e. via a hot
sudo apt install -y python3-venv sudo apt install -y python3-venv
python3 -m venv /opt/drive-ctl-venv python3 -m venv /opt/drive-ctl-venv
sudo chown -R $USER:$USER /opt/drive-ctl-venv
/opt/drive-ctl-venv/bin/pip install fastapi uvicorn pyserial /opt/drive-ctl-venv/bin/pip install fastapi uvicorn pyserial
source /opt/drive-ctl-venv/bin/activate source /opt/drive-ctl-venv/bin/activate
pip install fastapi uvicorn pyserial pip install fastapi uvicorn pyserial
Configure Arduino-USB-ID
ls -l /dev/serial/by-id/ 2>/dev/null
Example Output
usb-1a86_USB2.0-Serial-if00-port0 -> ../../ttyUSB0
Watch USB devices while replugging
dmesg -T | tail -n 80
Configure the USB-Device-ID in /opt/helva-robot/drive/opt/drive-ctl/server.py
### Activate Web Control Interface ### Activate Web Control Interface
@ -223,4 +237,14 @@ Check Serial device is stable, otherwise create a udev rule
http://pi-ip/drive/ http://pi-ip/drive/
### Debug drive-ctl WebUI
check local webservice
curl -s http://127.0.0.1:8002/health
should be -> {"ok": true, ... } -> otherwise look at the logs:
journalctl -u drive-ctl -n 80 --no-pager

View File

@ -1,15 +1,16 @@
location /drive/ { location ^~ /drive/ {
alias /opt/helva-robot/drive/var/www/drive/; alias /opt/helva-robot/drive/var/www/drive/;
try_files $uri $uri/ /drive/index.html; try_files $uri $uri/ /drive/index.html;
} }
location /drive-ws { location = /drive-ws {
proxy_pass http://127.0.0.1:8002/ws; proxy_pass http://127.0.0.1:8002/ws;
proxy_http_version 1.1; proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade; proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade"; proxy_set_header Connection "Upgrade";
proxy_set_header Host $host; proxy_set_header Host $host;
proxy_read_timeout 3600;
} }
location /drive-health { location /drive-health {

View File

@ -5,11 +5,11 @@ import serial
from fastapi import FastAPI, WebSocket, WebSocketDisconnect from fastapi import FastAPI, WebSocket, WebSocketDisconnect
from fastapi.responses import HTMLResponse from fastapi.responses import HTMLResponse
SERIAL_PORT = "/dev/ttyACM0" # ggf. /dev/ttyUSB0 SERIAL_PORT = "/dev/serial/by-id/usb-1a86_USB2.0-Serial-if00-port0" # ggf. /dev/ttyUSB0
BAUD = 115200 BAUD = 115200
# Safety: if websocket stops sending, we also stop. # Safety: if websocket stops sending, we also stop.
STOP_AFTER_SEC = 0.35 STOP_AFTER_SEC = 0.5
app = FastAPI() app = FastAPI()
@ -35,6 +35,9 @@ async def ws(websocket: WebSocket):
global last_msg_ts global last_msg_ts
await websocket.accept() await websocket.accept()
last_msg_ts = time.time()
send_lr(0, 0)
async def watchdog(): async def watchdog():
while True: while True:
await asyncio.sleep(0.05) await asyncio.sleep(0.05)

View File

@ -265,7 +265,22 @@
lastL = L; lastR = R; lastL = L; lastR = R;
readoutEl.textContent = `T ${throttle.toFixed(2)} | Turn ${turn.toFixed(2)} → L ${L} | R ${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() { function hardStop() {

View File

@ -2,6 +2,8 @@ server {
listen 80; listen 80;
server_name _; server_name _;
include /opt/helva-robot/drive/etc/nginx/snippets/drive.conf;
root /opt/helva-robot/face/var/www/html; root /opt/helva-robot/face/var/www/html;
index index.html; index index.html;
@ -31,6 +33,5 @@ server {
add_header Cache-Control no-cache; add_header Cache-Control no-cache;
} }
include /opt/helva-robot/drive/etc/nginx/snippets/drive.conf;
} }