Car interface: require fingerprint and FW versions to get params (#26932)

* require fingerprint and FW versions

* add get_non_essential_params()

* comment

* all required

* classmethod, need to allow subclasses to override _get_params

* fix that

* fix

* fix

* wrong fix 🤦
old-commit-hash: b00bc4f57e
This commit is contained in:
Shane Smiskol 2023-01-12 12:25:24 -08:00 committed by GitHub
parent b67646e1ab
commit 0ceb423ccc
12 changed files with 18 additions and 17 deletions

View File

@ -29,7 +29,7 @@ def get_all_car_info() -> List[CarInfo]:
all_car_info: List[CarInfo] = []
footnotes = get_all_footnotes()
for model, car_info in get_interface_attr("CAR_INFO", combine_brands=True).items():
CP = interfaces[model][0].get_params(model, fingerprint=gen_empty_fingerprint(), car_fw=[car.CarParams.CarFw(ecu="unknown")])
CP = interfaces[model][0].get_params(model, fingerprint=gen_empty_fingerprint(), car_fw=[car.CarParams.CarFw(ecu="unknown")], experimental_long=False)
if CP.dashcamOnly or car_info is None:
continue

View File

@ -88,13 +88,14 @@ class CarInterfaceBase(ABC):
return ACCEL_MIN, ACCEL_MAX
@classmethod
def get_params(cls, candidate: str, fingerprint: Optional[Dict[int, Dict[int, int]]] = None, car_fw: Optional[List[car.CarParams.CarFw]] = None, experimental_long: bool = False):
if fingerprint is None:
fingerprint = gen_empty_fingerprint()
if car_fw is None:
car_fw = list()
def get_non_essential_params(cls, candidate: str):
"""
Parameters essential to controlling the car may be incomplete or wrong without FW versions or fingerprints.
"""
return cls.get_params(candidate, gen_empty_fingerprint(), list(), False)
@classmethod
def get_params(cls, candidate: str, fingerprint: Dict[int, Dict[int, int]], car_fw: List[car.CarParams.CarFw], experimental_long: bool):
ret = CarInterfaceBase.get_std_params(candidate)
ret = cls._get_params(ret, candidate, fingerprint, car_fw, experimental_long)

View File

@ -25,7 +25,7 @@ class TestCarInterfaces(unittest.TestCase):
car_fw = []
car_params = CarInterface.get_params(car_name, fingerprints, car_fw)
car_params = CarInterface.get_params(car_name, fingerprints, car_fw, experimental_long=False)
car_interface = CarInterface(car_params, CarController, CarState)
assert car_params
assert car_interface

View File

@ -67,7 +67,7 @@ class TestFwFingerprint(unittest.TestCase):
blacklisted_addrs = (0x7c4, 0x7d0) # includes A/C ecu and an unknown ecu
for car_model, ecus in FW_VERSIONS.items():
with self.subTest(car_model=car_model):
CP = interfaces[car_model][0].get_params(car_model)
CP = interfaces[car_model][0].get_non_essential_params(car_model)
if CP.carName == 'subaru':
for ecu in ecus.keys():
self.assertNotIn(ecu[1], blacklisted_addrs, f'{car_model}: Blacklisted ecu: (Ecu.{ECU_NAME[ecu[0]]}, {hex(ecu[1])})')

View File

@ -40,7 +40,7 @@ class TestLateralLimits(unittest.TestCase):
@classmethod
def setUpClass(cls):
CarInterface, _, _ = interfaces[cls.car_model]
CP = CarInterface.get_params(cls.car_model)
CP = CarInterface.get_non_essential_params(cls.car_model)
if CP.dashcamOnly:
raise unittest.SkipTest("Platform is behind dashcamOnly")

View File

@ -20,7 +20,7 @@ class TestLatControl(unittest.TestCase):
@parameterized.expand([(HONDA.CIVIC, LatControlPID), (TOYOTA.RAV4, LatControlTorque), (TOYOTA.PRIUS, LatControlINDI), (NISSAN.LEAF, LatControlAngle)])
def test_saturation(self, car_name, controller):
CarInterface, CarController, CarState = interfaces[car_name]
CP = CarInterface.get_params(car_name)
CP = CarInterface.get_non_essential_params(car_name)
CI = CarInterface(CP, CarController, CarState)
VM = VehicleModel(CP)

View File

@ -12,7 +12,7 @@ from selfdrive.controls.lib.vehicle_model import VehicleModel, dyn_ss_sol, creat
class TestVehicleModel(unittest.TestCase):
def setUp(self):
CP = CarInterface.get_params(CAR.CIVIC)
CP = CarInterface.get_non_essential_params(CAR.CIVIC)
self.VM = VehicleModel(CP)
def test_round_trip_yaw_rate(self):

View File

@ -31,7 +31,7 @@ class TestStateMachine(unittest.TestCase):
def setUp(self):
CarInterface, CarController, CarState = interfaces["mock"]
CP = CarInterface.get_params("mock")
CP = CarInterface.get_non_essential_params("mock")
CI = CarInterface(CP, CarController, CarState)
self.controlsd = Controls(CI=CI)

View File

@ -51,7 +51,7 @@ def cycle_alerts(duration=200, is_metric=False):
cameras = ['roadCameraState', 'wideRoadCameraState', 'driverCameraState']
CS = car.CarState.new_message()
CP = CarInterface.get_params("HONDA CIVIC 2016")
CP = CarInterface.get_non_essential_params("HONDA CIVIC 2016")
sm = messaging.SubMaster(['deviceState', 'pandaStates', 'roadCameraState', 'modelV2', 'liveCalibration',
'driverMonitoringState', 'longitudinalPlan', 'lateralPlan', 'liveLocationKalman',
'managerState'] + cameras)

View File

@ -20,7 +20,7 @@ T_SIM = 5 * 60 # s
DT = 0.01
CP = CarInterface.get_params(CAR.CIVIC)
CP = CarInterface.get_non_essential_params(CAR.CIVIC)
VM = VehicleModel(CP)
x, y = 0, 0 # m, m

View File

@ -49,7 +49,7 @@ class Plant:
from selfdrive.car.honda.values import CAR
from selfdrive.car.honda.interface import CarInterface
self.planner = LongitudinalPlanner(CarInterface.get_params(CAR.CIVIC), init_v=self.speed)
self.planner = LongitudinalPlanner(CarInterface.get_non_essential_params(CAR.CIVIC), init_v=self.speed)
@property
def current_time(self):

View File

@ -180,7 +180,7 @@ def fingerprint(msgs, fsm, can_sock, fingerprint):
def get_car_params(msgs, fsm, can_sock, fingerprint):
if fingerprint:
CarInterface, _, _ = interfaces[fingerprint]
CP = CarInterface.get_params(fingerprint)
CP = CarInterface.get_non_essential_params(fingerprint)
else:
can = FakeSocket(wait=False)
sendcan = FakeSocket(wait=False)