diff --git a/selfdrive/car/car_helpers.py b/selfdrive/car/car_helpers.py index f6f3960475..fd8ecc5020 100644 --- a/selfdrive/car/car_helpers.py +++ b/selfdrive/car/car_helpers.py @@ -4,7 +4,6 @@ from collections.abc import Callable from cereal import car from openpilot.common.params import Params -from openpilot.common.basedir import BASEDIR from openpilot.system.version import is_comma_remote, is_tested_branch from openpilot.selfdrive.car.interfaces import get_interface_attr from openpilot.selfdrive.car.fingerprints import eliminate_incompatible_cars, all_legacy_fingerprint_cars @@ -48,17 +47,8 @@ def load_interfaces(brand_names): for brand_name in brand_names: path = f'openpilot.selfdrive.car.{brand_name}' CarInterface = __import__(path + '.interface', fromlist=['CarInterface']).CarInterface - - if os.path.exists(BASEDIR + '/' + path.replace('.', '/') + '/carstate.py'): - CarState = __import__(path + '.carstate', fromlist=['CarState']).CarState - else: - CarState = None - - if os.path.exists(BASEDIR + '/' + path.replace('.', '/') + '/carcontroller.py'): - CarController = __import__(path + '.carcontroller', fromlist=['CarController']).CarController - else: - CarController = None - + CarState = __import__(path + '.carstate', fromlist=['CarState']).CarState + CarController = __import__(path + '.carcontroller', fromlist=['CarController']).CarController for model_name in brand_names[brand_name]: ret[model_name] = (CarInterface, CarController, CarState) return ret diff --git a/selfdrive/car/interfaces.py b/selfdrive/car/interfaces.py index be1518a25a..b6a626edec 100644 --- a/selfdrive/car/interfaces.py +++ b/selfdrive/car/interfaces.py @@ -81,21 +81,16 @@ class CarInterfaceBase(ABC): self.silent_steer_warning = True self.v_ego_cluster_seen = False - self.CS = None - self.can_parsers = [] - if CarState is not None: - self.CS = CarState(CP) - - self.cp = self.CS.get_can_parser(CP) - self.cp_cam = self.CS.get_cam_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_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.CC: CarControllerBase = None - if CarController is not None: - self.CC = CarController(self.cp.dbc_name, CP, self.VM) + self.CS = CarState(CP) + self.cp = self.CS.get_can_parser(CP) + self.cp_cam = self.CS.get_cam_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_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] + + dbc_name = "" if self.cp is None else self.cp.dbc_name + self.CC: CarControllerBase = CarController(dbc_name, CP, self.VM) def apply(self, c: car.CarControl, now_nanos: int) -> tuple[car.CarControl.Actuators, list[tuple[int, int, bytes, int]]]: return self.CC.update(c, self.CS, now_nanos) @@ -438,6 +433,10 @@ class CarStateBase(ABC): } return d.get(gear.upper(), GearShifter.unknown) + @staticmethod + def get_can_parser(CP): + return None + @staticmethod def get_cam_can_parser(CP): return None @@ -459,6 +458,9 @@ SendCan = tuple[int, int, bytes, int] class CarControllerBase(ABC): + def __init__(self, dbc_name: str, CP, VM): + pass + @abstractmethod def update(self, CC: car.CarControl.Actuators, CS: car.CarState, now_nanos: int) -> tuple[car.CarControl.Actuators, list[SendCan]]: pass diff --git a/selfdrive/car/mock/carcontroller.py b/selfdrive/car/mock/carcontroller.py new file mode 100644 index 0000000000..2b2da954ff --- /dev/null +++ b/selfdrive/car/mock/carcontroller.py @@ -0,0 +1,5 @@ +from openpilot.selfdrive.car.interfaces import CarControllerBase + +class CarController(CarControllerBase): + def update(self, CC, CS, now_nanos): + return CC.actuators.copy(), [] diff --git a/selfdrive/car/mock/carstate.py b/selfdrive/car/mock/carstate.py new file mode 100644 index 0000000000..ece908b51c --- /dev/null +++ b/selfdrive/car/mock/carstate.py @@ -0,0 +1,4 @@ +from openpilot.selfdrive.car.interfaces import CarStateBase + +class CarState(CarStateBase): + pass