From 25b4672fda6a67c8a136a08a3cb96fa5bb97f9d1 Mon Sep 17 00:00:00 2001 From: Brian Hanson Date: Thu, 16 Apr 2026 22:46:07 -0500 Subject: [PATCH] feat: raise controlsdLagging alert threshold to 20ms avg MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Stock rk.lagging fires at 11.1ms (90% of 10ms interval), which the Hyundai CAN load routinely crosses during normal driving as carstate parses 50-200 msgs/sec. That's normal, not a fault — the same code behaved the same way at the fork baseline; we just made it visible with the LAG overlay. 50Hz effective control is still tighter than any human reaction loop. rk.lagging remains wired to the defensive skip paths (secondary camera and radar checks) at the original tighter threshold, so we still avoid false-alarming dependent events when briefly overloaded. Co-Authored-By: Claude Opus 4.6 (1M context) --- selfdrive/controls/controlsd.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/selfdrive/controls/controlsd.py b/selfdrive/controls/controlsd.py index 1632a9e..6c9d745 100755 --- a/selfdrive/controls/controlsd.py +++ b/selfdrive/controls/controlsd.py @@ -481,12 +481,16 @@ class Controls: self.events.add(EventName.cameraMalfunction) elif not self.sm.all_freq_ok(self.camera_packets): self.events.add(EventName.cameraFrameRate) - # CLEARPILOT: also gate on model_suppress + lat_engage_suppress — the fps transition - # on engage briefly pushes avg cycle time over the 11.1ms (90% of 10ms) threshold - # while downstream services (plannerd, locationd) drain the sudden 5x message rate - if not REPLAY and self.rk.lagging and not model_suppress and not lat_engage_suppress: + # CLEARPILOT: alert only when avg cycle time exceeds 20ms (≈50Hz effective). + # Stock rk.lagging fires at 11.1ms (90% of 10ms) which the Hyundai CAN load + # routinely crosses while driving — that's normal, not a fault. 50Hz control is + # still plenty responsive. `rk.lagging` is still used defensively elsewhere + # (lines ~479, 492) to skip secondary checks when slightly overloaded. + avg_dt = sum(self.rk._dts) / len(self.rk._dts) + alert_lagging = avg_dt > 0.020 + if not REPLAY and alert_lagging and not model_suppress and not lat_engage_suppress: import sys - print(f"CLP controlsdLagging: remaining={self.rk.remaining:.4f} standstill={CS.standstill} vEgo={CS.vEgo:.2f}", file=sys.stderr) + print(f"CLP controlsdLagging: avg_dt={avg_dt*1000:.2f}ms remaining={self.rk.remaining:.4f} standstill={CS.standstill} vEgo={CS.vEgo:.2f}", file=sys.stderr) self.events.add(EventName.controlsdLagging) if not self.radarless_model: if not model_suppress and (len(self.sm['radarState'].radarErrors) or (not self.rk.lagging and not self.sm.all_checks(['radarState']))):