From d3f6c2d6eb06e5457811edcdebc4efb3d339c34d Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Wed, 24 Apr 2024 17:00:13 -0400 Subject: [PATCH] Support Driving Personality change --- selfdrive/car/hyundai/carcontroller.py | 2 +- selfdrive/car/hyundai/hyundaicanfd.py | 8 +++++--- selfdrive/car/hyundai/values.py | 7 +++++++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/selfdrive/car/hyundai/carcontroller.py b/selfdrive/car/hyundai/carcontroller.py index 1f738c394f..e7c7430c18 100644 --- a/selfdrive/car/hyundai/carcontroller.py +++ b/selfdrive/car/hyundai/carcontroller.py @@ -138,7 +138,7 @@ class CarController(CarControllerBase): if can_canfd: can_sends.extend(hyundaicanfd.create_acc_commands_can_canfd(self.packer, self.CAN, CC.enabled, accel, int(self.frame / 2), hud_control.leadVisible, - set_speed_in_units, stopping, CC.cruiseControl.override)) + set_speed_in_units, stopping, CC.cruiseControl.override, hud_control)) else: can_sends.append(hyundaicanfd.create_acc_control(self.packer, self.CAN, CC.enabled, self.accel_last, accel, stopping, CC.cruiseControl.override, set_speed_in_units, hud_control)) diff --git a/selfdrive/car/hyundai/hyundaicanfd.py b/selfdrive/car/hyundai/hyundaicanfd.py index 6de9dfc755..8ca1d1c8c6 100644 --- a/selfdrive/car/hyundai/hyundaicanfd.py +++ b/selfdrive/car/hyundai/hyundaicanfd.py @@ -1,7 +1,9 @@ from openpilot.common.numpy_fast import clip from openpilot.selfdrive.car import CanBusBase from openpilot.selfdrive.car.hyundai.hyundaican import hyundai_checksum -from openpilot.selfdrive.car.hyundai.values import HyundaiFlags +from openpilot.selfdrive.car.hyundai.values import HyundaiFlags, TauGapSetCanCanfd + +DISTANCE_DICT_CAN_CANFD = {3: TauGapSetCanCanfd.DISTANCE_3, 2: TauGapSetCanCanfd.DISTANCE_2, 1: TauGapSetCanCanfd.DISTANCE_1} class CanBus(CanBusBase): @@ -192,7 +194,7 @@ def create_acc_control(packer, CAN, enabled, accel_last, accel, stopping, gas_ov return packer.make_can_msg("SCC_CONTROL", CAN.ECAN, values) -def create_acc_commands_can_canfd(packer, CAN, enabled, accel, idx, lead_visible, set_speed, stopping, long_override): +def create_acc_commands_can_canfd(packer, CAN, enabled, accel, idx, lead_visible, set_speed, stopping, long_override, hud_control): ret = [] msg_values = [ @@ -205,7 +207,7 @@ def create_acc_commands_can_canfd(packer, CAN, enabled, accel, idx, lead_visible ("SCC12", { "MainMode_ACC": 1, - "TauGapSet": 6, + "TauGapSet": DISTANCE_DICT_CAN_CANFD.get(hud_control.leadDistanceBars, TauGapSetCanCanfd.DISTANCE_3), "VSetDis": set_speed if enabled else 0, "ObjValid": 0, "ACC_ObjDist": 1, diff --git a/selfdrive/car/hyundai/values.py b/selfdrive/car/hyundai/values.py index f3073812eb..8ed9c2a7a9 100644 --- a/selfdrive/car/hyundai/values.py +++ b/selfdrive/car/hyundai/values.py @@ -563,6 +563,13 @@ class Buttons: CANCEL = 4 # on newer models, this is a pause/resume button +class TauGapSetCanCanfd: + DISTANCE_4 = 1 + DISTANCE_3 = 0 + DISTANCE_2 = 7 + DISTANCE_1 = 6 + + def get_platform_codes(fw_versions: list[bytes]) -> set[tuple[bytes, bytes | None]]: # Returns unique, platform-specific identification codes for a set of versions codes = set() # (code-Optional[part], date)