diff --git a/selfdrive/controls/controlsd.py b/selfdrive/controls/controlsd.py index 1f330e2..c6d77e3 100755 --- a/selfdrive/controls/controlsd.py +++ b/selfdrive/controls/controlsd.py @@ -174,6 +174,12 @@ class Controls: self.state = State.disabled self.enabled = False self.active = False + # CLEARPILOT: track engagement edge for the post-engage controlsdLagging + # suppression window (the loop briefly lags during state transition into + # enabled, which would otherwise pop "Controls Process Lagging: Reboot + # Your Device" right as the user lets the wheel go). + self.last_engaged_frame = -1 + self.POST_ENGAGE_LAG_GRACE_FRAMES = int(3.0 / DT_CTRL) self.soft_disable_timer = 0 self.mismatch_counter = 0 self.cruise_mismatch_counter = 0 @@ -486,7 +492,14 @@ class Controls: elif not self.sm.all_freq_ok(self.camera_packets): self.events.add(EventName.cameraFrameRate) if not REPLAY and self.rk.lagging: - self.events.add(EventName.controlsdLagging) + # CLEARPILOT: suppress controlsdLagging for the first 3 seconds after + # engagement — the loop briefly lags during the state transition into + # enabled, which otherwise pops a scary "Reboot Your Device" alert + # just as the user is letting their hands off the wheel. + in_post_engage_lag_grace = (self.last_engaged_frame >= 0 + and (self.sm.frame - self.last_engaged_frame) < self.POST_ENGAGE_LAG_GRACE_FRAMES) + if not in_post_engage_lag_grace: + self.events.add(EventName.controlsdLagging) if not self.radarless_model: if len(self.sm['radarState'].radarErrors) or (not self.rk.lagging and not self.sm.all_checks(['radarState'])): self.events.add(EventName.radarFault) @@ -658,8 +671,12 @@ class Controls: self.v_cruise_helper.initialize_v_cruise(CS, self.experimental_mode, self.sm['frogpilotPlan'].unconfirmedSlcSpeedLimit, self.frogpilot_variables) # Check if openpilot is engaged and actuators are enabled + enabled_prev = self.enabled self.enabled = self.state in ENABLED_STATES self.active = self.state in ACTIVE_STATES + # CLEARPILOT: capture rising edge of engagement for the lag-grace window. + if self.enabled and not enabled_prev: + self.last_engaged_frame = self.sm.frame if self.active: self.current_alert_types.append(ET.WARNING)