From b97ed10ea1f61728dd3cccea76770915e64d6932 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Tue, 13 Aug 2024 21:16:39 -0700 Subject: [PATCH] Car interface clean up (#33290) * remove some defs * now carstate * remove carControl from CI update function * almost merged that * and that old-commit-hash: 65fccbf7563ceca5ec84bb75ceb39556371a74de --- selfdrive/car/body/carstate.py | 2 -- selfdrive/car/body/interface.py | 2 +- selfdrive/car/card.py | 2 +- selfdrive/car/chrysler/interface.py | 2 +- selfdrive/car/ford/interface.py | 3 +-- selfdrive/car/gm/interface.py | 3 +-- selfdrive/car/honda/interface.py | 2 +- selfdrive/car/hyundai/interface.py | 2 +- selfdrive/car/interfaces.py | 6 +++--- selfdrive/car/mazda/interface.py | 2 +- selfdrive/car/mock/interface.py | 2 +- selfdrive/car/nissan/interface.py | 2 +- selfdrive/car/subaru/interface.py | 2 +- selfdrive/car/tesla/interface.py | 2 +- selfdrive/car/tests/test_car_interfaces.py | 4 ++-- selfdrive/car/tests/test_models.py | 10 +++++----- selfdrive/car/toyota/interface.py | 2 +- selfdrive/car/volkswagen/interface.py | 4 +--- 18 files changed, 24 insertions(+), 30 deletions(-) diff --git a/selfdrive/car/body/carstate.py b/selfdrive/car/body/carstate.py index fca9bcc62..f2a8d702f 100644 --- a/selfdrive/car/body/carstate.py +++ b/selfdrive/car/body/carstate.py @@ -3,8 +3,6 @@ from opendbc.can.parser import CANParser from openpilot.selfdrive.car.interfaces import CarStateBase from openpilot.selfdrive.car.body.values import DBC -STARTUP_TICKS = 100 - class CarState(CarStateBase): def update(self, cp): ret = car.CarState.new_message() diff --git a/selfdrive/car/body/interface.py b/selfdrive/car/body/interface.py index 29d55c934..f0b473cc1 100644 --- a/selfdrive/car/body/interface.py +++ b/selfdrive/car/body/interface.py @@ -24,7 +24,7 @@ class CarInterface(CarInterfaceBase): return ret - def _update(self, c): + def _update(self): ret = self.CS.update(self.cp) return ret diff --git a/selfdrive/car/card.py b/selfdrive/car/card.py index 0cd5591e9..78b95163e 100755 --- a/selfdrive/car/card.py +++ b/selfdrive/car/card.py @@ -142,7 +142,7 @@ class Car: # Update carState from CAN can_strs = messaging.drain_sock_raw(self.can_sock, wait_for_one=True) - CS = self.CI.update(self.CC_prev, can_capnp_to_list(can_strs)) + CS = self.CI.update(can_capnp_to_list(can_strs)) self.sm.update(0) diff --git a/selfdrive/car/chrysler/interface.py b/selfdrive/car/chrysler/interface.py index 803fc02a6..04a7cc6c6 100755 --- a/selfdrive/car/chrysler/interface.py +++ b/selfdrive/car/chrysler/interface.py @@ -76,7 +76,7 @@ class CarInterface(CarInterfaceBase): return ret - def _update(self, c): + def _update(self): ret = self.CS.update(self.cp, self.cp_cam) ret.buttonEvents = create_button_events(self.CS.distance_button, self.CS.prev_distance_button, {1: ButtonType.gapAdjustCruise}) diff --git a/selfdrive/car/ford/interface.py b/selfdrive/car/ford/interface.py index 1d0233f77..8c50561a1 100644 --- a/selfdrive/car/ford/interface.py +++ b/selfdrive/car/ford/interface.py @@ -8,7 +8,6 @@ from openpilot.selfdrive.car.interfaces import CarInterfaceBase ButtonType = car.CarState.ButtonEvent.Type TransmissionType = car.CarParams.TransmissionType -GearShifter = car.CarState.GearShifter class CarInterface(CarInterfaceBase): @@ -67,7 +66,7 @@ class CarInterface(CarInterfaceBase): ret.centerToFront = ret.wheelbase * 0.44 return ret - def _update(self, c): + def _update(self): ret = self.CS.update(self.cp, self.cp_cam) ret.buttonEvents = create_button_events(self.CS.distance_button, self.CS.prev_distance_button, {1: ButtonType.gapAdjustCruise}) diff --git a/selfdrive/car/gm/interface.py b/selfdrive/car/gm/interface.py index 8dd3426d3..142301bf7 100755 --- a/selfdrive/car/gm/interface.py +++ b/selfdrive/car/gm/interface.py @@ -12,7 +12,6 @@ from openpilot.selfdrive.car.gm.values import CAR, CruiseButtons, CarControllerP from openpilot.selfdrive.car.interfaces import CarInterfaceBase, TorqueFromLateralAccelCallbackType, FRICTION_THRESHOLD, LatControlInputs, NanoFFModel ButtonType = car.CarState.ButtonEvent.Type -GearShifter = car.CarState.GearShifter TransmissionType = car.CarParams.TransmissionType NetworkLocation = car.CarParams.NetworkLocation BUTTONS_DICT = {CruiseButtons.RES_ACCEL: ButtonType.accelCruise, CruiseButtons.DECEL_SET: ButtonType.decelCruise, @@ -200,7 +199,7 @@ class CarInterface(CarInterfaceBase): return ret # returns a car.CarState - def _update(self, c): + def _update(self): ret = self.CS.update(self.cp, self.cp_cam, self.cp_loopback) # Don't add event if transitioning from INIT, unless it's to an actual button diff --git a/selfdrive/car/honda/interface.py b/selfdrive/car/honda/interface.py index f02cc07ef..7ee40b326 100755 --- a/selfdrive/car/honda/interface.py +++ b/selfdrive/car/honda/interface.py @@ -221,7 +221,7 @@ class CarInterface(CarInterfaceBase): disable_ecu(can_recv, can_send, bus=1, addr=0x18DAB0F1, com_cont_req=b'\x28\x83\x03') # returns a car.CarState - def _update(self, c): + def _update(self): ret = self.CS.update(self.cp, self.cp_cam, self.cp_body) ret.buttonEvents = [ diff --git a/selfdrive/car/hyundai/interface.py b/selfdrive/car/hyundai/interface.py index 365b8dac6..739e9d663 100644 --- a/selfdrive/car/hyundai/interface.py +++ b/selfdrive/car/hyundai/interface.py @@ -149,7 +149,7 @@ class CarInterface(CarInterfaceBase): if CP.flags & HyundaiFlags.ENABLE_BLINKERS: disable_ecu(can_recv, can_send, bus=CanBus(CP).ECAN, addr=0x7B1, com_cont_req=b'\x28\x83\x01') - def _update(self, c): + def _update(self): ret = self.CS.update(self.cp, self.cp_cam) if self.CS.CP.openpilotLongitudinalControl: diff --git a/selfdrive/car/interfaces.py b/selfdrive/car/interfaces.py index fca988f55..58f814c0e 100644 --- a/selfdrive/car/interfaces.py +++ b/selfdrive/car/interfaces.py @@ -218,17 +218,17 @@ class CarInterfaceBase(ABC): tune.torque.steeringAngleDeadzoneDeg = steering_angle_deadzone_deg @abstractmethod - def _update(self, c: car.CarControl) -> car.CarState: + def _update(self) -> car.CarState: pass - def update(self, c: car.CarControl, can_packets: list[tuple[int, list[CanData]]]) -> car.CarState: + def update(self, can_packets: list[tuple[int, list[CanData]]]) -> car.CarState: # parse can for cp in self.can_parsers: if cp is not None: cp.update_strings(can_packets) # get CarState - ret = self._update(c) + ret = self._update() ret.canValid = all(cp.can_valid for cp in self.can_parsers if cp is not None) ret.canTimeout = any(cp.bus_timeout for cp in self.can_parsers if cp is not None) diff --git a/selfdrive/car/mazda/interface.py b/selfdrive/car/mazda/interface.py index 8153d6969..984ca1669 100755 --- a/selfdrive/car/mazda/interface.py +++ b/selfdrive/car/mazda/interface.py @@ -30,7 +30,7 @@ class CarInterface(CarInterfaceBase): return ret # returns a car.CarState - def _update(self, c): + def _update(self): ret = self.CS.update(self.cp, self.cp_cam) # TODO: add button types for inc and dec diff --git a/selfdrive/car/mock/interface.py b/selfdrive/car/mock/interface.py index 7506bab05..06922888f 100755 --- a/selfdrive/car/mock/interface.py +++ b/selfdrive/car/mock/interface.py @@ -21,7 +21,7 @@ class CarInterface(CarInterfaceBase): ret.dashcamOnly = True return ret - def _update(self, c): + def _update(self): self.sm.update(0) gps_sock = 'gpsLocationExternal' if self.sm.recv_frame['gpsLocationExternal'] > 1 else 'gpsLocation' diff --git a/selfdrive/car/nissan/interface.py b/selfdrive/car/nissan/interface.py index 551108ed0..2df6b91f8 100644 --- a/selfdrive/car/nissan/interface.py +++ b/selfdrive/car/nissan/interface.py @@ -29,7 +29,7 @@ class CarInterface(CarInterfaceBase): return ret # returns a car.CarState - def _update(self, c): + def _update(self): ret = self.CS.update(self.cp, self.cp_adas, self.cp_cam) ret.buttonEvents = create_button_events(self.CS.distance_button, self.CS.prev_distance_button, {1: ButtonType.gapAdjustCruise}) diff --git a/selfdrive/car/subaru/interface.py b/selfdrive/car/subaru/interface.py index 76bda1ee0..d44be3de3 100644 --- a/selfdrive/car/subaru/interface.py +++ b/selfdrive/car/subaru/interface.py @@ -97,7 +97,7 @@ class CarInterface(CarInterfaceBase): return ret # returns a car.CarState - def _update(self, c): + def _update(self): ret = self.CS.update(self.cp, self.cp_cam, self.cp_body) diff --git a/selfdrive/car/tesla/interface.py b/selfdrive/car/tesla/interface.py index 5681f4c4a..9b8834ccf 100755 --- a/selfdrive/car/tesla/interface.py +++ b/selfdrive/car/tesla/interface.py @@ -39,7 +39,7 @@ class CarInterface(CarInterfaceBase): ret.steerActuatorDelay = 0.25 return ret - def _update(self, c): + def _update(self): ret = self.CS.update(self.cp, self.cp_cam) return ret diff --git a/selfdrive/car/tests/test_car_interfaces.py b/selfdrive/car/tests/test_car_interfaces.py index 107c13a14..f95a4a671 100644 --- a/selfdrive/car/tests/test_car_interfaces.py +++ b/selfdrive/car/tests/test_car_interfaces.py @@ -96,14 +96,14 @@ class TestCarInterfaces: now_nanos = 0 CC = car.CarControl.new_message(**cc_msg) for _ in range(10): - car_interface.update(CC, []) + car_interface.update([]) car_interface.apply(CC.as_reader(), now_nanos) now_nanos += DT_CTRL * 1e9 # 10 ms CC = car.CarControl.new_message(**cc_msg) CC.enabled = True for _ in range(10): - car_interface.update(CC, []) + car_interface.update([]) car_interface.apply(CC.as_reader(), now_nanos) now_nanos += DT_CTRL * 1e9 # 10ms diff --git a/selfdrive/car/tests/test_models.py b/selfdrive/car/tests/test_models.py index f57def036..76d360c9d 100644 --- a/selfdrive/car/tests/test_models.py +++ b/selfdrive/car/tests/test_models.py @@ -217,7 +217,7 @@ class TestCarModelBase(unittest.TestCase): CC = car.CarControl.new_message().as_reader() for i, msg in enumerate(self.can_msgs): - CS = self.CI.update(CC, can_capnp_to_list((msg.as_builder().to_bytes(),))) + CS = self.CI.update(can_capnp_to_list((msg.as_builder().to_bytes(),))) self.CI.apply(CC, msg.logMonoTime) if CS.canValid: @@ -293,7 +293,7 @@ class TestCarModelBase(unittest.TestCase): msgs_sent = 0 CI = self.CarInterface(self.CP, self.CarController, self.CarState) for _ in range(round(10.0 / DT_CTRL)): # make sure we hit the slowest messages - CI.update(car_control, []) + CI.update([]) _, sendcan = CI.apply(car_control, now_nanos) now_nanos += DT_CTRL * 1e9 @@ -358,7 +358,7 @@ class TestCarModelBase(unittest.TestCase): can = messaging.new_message('can', 1) can.can = [log.CanData(address=address, dat=dat, src=bus)] - CS = self.CI.update(CC, can_capnp_to_list((can.to_bytes(),))) + CS = self.CI.update(can_capnp_to_list((can.to_bytes(),))) if self.safety.get_gas_pressed_prev() != prev_panda_gas: self.assertEqual(CS.gasPressed, self.safety.get_gas_pressed_prev()) @@ -397,7 +397,7 @@ class TestCarModelBase(unittest.TestCase): # warm up pass, as initial states may be different for can in self.can_msgs[:300]: - self.CI.update(CC, can_capnp_to_list((can.as_builder().to_bytes(), ))) + self.CI.update(can_capnp_to_list((can.as_builder().to_bytes(), ))) for msg in filter(lambda m: m.src in range(64), can.can): to_send = libpanda_py.make_CANPacket(msg.address, msg.src % 4, msg.dat) self.safety.safety_rx_hook(to_send) @@ -407,7 +407,7 @@ class TestCarModelBase(unittest.TestCase): checks = defaultdict(int) card = Car(CI=self.CI) for idx, can in enumerate(self.can_msgs): - CS = self.CI.update(CC, can_capnp_to_list((can.as_builder().to_bytes(), ))) + CS = self.CI.update(can_capnp_to_list((can.as_builder().to_bytes(), ))) for msg in filter(lambda m: m.src in range(64), can.can): to_send = libpanda_py.make_CANPacket(msg.address, msg.src % 4, msg.dat) ret = self.safety.safety_rx_hook(to_send) diff --git a/selfdrive/car/toyota/interface.py b/selfdrive/car/toyota/interface.py index 236ce104a..3efaa142a 100644 --- a/selfdrive/car/toyota/interface.py +++ b/selfdrive/car/toyota/interface.py @@ -144,7 +144,7 @@ class CarInterface(CarInterfaceBase): disable_ecu(can_recv, can_send, bus=0, addr=0x750, sub_addr=0xf, com_cont_req=communication_control) # returns a car.CarState - def _update(self, c): + def _update(self): ret = self.CS.update(self.cp, self.cp_cam) if self.CP.carFingerprint in (TSS2_CAR - RADAR_ACC_CAR): diff --git a/selfdrive/car/volkswagen/interface.py b/selfdrive/car/volkswagen/interface.py index db6adfe21..dd1a1fd1d 100644 --- a/selfdrive/car/volkswagen/interface.py +++ b/selfdrive/car/volkswagen/interface.py @@ -4,8 +4,6 @@ from openpilot.selfdrive.car import get_safety_config from openpilot.selfdrive.car.interfaces import CarInterfaceBase from openpilot.selfdrive.car.volkswagen.values import CAR, CANBUS, NetworkLocation, TransmissionType, VolkswagenFlags -ButtonType = car.CarState.ButtonEvent.Type - class CarInterface(CarInterfaceBase): def __init__(self, CP, CarController, CarState): @@ -100,7 +98,7 @@ class CarInterface(CarInterfaceBase): return ret # returns a car.CarState - def _update(self, c): + def _update(self): ret = self.CS.update(self.cp, self.cp_cam, self.cp_ext, self.CP.transmissionType) return ret