From d1e143ac984aec60c79917e3c4a82f3b26a3d5cf Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Tue, 14 Jul 2026 19:01:22 -0700 Subject: [PATCH] longcontrol: simplify state machine (#38337) --- openpilot/selfdrive/controls/lib/longcontrol.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/openpilot/selfdrive/controls/lib/longcontrol.py b/openpilot/selfdrive/controls/lib/longcontrol.py index 1132fedda..977add128 100644 --- a/openpilot/selfdrive/controls/lib/longcontrol.py +++ b/openpilot/selfdrive/controls/lib/longcontrol.py @@ -12,11 +12,9 @@ LongCtrlState = car.CarControl.Actuators.LongControlState def long_control_state_trans(CP, active, long_control_state, v_ego, should_stop, brake_pressed, cruise_standstill): - stopping_condition = should_stop starting_condition = (not should_stop and not cruise_standstill and not brake_pressed) - started_condition = v_ego > CP.vEgoStarting if not active: long_control_state = LongCtrlState.off @@ -25,11 +23,10 @@ def long_control_state_trans(CP, active, long_control_state, v_ego, if long_control_state == LongCtrlState.off: if not starting_condition: long_control_state = LongCtrlState.stopping + elif CP.startingState: + long_control_state = LongCtrlState.starting else: - if starting_condition and CP.startingState: - long_control_state = LongCtrlState.starting - else: - long_control_state = LongCtrlState.pid + long_control_state = LongCtrlState.pid elif long_control_state == LongCtrlState.stopping: if starting_condition and CP.startingState: @@ -38,9 +35,9 @@ def long_control_state_trans(CP, active, long_control_state, v_ego, long_control_state = LongCtrlState.pid elif long_control_state in [LongCtrlState.starting, LongCtrlState.pid]: - if stopping_condition: + if should_stop: long_control_state = LongCtrlState.stopping - elif started_condition: + elif v_ego > CP.vEgoStarting: long_control_state = LongCtrlState.pid return long_control_state