78 lines
3.6 KiB
Python
78 lines
3.6 KiB
Python
from cereal import car
|
|
from openpilot.selfdrive.controls.lib.longcontrol import LongCtrlState, long_control_state_trans
|
|
import openpilot.selfdrive.controls.lib.longcontrol as longcontrol
|
|
from openpilot.selfdrive.controls.lib.longcontrol import LongControl
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
def test_volt_testing_ground_handoff_freezes_integrator(monkeypatch):
|
|
CP = car.CarParams.new_message()
|
|
CP.brand = "gm"
|
|
CP.enableGasInterceptorDEPRECATED = True
|
|
CP.carFingerprint = "CHEVROLET_VOLT_ASCM"
|
|
CP.longitudinalTuning.kpBP = [0.0]
|
|
CP.longitudinalTuning.kpV = [0.1]
|
|
CP.longitudinalTuning.kiBP = [0.0]
|
|
CP.longitudinalTuning.kiV = [0.03]
|
|
|
|
monkeypatch.setattr(longcontrol.testing_ground, "use_2", True, raising=False)
|
|
|
|
lc = LongControl(CP)
|
|
freeze = lc._get_pedal_long_freeze(a_target=0.7, error=0.7, v_ego=8.0, accel_limits=(-3.0, 2.0))
|
|
|
|
assert freeze
|
|
assert lc.integrator_hold_frames > 0
|