From 35a99d7fc685b3e8a08a01fe305c3144934eec00 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Tue, 13 Aug 2024 22:59:25 -0700 Subject: [PATCH] Common CI._update function (#33289) * use CP * no car control, consistent _update function signatures * eh it's fine to name it whatever * clean up * oops * !! * now we can delete this! * nobody does anymore old-commit-hash: 7248b00086f9b8d5d95c80a2eb7fe89c387f44ea --- selfdrive/car/body/carstate.py | 2 +- selfdrive/car/body/interface.py | 3 --- selfdrive/car/chrysler/carstate.py | 2 +- selfdrive/car/chrysler/interface.py | 3 --- selfdrive/car/ford/carstate.py | 2 +- selfdrive/car/ford/interface.py | 3 --- selfdrive/car/gm/carstate.py | 2 +- selfdrive/car/gm/interface.py | 4 ---- selfdrive/car/honda/carstate.py | 2 +- selfdrive/car/honda/interface.py | 4 ---- selfdrive/car/hyundai/carstate.py | 2 +- selfdrive/car/hyundai/interface.py | 3 --- selfdrive/car/interfaces.py | 5 ++--- selfdrive/car/mazda/carstate.py | 2 +- selfdrive/car/mazda/interface.py | 4 ---- selfdrive/car/mock/interface.py | 3 --- selfdrive/car/nissan/carstate.py | 2 +- selfdrive/car/nissan/interface.py | 4 ---- selfdrive/car/subaru/carstate.py | 2 +- selfdrive/car/subaru/interface.py | 4 ---- selfdrive/car/tesla/carstate.py | 2 +- selfdrive/car/tesla/interface.py | 3 --- selfdrive/car/toyota/carstate.py | 2 +- selfdrive/car/toyota/interface.py | 4 ---- selfdrive/car/volkswagen/carstate.py | 19 +++++++++++-------- selfdrive/car/volkswagen/interface.py | 16 +--------------- 26 files changed, 25 insertions(+), 79 deletions(-) diff --git a/selfdrive/car/body/carstate.py b/selfdrive/car/body/carstate.py index e0e710b116..1c981a6c6e 100644 --- a/selfdrive/car/body/carstate.py +++ b/selfdrive/car/body/carstate.py @@ -5,7 +5,7 @@ from openpilot.selfdrive.car.body.values import DBC class CarState(CarStateBase): - def update(self, cp): + def update(self, cp, *_): ret = car.CarState.new_message() ret.wheelSpeeds.fl = cp.vl['MOTORS_DATA']['SPEED_L'] diff --git a/selfdrive/car/body/interface.py b/selfdrive/car/body/interface.py index a22c7b6a27..68509aa246 100644 --- a/selfdrive/car/body/interface.py +++ b/selfdrive/car/body/interface.py @@ -24,6 +24,3 @@ class CarInterface(CarInterfaceBase): ret.steerControlType = car.CarParams.SteerControlType.angle return ret - - def _update(self): - return self.CS.update(self.cp) diff --git a/selfdrive/car/chrysler/carstate.py b/selfdrive/car/chrysler/carstate.py index 33d76767bf..216e6f7891 100644 --- a/selfdrive/car/chrysler/carstate.py +++ b/selfdrive/car/chrysler/carstate.py @@ -26,7 +26,7 @@ class CarState(CarStateBase): self.distance_button = 0 - def update(self, cp, cp_cam): + def update(self, cp, cp_cam, *_): ret = car.CarState.new_message() diff --git a/selfdrive/car/chrysler/interface.py b/selfdrive/car/chrysler/interface.py index 44ed2049c0..21e752889e 100755 --- a/selfdrive/car/chrysler/interface.py +++ b/selfdrive/car/chrysler/interface.py @@ -73,6 +73,3 @@ class CarInterface(CarInterfaceBase): ret.enableBsm = 720 in fingerprint[0] return ret - - def _update(self): - return self.CS.update(self.cp, self.cp_cam) diff --git a/selfdrive/car/ford/carstate.py b/selfdrive/car/ford/carstate.py index 984b241a65..6d1e4ae5dc 100644 --- a/selfdrive/car/ford/carstate.py +++ b/selfdrive/car/ford/carstate.py @@ -21,7 +21,7 @@ class CarState(CarStateBase): self.distance_button = 0 - def update(self, cp, cp_cam): + def update(self, cp, cp_cam, *_): ret = car.CarState.new_message() # Occasionally on startup, the ABS module recalibrates the steering pinion offset, so we need to block engagement diff --git a/selfdrive/car/ford/interface.py b/selfdrive/car/ford/interface.py index 0180f5948e..4021f583c1 100644 --- a/selfdrive/car/ford/interface.py +++ b/selfdrive/car/ford/interface.py @@ -64,6 +64,3 @@ class CarInterface(CarInterfaceBase): ret.autoResumeSng = ret.minEnableSpeed == -1. ret.centerToFront = ret.wheelbase * 0.44 return ret - - def _update(self): - return self.CS.update(self.cp, self.cp_cam) diff --git a/selfdrive/car/gm/carstate.py b/selfdrive/car/gm/carstate.py index b6f3ad5ebb..2efe2b41e6 100644 --- a/selfdrive/car/gm/carstate.py +++ b/selfdrive/car/gm/carstate.py @@ -34,7 +34,7 @@ class CarState(CarStateBase): self.distance_button = 0 - def update(self, pt_cp, cam_cp, loopback_cp): + def update(self, pt_cp, cam_cp, _, __, loopback_cp): ret = car.CarState.new_message() prev_cruise_buttons = self.cruise_buttons diff --git a/selfdrive/car/gm/interface.py b/selfdrive/car/gm/interface.py index ba93318911..1026fe97cd 100755 --- a/selfdrive/car/gm/interface.py +++ b/selfdrive/car/gm/interface.py @@ -193,7 +193,3 @@ class CarInterface(CarInterfaceBase): CarInterfaceBase.configure_torque_tune(candidate, ret.lateralTuning) return ret - - # returns a car.CarState - def _update(self): - return self.CS.update(self.cp, self.cp_cam, self.cp_loopback) diff --git a/selfdrive/car/honda/carstate.py b/selfdrive/car/honda/carstate.py index 97c4bd2eb2..d8ecba8303 100644 --- a/selfdrive/car/honda/carstate.py +++ b/selfdrive/car/honda/carstate.py @@ -110,7 +110,7 @@ class CarState(CarStateBase): # However, on cars without a digital speedometer this is not always present (HRV, FIT, CRV 2016, ILX and RDX) self.dash_speed_seen = False - def update(self, cp, cp_cam, cp_body): + def update(self, cp, cp_cam, _, cp_body, __): ret = car.CarState.new_message() # car params diff --git a/selfdrive/car/honda/interface.py b/selfdrive/car/honda/interface.py index 711577355b..c6c25ae359 100755 --- a/selfdrive/car/honda/interface.py +++ b/selfdrive/car/honda/interface.py @@ -214,7 +214,3 @@ class CarInterface(CarInterfaceBase): def init(CP, can_recv, can_send): if CP.carFingerprint in (HONDA_BOSCH - HONDA_BOSCH_RADARLESS) and CP.openpilotLongitudinalControl: disable_ecu(can_recv, can_send, bus=1, addr=0x18DAB0F1, com_cont_req=b'\x28\x83\x03') - - # returns a car.CarState - def _update(self): - return self.CS.update(self.cp, self.cp_cam, self.cp_body) diff --git a/selfdrive/car/hyundai/carstate.py b/selfdrive/car/hyundai/carstate.py index 0cc0a6e1a9..a2940a3b91 100644 --- a/selfdrive/car/hyundai/carstate.py +++ b/selfdrive/car/hyundai/carstate.py @@ -58,7 +58,7 @@ class CarState(CarStateBase): self.params = CarControllerParams(CP) - def update(self, cp, cp_cam): + def update(self, cp, cp_cam, *_): if self.CP.carFingerprint in CANFD_CAR: return self.update_canfd(cp, cp_cam) diff --git a/selfdrive/car/hyundai/interface.py b/selfdrive/car/hyundai/interface.py index 38d6603bff..923c84d4b2 100644 --- a/selfdrive/car/hyundai/interface.py +++ b/selfdrive/car/hyundai/interface.py @@ -146,6 +146,3 @@ class CarInterface(CarInterfaceBase): # for blinkers 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): - return self.CS.update(self.cp, self.cp_cam) diff --git a/selfdrive/car/interfaces.py b/selfdrive/car/interfaces.py index 58f814c0ef..ae0df0123c 100644 --- a/selfdrive/car/interfaces.py +++ b/selfdrive/car/interfaces.py @@ -217,9 +217,8 @@ class CarInterfaceBase(ABC): tune.torque.latAccelOffset = 0.0 tune.torque.steeringAngleDeadzoneDeg = steering_angle_deadzone_deg - @abstractmethod def _update(self) -> car.CarState: - pass + return self.CS.update(*self.can_parsers) def update(self, can_packets: list[tuple[int, list[CanData]]]) -> car.CarState: # parse can @@ -292,7 +291,7 @@ class CarStateBase(ABC): self.v_ego_kf = KF1D(x0=x0, A=A, C=C[0], K=K) @abstractmethod - def update(self, *args) -> car.CarState: + def update(self, cp, cp_cam, cp_adas, cp_body, cp_loopback) -> car.CarState: pass def update_speed_kf(self, v_ego_raw): diff --git a/selfdrive/car/mazda/carstate.py b/selfdrive/car/mazda/carstate.py index a55d02a8d8..1693d167be 100644 --- a/selfdrive/car/mazda/carstate.py +++ b/selfdrive/car/mazda/carstate.py @@ -24,7 +24,7 @@ class CarState(CarStateBase): self.distance_button = 0 - def update(self, cp, cp_cam): + def update(self, cp, cp_cam, *_): ret = car.CarState.new_message() diff --git a/selfdrive/car/mazda/interface.py b/selfdrive/car/mazda/interface.py index a4e1ffe413..e37fca384a 100755 --- a/selfdrive/car/mazda/interface.py +++ b/selfdrive/car/mazda/interface.py @@ -28,7 +28,3 @@ class CarInterface(CarInterfaceBase): ret.centerToFront = ret.wheelbase * 0.41 return ret - - # returns a car.CarState - def _update(self): - return self.CS.update(self.cp, self.cp_cam) diff --git a/selfdrive/car/mock/interface.py b/selfdrive/car/mock/interface.py index 44cd40d28c..95887b4442 100755 --- a/selfdrive/car/mock/interface.py +++ b/selfdrive/car/mock/interface.py @@ -14,6 +14,3 @@ class CarInterface(CarInterfaceBase): ret.steerRatio = 13. ret.dashcamOnly = True return ret - - def _update(self): - return self.CS.update() diff --git a/selfdrive/car/nissan/carstate.py b/selfdrive/car/nissan/carstate.py index 32ac8014eb..9da8e8d4ba 100644 --- a/selfdrive/car/nissan/carstate.py +++ b/selfdrive/car/nissan/carstate.py @@ -26,7 +26,7 @@ class CarState(CarStateBase): self.distance_button = 0 - def update(self, cp, cp_adas, cp_cam): + def update(self, cp, cp_cam, cp_adas, *_): ret = car.CarState.new_message() prev_distance_button = self.distance_button diff --git a/selfdrive/car/nissan/interface.py b/selfdrive/car/nissan/interface.py index a12e28231b..c3418cabe6 100644 --- a/selfdrive/car/nissan/interface.py +++ b/selfdrive/car/nissan/interface.py @@ -25,7 +25,3 @@ class CarInterface(CarInterfaceBase): ret.safetyConfigs[0].safetyParam |= Panda.FLAG_NISSAN_ALT_EPS_BUS return ret - - # returns a car.CarState - def _update(self): - return self.CS.update(self.cp, self.cp_adas, self.cp_cam) diff --git a/selfdrive/car/subaru/carstate.py b/selfdrive/car/subaru/carstate.py index 7751785f0f..125d589928 100644 --- a/selfdrive/car/subaru/carstate.py +++ b/selfdrive/car/subaru/carstate.py @@ -16,7 +16,7 @@ class CarState(CarStateBase): self.angle_rate_calulator = CanSignalRateCalculator(50) - def update(self, cp, cp_cam, cp_body): + def update(self, cp, cp_cam, _, cp_body, __): ret = car.CarState.new_message() throttle_msg = cp.vl["Throttle"] if not (self.CP.flags & SubaruFlags.HYBRID) else cp_body.vl["Throttle_Hybrid"] diff --git a/selfdrive/car/subaru/interface.py b/selfdrive/car/subaru/interface.py index 0eb7d0be3f..c733ef291b 100644 --- a/selfdrive/car/subaru/interface.py +++ b/selfdrive/car/subaru/interface.py @@ -96,10 +96,6 @@ class CarInterface(CarInterfaceBase): return ret - # returns a car.CarState - def _update(self): - return self.CS.update(self.cp, self.cp_cam, self.cp_body) - @staticmethod def init(CP, can_recv, can_send): if CP.flags & SubaruFlags.DISABLE_EYESIGHT: diff --git a/selfdrive/car/tesla/carstate.py b/selfdrive/car/tesla/carstate.py index 262ac7add1..71e891b9bd 100644 --- a/selfdrive/car/tesla/carstate.py +++ b/selfdrive/car/tesla/carstate.py @@ -21,7 +21,7 @@ class CarState(CarStateBase): self.acc_state = 0 self.das_control_counters = deque(maxlen=32) - def update(self, cp, cp_cam): + def update(self, cp, cp_cam, *_): ret = car.CarState.new_message() # Vehicle speed diff --git a/selfdrive/car/tesla/interface.py b/selfdrive/car/tesla/interface.py index e31ae28604..118987e2ef 100755 --- a/selfdrive/car/tesla/interface.py +++ b/selfdrive/car/tesla/interface.py @@ -38,6 +38,3 @@ class CarInterface(CarInterfaceBase): ret.steerLimitTimer = 1.0 ret.steerActuatorDelay = 0.25 return ret - - def _update(self): - return self.CS.update(self.cp, self.cp_cam) diff --git a/selfdrive/car/toyota/carstate.py b/selfdrive/car/toyota/carstate.py index ed0ece4997..fd8306ef11 100644 --- a/selfdrive/car/toyota/carstate.py +++ b/selfdrive/car/toyota/carstate.py @@ -49,7 +49,7 @@ class CarState(CarStateBase): self.acc_type = 1 self.lkas_hud = {} - def update(self, cp, cp_cam): + def update(self, cp, cp_cam, *_): ret = car.CarState.new_message() ret.doorOpen = any([cp.vl["BODY_CONTROL_STATE"]["DOOR_OPEN_FL"], cp.vl["BODY_CONTROL_STATE"]["DOOR_OPEN_FR"], diff --git a/selfdrive/car/toyota/interface.py b/selfdrive/car/toyota/interface.py index bf26d01de6..fb63ab557b 100644 --- a/selfdrive/car/toyota/interface.py +++ b/selfdrive/car/toyota/interface.py @@ -141,7 +141,3 @@ class CarInterface(CarInterfaceBase): if CP.flags & ToyotaFlags.DISABLE_RADAR.value: communication_control = bytes([uds.SERVICE_TYPE.COMMUNICATION_CONTROL, uds.CONTROL_TYPE.ENABLE_RX_DISABLE_TX, uds.MESSAGE_TYPE.NORMAL]) 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): - return self.CS.update(self.cp, self.cp_cam) diff --git a/selfdrive/car/volkswagen/carstate.py b/selfdrive/car/volkswagen/carstate.py index 3f3683329c..31343887a4 100644 --- a/selfdrive/car/volkswagen/carstate.py +++ b/selfdrive/car/volkswagen/carstate.py @@ -32,9 +32,12 @@ class CarState(CarStateBase): return button_events - def update(self, pt_cp, cam_cp, ext_cp, trans_type): + def update(self, pt_cp, cam_cp, *_): + + ext_cp = pt_cp if self.CP.networkLocation == NetworkLocation.fwdCamera else cam_cp + if self.CP.flags & VolkswagenFlags.PQ: - return self.update_pq(pt_cp, cam_cp, ext_cp, trans_type) + return self.update_pq(pt_cp, cam_cp, ext_cp) ret = car.CarState.new_message() # Update vehicle speed and acceleration from ABS wheel speeds. @@ -73,11 +76,11 @@ class CarState(CarStateBase): ret.parkingBrake = bool(pt_cp.vl["Kombi_01"]["KBI_Handbremse"]) # FIXME: need to include an EPB check as well # Update gear and/or clutch position data. - if trans_type == TransmissionType.automatic: + if self.CP.transmissionType == TransmissionType.automatic: ret.gearShifter = self.parse_gear_shifter(self.CCP.shifter_values.get(pt_cp.vl["Getriebe_11"]["GE_Fahrstufe"], None)) - elif trans_type == TransmissionType.direct: + elif self.CP.transmissionType == TransmissionType.direct: ret.gearShifter = self.parse_gear_shifter(self.CCP.shifter_values.get(pt_cp.vl["EV_Gearshift"]["GearPosition"], None)) - elif trans_type == TransmissionType.manual: + elif self.CP.transmissionType == TransmissionType.manual: ret.clutchPressed = not pt_cp.vl["Motor_14"]["MO_Kuppl_schalter"] if bool(pt_cp.vl["Gateway_72"]["BCM1_Rueckfahrlicht_Schalter"]): ret.gearShifter = GearShifter.reverse @@ -155,7 +158,7 @@ class CarState(CarStateBase): self.frame += 1 return ret - def update_pq(self, pt_cp, cam_cp, ext_cp, trans_type): + def update_pq(self, pt_cp, cam_cp, ext_cp): ret = car.CarState.new_message() # Update vehicle speed and acceleration from ABS wheel speeds. ret.wheelSpeeds = self.get_wheel_speeds( @@ -187,9 +190,9 @@ class CarState(CarStateBase): ret.parkingBrake = bool(pt_cp.vl["Kombi_1"]["Bremsinfo"]) # Update gear and/or clutch position data. - if trans_type == TransmissionType.automatic: + if self.CP.transmissionType == TransmissionType.automatic: ret.gearShifter = self.parse_gear_shifter(self.CCP.shifter_values.get(pt_cp.vl["Getriebe_1"]["Waehlhebelposition__Getriebe_1_"], None)) - elif trans_type == TransmissionType.manual: + elif self.CP.transmissionType == TransmissionType.manual: ret.clutchPressed = not pt_cp.vl["Motor_1"]["Kupplungsschalter"] reverse_light = bool(pt_cp.vl["Gate_Komf_1"]["GK1_Rueckfahr"]) if reverse_light: diff --git a/selfdrive/car/volkswagen/interface.py b/selfdrive/car/volkswagen/interface.py index 015f9b81d9..48656d5e82 100644 --- a/selfdrive/car/volkswagen/interface.py +++ b/selfdrive/car/volkswagen/interface.py @@ -2,20 +2,10 @@ from cereal import car from panda import Panda 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 +from openpilot.selfdrive.car.volkswagen.values import CAR, NetworkLocation, TransmissionType, VolkswagenFlags class CarInterface(CarInterfaceBase): - def __init__(self, CP, CarController, CarState): - super().__init__(CP, CarController, CarState) - - if CP.networkLocation == NetworkLocation.fwdCamera: - self.ext_bus = CANBUS.pt - self.cp_ext = self.cp - else: - self.ext_bus = CANBUS.cam - self.cp_ext = self.cp_cam - @staticmethod def _get_params(ret, candidate: CAR, fingerprint, car_fw, experimental_long, docs): ret.carName = "volkswagen" @@ -96,7 +86,3 @@ class CarInterface(CarInterfaceBase): ret.autoResumeSng = ret.minEnableSpeed == -1 return ret - - # returns a car.CarState - def _update(self): - return self.CS.update(self.cp, self.cp_cam, self.cp_ext, self.CP.transmissionType)