interfaces: assume CarState is instantiated (#33284)

test to make sure mock doesn't crash!
old-commit-hash: 3d2fbe9aa3
pull/33314/head
Shane Smiskol 9 months ago committed by GitHub
parent 1c2b830650
commit 6a15aa3f8c
  1. 12
      selfdrive/car/interfaces.py
  2. 10
      selfdrive/car/tests/test_car_interfaces.py

@ -103,7 +103,7 @@ class CarInterfaceBase(ABC):
self.cp_adas = self.CS.get_adas_can_parser(CP) self.cp_adas = self.CS.get_adas_can_parser(CP)
self.cp_body = self.CS.get_body_can_parser(CP) self.cp_body = self.CS.get_body_can_parser(CP)
self.cp_loopback = self.CS.get_loopback_can_parser(CP) self.cp_loopback = self.CS.get_loopback_can_parser(CP)
self.can_parsers = [self.cp, self.cp_cam, self.cp_adas, self.cp_body, self.cp_loopback] self.can_parsers = (self.cp, self.cp_cam, self.cp_adas, self.cp_body, self.cp_loopback)
dbc_name = "" if self.cp is None else self.cp.dbc_name dbc_name = "" if self.cp is None else self.cp.dbc_name
self.CC: CarControllerBase = CarController(dbc_name, CP) self.CC: CarControllerBase = CarController(dbc_name, CP)
@ -246,17 +246,15 @@ class CarInterfaceBase(ABC):
self.v_ego_cluster_seen = True self.v_ego_cluster_seen = True
# Many cars apply hysteresis to the ego dash speed # Many cars apply hysteresis to the ego dash speed
if self.CS is not None: ret.vEgoCluster = apply_hysteresis(ret.vEgoCluster, self.CS.out.vEgoCluster, self.CS.cluster_speed_hyst_gap)
ret.vEgoCluster = apply_hysteresis(ret.vEgoCluster, self.CS.out.vEgoCluster, self.CS.cluster_speed_hyst_gap) if abs(ret.vEgo) < self.CS.cluster_min_speed:
if abs(ret.vEgo) < self.CS.cluster_min_speed: ret.vEgoCluster = 0.0
ret.vEgoCluster = 0.0
if ret.cruiseState.speedCluster == 0: if ret.cruiseState.speedCluster == 0:
ret.cruiseState.speedCluster = ret.cruiseState.speed ret.cruiseState.speedCluster = ret.cruiseState.speed
# copy back for next iteration # copy back for next iteration
if self.CS is not None: self.CS.out = ret.as_reader()
self.CS.out = ret.as_reader()
return ret return ret

@ -11,6 +11,7 @@ from openpilot.selfdrive.car.car_helpers import interfaces
from openpilot.selfdrive.car.fingerprints import all_known_cars from openpilot.selfdrive.car.fingerprints import all_known_cars
from openpilot.selfdrive.car.fw_versions import FW_VERSIONS, FW_QUERY_CONFIGS from openpilot.selfdrive.car.fw_versions import FW_VERSIONS, FW_QUERY_CONFIGS
from openpilot.selfdrive.car.interfaces import get_interface_attr from openpilot.selfdrive.car.interfaces import get_interface_attr
from openpilot.selfdrive.car.mock.values import CAR as MOCK
from openpilot.selfdrive.controls.lib.latcontrol_angle import LatControlAngle from openpilot.selfdrive.controls.lib.latcontrol_angle import LatControlAngle
from openpilot.selfdrive.controls.lib.latcontrol_pid import LatControlPID from openpilot.selfdrive.controls.lib.latcontrol_pid import LatControlPID
from openpilot.selfdrive.controls.lib.latcontrol_torque import LatControlTorque from openpilot.selfdrive.controls.lib.latcontrol_torque import LatControlTorque
@ -51,7 +52,7 @@ def get_fuzzy_car_interface_args(draw: DrawType) -> dict:
class TestCarInterfaces: class TestCarInterfaces:
# FIXME: Due to the lists used in carParams, Phase.target is very slow and will cause # FIXME: Due to the lists used in carParams, Phase.target is very slow and will cause
# many generated examples to overrun when max_examples > ~20, don't use it # many generated examples to overrun when max_examples > ~20, don't use it
@parameterized.expand([(car,) for car in sorted(all_known_cars())]) @parameterized.expand([(car,) for car in sorted(all_known_cars())] + [MOCK.MOCK])
@settings(max_examples=MAX_EXAMPLES, deadline=None, @settings(max_examples=MAX_EXAMPLES, deadline=None,
phases=(Phase.reuse, Phase.generate, Phase.shrink)) phases=(Phase.reuse, Phase.generate, Phase.shrink))
@given(data=st.data()) @given(data=st.data())
@ -81,9 +82,10 @@ class TestCarInterfaces:
if car_params.steerControlType != car.CarParams.SteerControlType.angle: if car_params.steerControlType != car.CarParams.SteerControlType.angle:
tune = car_params.lateralTuning tune = car_params.lateralTuning
if tune.which() == 'pid': if tune.which() == 'pid':
assert not math.isnan(tune.pid.kf) and tune.pid.kf > 0 if car_name != MOCK.MOCK:
assert len(tune.pid.kpV) > 0 and len(tune.pid.kpV) == len(tune.pid.kpBP) assert not math.isnan(tune.pid.kf) and tune.pid.kf > 0
assert len(tune.pid.kiV) > 0 and len(tune.pid.kiV) == len(tune.pid.kiBP) assert len(tune.pid.kpV) > 0 and len(tune.pid.kpV) == len(tune.pid.kpBP)
assert len(tune.pid.kiV) > 0 and len(tune.pid.kiV) == len(tune.pid.kiBP)
elif tune.which() == 'torque': elif tune.which() == 'torque':
assert not math.isnan(tune.torque.kf) and tune.torque.kf > 0 assert not math.isnan(tune.torque.kf) and tune.torque.kf > 0

Loading…
Cancel
Save