mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-09-04 10:13:43 +08:00
af7bf5dc64
version: sunnypilot v2026.003.000 (feature-branch)
date: 2026-09-03T14:07:59
master commit: 1500f45576
45 lines
2.4 KiB
Python
45 lines
2.4 KiB
Python
from openpilot.common.test import OpenpilotTestCase
|
|
from openpilot.cereal import custom
|
|
from openpilot.selfdrive.controls.lib.longcontrol import LongCtrlState, long_control_state_trans
|
|
|
|
|
|
class TestLongControlStateTransition(OpenpilotTestCase):
|
|
|
|
def test_stay_stopped(self):
|
|
CP_SP = custom.CarParamsSP.new_message()
|
|
active = True
|
|
current_state = LongCtrlState.stopping
|
|
next_state = long_control_state_trans(CP_SP, active, current_state,
|
|
should_stop=True, brake_pressed=False, cruise_standstill=False)
|
|
assert next_state == LongCtrlState.stopping
|
|
next_state = long_control_state_trans(CP_SP, active, current_state,
|
|
should_stop=False, brake_pressed=True, cruise_standstill=False)
|
|
assert next_state == LongCtrlState.stopping
|
|
next_state = long_control_state_trans(CP_SP, active, current_state,
|
|
should_stop=False, brake_pressed=False, cruise_standstill=True)
|
|
assert next_state == LongCtrlState.stopping
|
|
next_state = long_control_state_trans(CP_SP, active, current_state,
|
|
should_stop=False, brake_pressed=False, cruise_standstill=False)
|
|
assert next_state == LongCtrlState.pid
|
|
active = False
|
|
next_state = long_control_state_trans(CP_SP, active, current_state,
|
|
should_stop=False, brake_pressed=False, cruise_standstill=False)
|
|
assert next_state == LongCtrlState.off
|
|
|
|
def test_engage(self):
|
|
CP_SP = custom.CarParamsSP.new_message()
|
|
active = True
|
|
current_state = LongCtrlState.off
|
|
next_state = long_control_state_trans(CP_SP, active, current_state,
|
|
should_stop=True, brake_pressed=False, cruise_standstill=False)
|
|
assert next_state == LongCtrlState.stopping
|
|
next_state = long_control_state_trans(CP_SP, active, current_state,
|
|
should_stop=False, brake_pressed=True, cruise_standstill=False)
|
|
assert next_state == LongCtrlState.stopping
|
|
next_state = long_control_state_trans(CP_SP, active, current_state,
|
|
should_stop=False, brake_pressed=False, cruise_standstill=True)
|
|
assert next_state == LongCtrlState.stopping
|
|
next_state = long_control_state_trans(CP_SP, active, current_state,
|
|
should_stop=False, brake_pressed=False, cruise_standstill=False)
|
|
assert next_state == LongCtrlState.pid
|