bench mode, ClearPilot menu, status window, UI introspection RPC
Bench mode (--bench flag): - bench_onroad.py publishes fake vehicle state as managed process - manager blocks real car processes (pandad, thermald, controlsd, etc.) - bench_cmd.py for setting params and querying UI state - BLOCKER: UI segfaults (SIGSEGV) when OnroadWindow becomes visible without camera frames — need to make CameraWidget handle missing VisionIPC gracefully before bench drive mode works ClearPilot menu: - Replaced grid launcher with sidebar settings panel (ClearPilotPanel) - Sidebar: Home, Dashcam, Debug - Home panel: Status and System Settings buttons - Debug panel: telemetry logging toggle (ParamControl) - Tap from any view (splash, onroad) opens ClearPilotPanel - Back button returns to splash/onroad Status window: - Live system stats refreshing every 1 second - Storage, RAM, load, IP, WiFi, VPN, GPS, time, telemetry status - Tap anywhere to close, returns to previous view - Honors interactive timeout UI introspection RPC: - ZMQ REP server at ipc:///tmp/clearpilot_ui_rpc - Dumps full widget tree with visibility, geometry, stacked indices - bench_cmd dump queries it, detects crash loops via process uptime - ui_dump.py standalone tool Other: - Telemetry toggle wired to TelemetryEnabled param with disk space guard - Telemetry disabled on every manager start - Blinking red circle on onroad UI when telemetry recording - Fixed showDriverView overriding park/drive transitions every frame - Fixed offroadTransition sidebar visibility race in MainWindow - launch_openpilot.sh: cd to /data/openpilot, --bench flag support Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
122
selfdrive/clearpilot/bench_cmd.py
Normal file
122
selfdrive/clearpilot/bench_cmd.py
Normal file
@@ -0,0 +1,122 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
ClearPilot bench command tool. Sets bench params and queries UI state.
|
||||
|
||||
Usage:
|
||||
python3 -m selfdrive.clearpilot.bench_cmd gear D
|
||||
python3 -m selfdrive.clearpilot.bench_cmd speed 20
|
||||
python3 -m selfdrive.clearpilot.bench_cmd speedlimit 45
|
||||
python3 -m selfdrive.clearpilot.bench_cmd cruise 55
|
||||
python3 -m selfdrive.clearpilot.bench_cmd engaged 1
|
||||
python3 -m selfdrive.clearpilot.bench_cmd dump
|
||||
python3 -m selfdrive.clearpilot.bench_cmd wait_ready
|
||||
"""
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
import zmq
|
||||
from openpilot.common.params import Params
|
||||
|
||||
|
||||
def check_ui_process():
|
||||
"""Check if UI process is running and healthy. Returns error string or None if OK."""
|
||||
try:
|
||||
result = subprocess.run(["pgrep", "-a", "-f", "./ui"], capture_output=True, text=True)
|
||||
if result.returncode != 0:
|
||||
return "ERROR: UI process not running"
|
||||
# Get the PID and check its uptime
|
||||
for line in result.stdout.strip().split("\n"):
|
||||
parts = line.split(None, 1)
|
||||
if len(parts) >= 2 and "./ui" in parts[1]:
|
||||
pid = parts[0]
|
||||
try:
|
||||
stat = os.stat(f"/proc/{pid}")
|
||||
uptime = time.time() - stat.st_mtime
|
||||
if uptime < 5:
|
||||
return f"ERROR: UI process (pid {pid}) uptime {uptime:.1f}s — likely crash looping. Check: tail /data/log2/$(ls -t /data/log2/ | head -1)/session.log"
|
||||
except FileNotFoundError:
|
||||
return "ERROR: UI process disappeared"
|
||||
except Exception:
|
||||
pass
|
||||
return None
|
||||
|
||||
|
||||
def ui_dump():
|
||||
ctx = zmq.Context()
|
||||
sock = ctx.socket(zmq.REQ)
|
||||
sock.setsockopt(zmq.RCVTIMEO, 2000)
|
||||
sock.connect("ipc:///tmp/clearpilot_ui_rpc")
|
||||
sock.send_string("dump")
|
||||
try:
|
||||
return sock.recv_string()
|
||||
except zmq.Again:
|
||||
return None
|
||||
finally:
|
||||
sock.close()
|
||||
ctx.term()
|
||||
|
||||
|
||||
def wait_ready(timeout=10):
|
||||
"""Wait until the UI shows ReadyWindow, up to timeout seconds."""
|
||||
start = time.time()
|
||||
while time.time() - start < timeout:
|
||||
dump = ui_dump()
|
||||
if dump and "ReadyWindow" in dump:
|
||||
# Check it's actually visible
|
||||
for line in dump.split("\n"):
|
||||
if "ReadyWindow" in line and "vis=Y" in line:
|
||||
print("UI ready (ReadyWindow visible)")
|
||||
return True
|
||||
time.sleep(1)
|
||||
print(f"ERROR: UI not ready after {timeout}s")
|
||||
if dump:
|
||||
print(dump)
|
||||
return False
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2:
|
||||
print(__doc__)
|
||||
return
|
||||
|
||||
cmd = sys.argv[1].lower()
|
||||
params = Params("/dev/shm/params")
|
||||
|
||||
param_map = {
|
||||
"gear": "BenchGear",
|
||||
"speed": "BenchSpeed",
|
||||
"speedlimit": "BenchSpeedLimit",
|
||||
"cruise": "BenchCruiseSpeed",
|
||||
"engaged": "BenchEngaged",
|
||||
}
|
||||
|
||||
if cmd == "dump":
|
||||
ui_status = check_ui_process()
|
||||
if ui_status:
|
||||
print(ui_status)
|
||||
else:
|
||||
result = ui_dump()
|
||||
if result:
|
||||
print(result)
|
||||
else:
|
||||
print("ERROR: UI not responding")
|
||||
|
||||
elif cmd == "wait_ready":
|
||||
wait_ready()
|
||||
|
||||
elif cmd in param_map:
|
||||
if len(sys.argv) < 3:
|
||||
print(f"Usage: bench_cmd {cmd} <value>")
|
||||
return
|
||||
value = sys.argv[2]
|
||||
params.put(param_map[cmd], value)
|
||||
print(f"{param_map[cmd]} = {value}")
|
||||
|
||||
else:
|
||||
print(f"Unknown command: {cmd}")
|
||||
print(__doc__)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
129
selfdrive/clearpilot/bench_onroad.py
Normal file
129
selfdrive/clearpilot/bench_onroad.py
Normal file
@@ -0,0 +1,129 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
ClearPilot bench onroad simulator.
|
||||
|
||||
Publishes fake messages to make the UI go onroad and display
|
||||
configurable vehicle state. Control values via params in /dev/shm/params:
|
||||
|
||||
BenchSpeed - vehicle speed in mph (default: 0)
|
||||
BenchSpeedLimit - speed limit in mph (default: 0, 0=hidden)
|
||||
BenchCruiseSpeed - cruise set speed in mph (default: 0, 0=not set)
|
||||
BenchGear - P, D, R, N (default: P)
|
||||
BenchEngaged - 0 or 1, cruise engaged (default: 0)
|
||||
|
||||
Usage:
|
||||
su - comma -c "PYTHONPATH=/data/openpilot python3 -m selfdrive.clearpilot.bench_onroad"
|
||||
|
||||
To stop: Ctrl+C or kill the process. UI returns to offroad.
|
||||
"""
|
||||
import time
|
||||
|
||||
import cereal.messaging as messaging
|
||||
from cereal import log, car
|
||||
from openpilot.common.params import Params
|
||||
|
||||
MS_PER_MPH = 0.44704
|
||||
|
||||
|
||||
def main():
|
||||
params = Params()
|
||||
params_mem = Params("/dev/shm/params")
|
||||
|
||||
# Set defaults
|
||||
params_mem.put("BenchSpeed", "0")
|
||||
params_mem.put("BenchSpeedLimit", "0")
|
||||
params_mem.put("BenchCruiseSpeed", "0")
|
||||
params_mem.put("BenchGear", "P")
|
||||
params_mem.put("BenchEngaged", "0")
|
||||
|
||||
pm = messaging.PubMaster([
|
||||
"deviceState", "pandaStates", "carState", "controlsState",
|
||||
"driverMonitoringState", "liveCalibration",
|
||||
])
|
||||
|
||||
print("Bench onroad simulator started")
|
||||
print("Set values in /dev/shm/params/d/Bench*")
|
||||
print(" BenchSpeed=0 BenchSpeedLimit=0 BenchCruiseSpeed=0 BenchGear=P BenchEngaged=0")
|
||||
|
||||
gear_map = {
|
||||
"P": car.CarState.GearShifter.park,
|
||||
"D": car.CarState.GearShifter.drive,
|
||||
"R": car.CarState.GearShifter.reverse,
|
||||
"N": car.CarState.GearShifter.neutral,
|
||||
}
|
||||
|
||||
frame = 0
|
||||
try:
|
||||
while True:
|
||||
# Read bench params
|
||||
speed_mph = float((params_mem.get("BenchSpeed", encoding="utf-8") or "0").strip())
|
||||
speed_limit_mph = float((params_mem.get("BenchSpeedLimit", encoding="utf-8") or "0").strip())
|
||||
cruise_mph = float((params_mem.get("BenchCruiseSpeed", encoding="utf-8") or "0").strip())
|
||||
gear_str = (params_mem.get("BenchGear", encoding="utf-8") or "P").strip().upper()
|
||||
engaged = (params_mem.get("BenchEngaged", encoding="utf-8") or "0").strip() == "1"
|
||||
|
||||
speed_ms = speed_mph * MS_PER_MPH
|
||||
gear = gear_map.get(gear_str, car.CarState.GearShifter.park)
|
||||
|
||||
# deviceState — 2 Hz
|
||||
if frame % 5 == 0:
|
||||
dat = messaging.new_message("deviceState")
|
||||
dat.deviceState.started = True
|
||||
dat.deviceState.freeSpacePercent = 80
|
||||
dat.deviceState.memoryUsagePercent = 30
|
||||
dat.deviceState.cpuTempC = [40.0] * 3
|
||||
dat.deviceState.gpuTempC = [40.0] * 3
|
||||
dat.deviceState.cpuUsagePercent = [20] * 8
|
||||
dat.deviceState.networkType = log.DeviceState.NetworkType.cell4G
|
||||
pm.send("deviceState", dat)
|
||||
|
||||
# pandaStates — 10 Hz
|
||||
if frame % 1 == 0:
|
||||
dat = messaging.new_message("pandaStates", 1)
|
||||
dat.pandaStates[0].ignitionLine = True
|
||||
dat.pandaStates[0].pandaType = log.PandaState.PandaType.tres
|
||||
pm.send("pandaStates", dat)
|
||||
|
||||
# carState — 10 Hz
|
||||
dat = messaging.new_message("carState")
|
||||
cs = dat.carState
|
||||
cs.vEgo = speed_ms
|
||||
cs.vEgoCluster = speed_ms
|
||||
cs.gearShifter = gear
|
||||
cs.standstill = speed_ms < 0.1
|
||||
cs.cruiseState.available = True
|
||||
cs.cruiseState.enabled = engaged
|
||||
cs.cruiseState.speed = cruise_mph * MS_PER_MPH if cruise_mph > 0 else 0
|
||||
pm.send("carState", dat)
|
||||
|
||||
# controlsState — 10 Hz
|
||||
dat = messaging.new_message("controlsState")
|
||||
ctl = dat.controlsState
|
||||
ctl.vCruise = cruise_mph * 1.60934 if cruise_mph > 0 else 255 # km/h or 255=not set
|
||||
ctl.vCruiseCluster = ctl.vCruise
|
||||
ctl.enabled = engaged
|
||||
ctl.active = engaged
|
||||
pm.send("controlsState", dat)
|
||||
|
||||
# driverMonitoringState — low freq
|
||||
if frame % 10 == 0:
|
||||
dat = messaging.new_message("driverMonitoringState")
|
||||
dat.driverMonitoringState.isActiveMode = True
|
||||
pm.send("driverMonitoringState", dat)
|
||||
|
||||
# liveCalibration — low freq
|
||||
if frame % 50 == 0:
|
||||
dat = messaging.new_message("liveCalibration")
|
||||
dat.liveCalibration.calStatus = log.LiveCalibrationData.Status.calibrated
|
||||
dat.liveCalibration.rpyCalib = [0.0, 0.0, 0.0]
|
||||
pm.send("liveCalibration", dat)
|
||||
|
||||
frame += 1
|
||||
time.sleep(0.1) # 10 Hz base loop
|
||||
|
||||
except KeyboardInterrupt:
|
||||
print("\nBench simulator stopped")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -5,18 +5,28 @@ ClearPilot telemetry collector.
|
||||
Receives telemetry packets from any process via ZMQ, diffs against previous
|
||||
state per group, and writes only changed values to CSV.
|
||||
|
||||
Controlled by TelemetryEnabled param — when toggled on, the first packet
|
||||
from each group writes all values (full dump). When toggled off, stops writing.
|
||||
|
||||
CSV format: timestamp,group,key,value
|
||||
"""
|
||||
import csv
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import time
|
||||
import zmq
|
||||
|
||||
from openpilot.common.params import Params
|
||||
from openpilot.selfdrive.clearpilot.telemetry import TELEMETRY_SOCK
|
||||
from openpilot.selfdrive.manager.process import _log_dir
|
||||
from openpilot.selfdrive.manager.process import _log_dir, session_log
|
||||
|
||||
MIN_DISK_FREE_GB = 5
|
||||
DISK_CHECK_INTERVAL = 10 # seconds
|
||||
|
||||
|
||||
def main():
|
||||
params = Params()
|
||||
ctx = zmq.Context.instance()
|
||||
sock = ctx.socket(zmq.PULL)
|
||||
sock.setsockopt(zmq.RCVHWM, 1000)
|
||||
@@ -24,43 +34,80 @@ def main():
|
||||
|
||||
csv_path = os.path.join(_log_dir, "telemetry.csv")
|
||||
state: dict[str, dict] = {} # group -> {key: last_value}
|
||||
was_enabled = False
|
||||
writer = None
|
||||
f = None
|
||||
last_disk_check = 0
|
||||
|
||||
with open(csv_path, "w", newline="") as f:
|
||||
writer = csv.writer(f)
|
||||
writer.writerow(["timestamp", "group", "key", "value"])
|
||||
f.flush()
|
||||
while True:
|
||||
# Check enable state every iteration (cheap param read)
|
||||
enabled = params.get("TelemetryEnabled") == b"1"
|
||||
|
||||
while True:
|
||||
try:
|
||||
raw = sock.recv_string()
|
||||
except zmq.ZMQError:
|
||||
continue
|
||||
# Check disk space every 10 seconds while enabled
|
||||
if enabled and (time.monotonic() - last_disk_check) > DISK_CHECK_INTERVAL:
|
||||
last_disk_check = time.monotonic()
|
||||
disk = shutil.disk_usage("/data")
|
||||
free_gb = disk.free / (1024 ** 3)
|
||||
if free_gb < MIN_DISK_FREE_GB:
|
||||
session_log.warning("telemetry disabled: disk free %.1f GB < %d GB", free_gb, MIN_DISK_FREE_GB)
|
||||
params.put("TelemetryEnabled", "0")
|
||||
enabled = False
|
||||
|
||||
try:
|
||||
pkt = json.loads(raw)
|
||||
except json.JSONDecodeError:
|
||||
continue
|
||||
# Toggled on: open CSV, clear state so first packet is a full dump
|
||||
if enabled and not was_enabled:
|
||||
f = open(csv_path, "a", newline="")
|
||||
writer = csv.writer(f)
|
||||
if os.path.getsize(csv_path) == 0:
|
||||
writer.writerow(["timestamp", "group", "key", "value"])
|
||||
state.clear() # force full dump on first packet per group
|
||||
f.flush()
|
||||
|
||||
ts = pkt.get("ts", 0)
|
||||
group = pkt.get("group", "")
|
||||
data = pkt.get("data", {})
|
||||
# Toggled off: close file
|
||||
if not enabled and was_enabled:
|
||||
if f:
|
||||
f.close()
|
||||
f = None
|
||||
writer = None
|
||||
|
||||
if group not in state:
|
||||
state[group] = {}
|
||||
was_enabled = enabled
|
||||
|
||||
prev = state[group]
|
||||
changed = False
|
||||
# Always drain the socket (even when disabled) to avoid backpressure
|
||||
try:
|
||||
raw = sock.recv_string(zmq.NOBLOCK)
|
||||
except zmq.Again:
|
||||
time.sleep(0.01)
|
||||
continue
|
||||
except zmq.ZMQError:
|
||||
time.sleep(0.01)
|
||||
continue
|
||||
|
||||
for key, value in data.items():
|
||||
# Convert to string for comparison so floats/ints/bools all diff correctly
|
||||
str_val = str(value)
|
||||
if key not in prev or prev[key] != str_val:
|
||||
writer.writerow([f"{ts:.6f}", group, key, str_val])
|
||||
prev[key] = str_val
|
||||
changed = True
|
||||
if not enabled or writer is None:
|
||||
continue
|
||||
|
||||
if changed:
|
||||
f.flush()
|
||||
try:
|
||||
pkt = json.loads(raw)
|
||||
except json.JSONDecodeError:
|
||||
continue
|
||||
|
||||
ts = pkt.get("ts", 0)
|
||||
group = pkt.get("group", "")
|
||||
data = pkt.get("data", {})
|
||||
|
||||
if group not in state:
|
||||
state[group] = {}
|
||||
|
||||
prev = state[group]
|
||||
changed = False
|
||||
|
||||
for key, value in data.items():
|
||||
str_val = str(value)
|
||||
if key not in prev or prev[key] != str_val:
|
||||
writer.writerow([f"{ts:.6f}", group, key, str_val])
|
||||
prev[key] = str_val
|
||||
changed = True
|
||||
|
||||
if changed:
|
||||
f.flush()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
12
selfdrive/clearpilot/ui_dump.py
Normal file
12
selfdrive/clearpilot/ui_dump.py
Normal file
@@ -0,0 +1,12 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Query the UI process for its current widget tree. Usage: python3 -m selfdrive.clearpilot.ui_dump"""
|
||||
import zmq
|
||||
ctx = zmq.Context()
|
||||
sock = ctx.socket(zmq.REQ)
|
||||
sock.setsockopt(zmq.RCVTIMEO, 2000)
|
||||
sock.connect("ipc:///tmp/clearpilot_ui_rpc")
|
||||
sock.send_string("dump")
|
||||
try:
|
||||
print(sock.recv_string())
|
||||
except zmq.Again:
|
||||
print("ERROR: UI not responding (timeout)")
|
||||
Reference in New Issue
Block a user