longcontrol: simplify state machine (#38337)

This commit is contained in:
Adeeb Shihadeh
2026-07-14 19:01:22 -07:00
committed by GitHub
parent 45b53cf66a
commit d1e143ac98
@@ -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