Longcontrol: engage into stopped state when needed (#33042)
test stay stopped
old-commit-hash: 3bc1b173d2
pull/33302/head
parent
61c4da30f5
commit
543e691203
2 changed files with 65 additions and 5 deletions
@ -0,0 +1,56 @@ |
|||||||
|
from cereal import car |
||||||
|
from openpilot.selfdrive.controls.lib.longcontrol import LongCtrlState, long_control_state_trans |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class TestLongControlStateTransition: |
||||||
|
|
||||||
|
def test_stay_stopped(self): |
||||||
|
CP = car.CarParams.new_message() |
||||||
|
active = True |
||||||
|
current_state = LongCtrlState.stopping |
||||||
|
next_state = long_control_state_trans(CP, active, current_state, v_ego=0.1, |
||||||
|
should_stop=True, brake_pressed=False, cruise_standstill=False) |
||||||
|
assert next_state == LongCtrlState.stopping |
||||||
|
next_state = long_control_state_trans(CP, active, current_state, v_ego=0.1, |
||||||
|
should_stop=False, brake_pressed=True, cruise_standstill=False) |
||||||
|
assert next_state == LongCtrlState.stopping |
||||||
|
next_state = long_control_state_trans(CP, active, current_state, v_ego=0.1, |
||||||
|
should_stop=False, brake_pressed=False, cruise_standstill=True) |
||||||
|
assert next_state == LongCtrlState.stopping |
||||||
|
next_state = long_control_state_trans(CP, active, current_state, v_ego=1.0, |
||||||
|
should_stop=False, brake_pressed=False, cruise_standstill=False) |
||||||
|
assert next_state == LongCtrlState.pid |
||||||
|
active = False |
||||||
|
next_state = long_control_state_trans(CP, active, current_state, v_ego=1.0, |
||||||
|
should_stop=False, brake_pressed=False, cruise_standstill=False) |
||||||
|
assert next_state == LongCtrlState.off |
||||||
|
|
||||||
|
def test_engage(): |
||||||
|
CP = car.CarParams.new_message() |
||||||
|
active = True |
||||||
|
current_state = LongCtrlState.off |
||||||
|
next_state = long_control_state_trans(CP, active, current_state, v_ego=0.1, |
||||||
|
should_stop=True, brake_pressed=False, cruise_standstill=False) |
||||||
|
assert next_state == LongCtrlState.stopping |
||||||
|
next_state = long_control_state_trans(CP, active, current_state, v_ego=0.1, |
||||||
|
should_stop=False, brake_pressed=True, cruise_standstill=False) |
||||||
|
assert next_state == LongCtrlState.stopping |
||||||
|
next_state = long_control_state_trans(CP, active, current_state, v_ego=0.1, |
||||||
|
should_stop=False, brake_pressed=False, cruise_standstill=True) |
||||||
|
assert next_state == LongCtrlState.stopping |
||||||
|
next_state = long_control_state_trans(CP, active, current_state, v_ego=0.1, |
||||||
|
should_stop=False, brake_pressed=False, cruise_standstill=False) |
||||||
|
assert next_state == LongCtrlState.pid |
||||||
|
|
||||||
|
def test_starting(): |
||||||
|
CP = car.CarParams.new_message(startingState=True, vEgoStarting=0.5) |
||||||
|
active = True |
||||||
|
current_state = LongCtrlState.starting |
||||||
|
next_state = long_control_state_trans(CP, active, current_state, v_ego=0.1, |
||||||
|
should_stop=False, brake_pressed=False, cruise_standstill=False) |
||||||
|
assert next_state == LongCtrlState.starting |
||||||
|
next_state = long_control_state_trans(CP, active, current_state, v_ego=1.0, |
||||||
|
should_stop=False, brake_pressed=False, cruise_standstill=False) |
||||||
|
assert next_state == LongCtrlState.pid |
Loading…
Reference in new issue