From c607d8aa041b974189dffcbdc83c3ffbb1ff6f61 Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Mon, 5 Aug 2024 17:44:53 -0400 Subject: [PATCH] custom stock long --- selfdrive/car/chrysler/interface.py | 4 +--- selfdrive/car/honda/interface.py | 4 +--- selfdrive/car/hyundai/interface.py | 4 +--- selfdrive/car/interfaces.py | 27 +++++++++++++++++---------- selfdrive/car/mazda/interface.py | 4 +--- selfdrive/car/volkswagen/interface.py | 4 +--- 6 files changed, 22 insertions(+), 25 deletions(-) diff --git a/selfdrive/car/chrysler/interface.py b/selfdrive/car/chrysler/interface.py index 46478742d1..cb2bbccf62 100755 --- a/selfdrive/car/chrysler/interface.py +++ b/selfdrive/car/chrysler/interface.py @@ -161,9 +161,7 @@ class CarInterface(CarInterfaceBase): if self.low_speed_alert: events.add(car.CarEvent.EventName.belowSteerSpeed) - ret.customStockLong = self.CS.update_custom_stock_long(self.CC.cruise_button, self.CC.final_speed_kph, - self.CC.target_speed, self.CC.v_set_dis, - self.CC.speed_diff, self.CC.button_type) + ret.customStockLong = self.update_custom_stock_long() ret.events = events.to_msg() diff --git a/selfdrive/car/honda/interface.py b/selfdrive/car/honda/interface.py index a15a0b4065..3d80470a23 100755 --- a/selfdrive/car/honda/interface.py +++ b/selfdrive/car/honda/interface.py @@ -329,9 +329,7 @@ class CarInterface(CarInterfaceBase): if self.CS.CP.minEnableSpeed > 0 and ret.vEgo < 0.001: events.add(EventName.manualRestart) - ret.customStockLong = self.CS.update_custom_stock_long(self.CC.cruise_button, self.CC.final_speed_kph, - self.CC.target_speed, self.CC.v_set_dis, - self.CC.speed_diff, self.CC.button_type) + ret.customStockLong = self.update_custom_stock_long() ret.events = events.to_msg() diff --git a/selfdrive/car/hyundai/interface.py b/selfdrive/car/hyundai/interface.py index 9af4a0f033..d9aa77c8c1 100644 --- a/selfdrive/car/hyundai/interface.py +++ b/selfdrive/car/hyundai/interface.py @@ -265,9 +265,7 @@ class CarInterface(CarInterfaceBase): if self.low_speed_alert and self.CS.madsEnabled: events.add(car.CarEvent.EventName.belowSteerSpeed) - ret.customStockLong = self.CS.update_custom_stock_long(self.CC.cruise_button, self.CC.final_speed_kph, - self.CC.target_speed, self.CC.v_set_dis, - self.CC.speed_diff, self.CC.button_type) + ret.customStockLong = self.update_custom_stock_long() ret.events = events.to_msg() diff --git a/selfdrive/car/interfaces.py b/selfdrive/car/interfaces.py index 4a951e387e..b1a92aa790 100644 --- a/selfdrive/car/interfaces.py +++ b/selfdrive/car/interfaces.py @@ -734,6 +734,16 @@ class CarInterfaceBase(ABC): return events, cs_out + def update_custom_stock_long(self): + customStockLong = car.CarState.CustomStockLong.new_message() + customStockLong.cruiseButton = 0 if self.CC.cruise_button is None else int(self.CC.cruise_button) + customStockLong.finalSpeedKph = float(self.CC.final_speed_kph) + customStockLong.targetSpeed = float(self.CC.target_speed) + customStockLong.vSetDis = float(self.CC.v_set_dis) + customStockLong.speedDiff = float(self.CC.speed_diff) + customStockLong.buttonType = int(self.CC.button_type) + return customStockLong + class RadarInterfaceBase(ABC): def __init__(self, CP): self.CP = CP @@ -837,16 +847,6 @@ class CarStateBase(ABC): return bool(left_blinker_stalk or self.left_blinker_cnt > 0), bool(right_blinker_stalk or self.right_blinker_cnt > 0) - def update_custom_stock_long(self, cruise_button, final_speed_kph, target_speed, v_set_dis, speed_diff, button_type): - customStockLong = car.CarState.CustomStockLong.new_message() - customStockLong.cruiseButton = 0 if cruise_button is None else cruise_button - customStockLong.finalSpeedKph = final_speed_kph - customStockLong.targetSpeed = target_speed - customStockLong.vSetDis = v_set_dis - customStockLong.speedDiff = speed_diff - customStockLong.buttonType = button_type - return customStockLong - @staticmethod def parse_gear_shifter(gear: str | None) -> car.CarState.GearShifter: if gear is None: @@ -879,6 +879,13 @@ class CarControllerBase(ABC): self.CP = CP self.frame = 0 + self.cruise_button = 0 + self.final_speed_kph = 0.0 + self.target_speed = 0.0 + self.v_set_dis = 0.0 + self.speed_diff = 0.0 + self.button_type = 0 + @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/mazda/interface.py b/selfdrive/car/mazda/interface.py index 7186870bed..5e782f7344 100755 --- a/selfdrive/car/mazda/interface.py +++ b/selfdrive/car/mazda/interface.py @@ -89,9 +89,7 @@ class CarInterface(CarInterfaceBase): if self.CS.low_speed_alert: events.add(EventName.belowSteerSpeed) - ret.customStockLong = self.CS.update_custom_stock_long(self.CC.cruise_button, self.CC.final_speed_kph, - self.CC.target_speed, self.CC.v_set_dis, - self.CC.speed_diff, self.CC.button_type) + ret.customStockLong = self.update_custom_stock_long() ret.events = events.to_msg() diff --git a/selfdrive/car/volkswagen/interface.py b/selfdrive/car/volkswagen/interface.py index f102ea38ec..aa34744fca 100644 --- a/selfdrive/car/volkswagen/interface.py +++ b/selfdrive/car/volkswagen/interface.py @@ -171,9 +171,7 @@ class CarInterface(CarInterfaceBase): if self.CC.eps_timer_soft_disable_alert: events.add(EventName.steerTimeLimit) - ret.customStockLong = self.CS.update_custom_stock_long(self.CC.cruise_button, self.CC.final_speed_kph, - self.CC.target_speed, self.CC.v_set_dis, - self.CC.speed_diff, self.CC.button_type) + ret.customStockLong = self.update_custom_stock_long() ret.events = events.to_msg()