disable tlog calls, add param gate to tlog client
- Comment out all tlog() calls in controlsd (100Hz) and carstate (100Hz) — was causing controlsd to lag from JSON serialization + ZMQ overhead - tlog() now checks TelemetryEnabled memory param (1/sec file read), returns immediately when disabled — zero cost when telemetry is off Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -421,59 +421,14 @@ class CarState(CarStateBase):
|
|||||||
# self.params_memory.put_float("CarSpeedLimitLiteral", self.calculate_speed_limit(cp, cp_cam))
|
# self.params_memory.put_float("CarSpeedLimitLiteral", self.calculate_speed_limit(cp, cp_cam))
|
||||||
self.params_memory.put_float("CarSpeedLimit", self.calculate_speed_limit(cp, cp_cam) * speed_factor)
|
self.params_memory.put_float("CarSpeedLimit", self.calculate_speed_limit(cp, cp_cam) * speed_factor)
|
||||||
|
|
||||||
# CLEARPILOT: telemetry logging
|
# CLEARPILOT: telemetry logging — disabled, re-enable when needed
|
||||||
speed_limit_bus = cp if self.CP.flags & HyundaiFlags.CANFD_HDA2 else cp_cam
|
# speed_limit_bus = cp if self.CP.flags & HyundaiFlags.CANFD_HDA2 else cp_cam
|
||||||
scc = cp_cam.vl["SCC_CONTROL"] if self.CP.flags & HyundaiFlags.CANFD_CAMERA_SCC else cp.vl["SCC_CONTROL"]
|
# scc = cp_cam.vl["SCC_CONTROL"] if self.CP.flags & HyundaiFlags.CANFD_CAMERA_SCC else cp.vl["SCC_CONTROL"]
|
||||||
cluster = speed_limit_bus.vl["CLUSTER_SPEED_LIMIT"]
|
# cluster = speed_limit_bus.vl["CLUSTER_SPEED_LIMIT"]
|
||||||
|
# tlog("car", { ... })
|
||||||
tlog("car", {
|
# tlog("cruise", { ... })
|
||||||
"vEgo": round(ret.vEgo, 3),
|
# tlog("speed_limit", { ... })
|
||||||
"vEgoRaw": round(ret.vEgoRaw, 3),
|
# tlog("buttons", { ... })
|
||||||
"aEgo": round(ret.aEgo, 3),
|
|
||||||
"steeringAngleDeg": round(ret.steeringAngleDeg, 1),
|
|
||||||
"gear": str(ret.gearShifter),
|
|
||||||
"brakePressed": ret.brakePressed,
|
|
||||||
"gasPressed": ret.gasPressed,
|
|
||||||
"standstill": ret.standstill,
|
|
||||||
"leftBlinker": ret.leftBlinker,
|
|
||||||
"rightBlinker": ret.rightBlinker,
|
|
||||||
})
|
|
||||||
|
|
||||||
tlog("cruise", {
|
|
||||||
"enabled": ret.cruiseState.enabled,
|
|
||||||
"available": ret.cruiseState.available,
|
|
||||||
"speed": round(ret.cruiseState.speed, 3),
|
|
||||||
"standstill": ret.cruiseState.standstill,
|
|
||||||
"accFaulted": ret.accFaulted,
|
|
||||||
"brakePressed": ret.brakePressed,
|
|
||||||
"ACCMode": scc.get("ACCMode", 0),
|
|
||||||
"VSetDis": scc.get("VSetDis", 0),
|
|
||||||
"aReqRaw": round(scc.get("aReqRaw", 0), 3),
|
|
||||||
"aReqValue": round(scc.get("aReqValue", 0), 3),
|
|
||||||
"DISTANCE_SETTING": scc.get("DISTANCE_SETTING", 0),
|
|
||||||
"ACC_ObjDist": round(scc.get("ACC_ObjDist", 0), 1),
|
|
||||||
})
|
|
||||||
|
|
||||||
tlog("speed_limit", {
|
|
||||||
"SPEED_LIMIT_1": cluster.get("SPEED_LIMIT_1", 0),
|
|
||||||
"SPEED_LIMIT_2": cluster.get("SPEED_LIMIT_2", 0),
|
|
||||||
"SPEED_LIMIT_3": cluster.get("SPEED_LIMIT_3", 0),
|
|
||||||
"SCHOOL_ZONE": cluster.get("SCHOOL_ZONE", 0),
|
|
||||||
"CHIME_1": cluster.get("CHIME_1", 0),
|
|
||||||
"CHIME_2": cluster.get("CHIME_2", 0),
|
|
||||||
"SPEED_CHANGE_BLINKING": cluster.get("SPEED_CHANGE_BLINKING", 0),
|
|
||||||
"calculated": self.calculate_speed_limit(cp, cp_cam),
|
|
||||||
"is_metric": self.is_metric,
|
|
||||||
})
|
|
||||||
|
|
||||||
tlog("buttons", {
|
|
||||||
"cruise_button": self.cruise_buttons[-1],
|
|
||||||
"prev_cruise_button": self.prev_cruise_buttons,
|
|
||||||
"main_button": self.main_buttons[-1],
|
|
||||||
"prev_main_button": self.prev_main_buttons,
|
|
||||||
"lkas_enabled": self.lkas_enabled,
|
|
||||||
"main_enabled": self.main_enabled,
|
|
||||||
})
|
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|||||||
@@ -6,20 +6,39 @@ Usage from any process:
|
|||||||
tlog("canbus", {"speed": 45.2, "speed_limit": 60})
|
tlog("canbus", {"speed": 45.2, "speed_limit": 60})
|
||||||
|
|
||||||
Sends JSON packets over ZMQ PUSH to telemetryd, which diffs and writes CSV.
|
Sends JSON packets over ZMQ PUSH to telemetryd, which diffs and writes CSV.
|
||||||
|
Only sends when TelemetryEnabled memory param is set — zero cost when disabled.
|
||||||
"""
|
"""
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
import time
|
import time
|
||||||
import zmq
|
import zmq
|
||||||
|
|
||||||
TELEMETRY_SOCK = "ipc:///tmp/clearpilot_telemetry"
|
TELEMETRY_SOCK = "ipc:///tmp/clearpilot_telemetry"
|
||||||
|
_PARAM_PATH = "/dev/shm/params/d/TelemetryEnabled"
|
||||||
|
|
||||||
_ctx = None
|
_ctx = None
|
||||||
_sock = None
|
_sock = None
|
||||||
|
_last_check = 0
|
||||||
|
_enabled = False
|
||||||
|
|
||||||
|
|
||||||
def tlog(group: str, data: dict):
|
def tlog(group: str, data: dict):
|
||||||
"""Log a telemetry packet. Only changed values will be written to CSV by telemetryd."""
|
"""Log a telemetry packet. Only changed values will be written to CSV by telemetryd."""
|
||||||
global _ctx, _sock
|
global _ctx, _sock, _last_check, _enabled
|
||||||
|
|
||||||
|
# Check param at most once per second to avoid filesystem overhead
|
||||||
|
now = time.monotonic()
|
||||||
|
if now - _last_check > 1.0:
|
||||||
|
_last_check = now
|
||||||
|
try:
|
||||||
|
with open(_PARAM_PATH, 'r') as f:
|
||||||
|
_enabled = f.read().strip() == "1"
|
||||||
|
except (FileNotFoundError, IOError):
|
||||||
|
_enabled = False
|
||||||
|
|
||||||
|
if not _enabled:
|
||||||
|
return
|
||||||
|
|
||||||
if _sock is None:
|
if _sock is None:
|
||||||
_ctx = zmq.Context.instance()
|
_ctx = zmq.Context.instance()
|
||||||
_sock = _ctx.socket(zmq.PUSH)
|
_sock = _ctx.socket(zmq.PUSH)
|
||||||
|
|||||||
@@ -639,15 +639,13 @@ class Controls:
|
|||||||
self.enabled = self.state in ENABLED_STATES
|
self.enabled = self.state in ENABLED_STATES
|
||||||
self.active = self.state in ACTIVE_STATES
|
self.active = self.state in ACTIVE_STATES
|
||||||
|
|
||||||
# CLEARPILOT: log engagement state for debugging cruise desync issues
|
# CLEARPILOT: engagement telemetry disabled — was running at 100Hz, causing CPU load
|
||||||
tlog("engage", {
|
# tlog("engage", {
|
||||||
"state": self.state.name if hasattr(self.state, 'name') else str(self.state),
|
# "state": self.state.name if hasattr(self.state, 'name') else str(self.state),
|
||||||
"enabled": self.enabled,
|
# "enabled": self.enabled, "active": self.active,
|
||||||
"active": self.active,
|
# "cruise_enabled": CS.cruiseState.enabled, "cruise_available": CS.cruiseState.available,
|
||||||
"cruise_enabled": CS.cruiseState.enabled,
|
# "brakePressed": CS.brakePressed,
|
||||||
"cruise_available": CS.cruiseState.available,
|
# })
|
||||||
"brakePressed": CS.brakePressed,
|
|
||||||
})
|
|
||||||
if self.active:
|
if self.active:
|
||||||
self.current_alert_types.append(ET.WARNING)
|
self.current_alert_types.append(ET.WARNING)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user