diff --git a/opendbc_repo/opendbc/car/hyundai/carstate.py b/opendbc_repo/opendbc/car/hyundai/carstate.py index 6174a94415..5d0449cfbe 100644 --- a/opendbc_repo/opendbc/car/hyundai/carstate.py +++ b/opendbc_repo/opendbc/car/hyundai/carstate.py @@ -8,7 +8,7 @@ from opendbc.car import Bus, create_button_events, structs from opendbc.car.common.conversions import Conversions as CV from opendbc.car.hyundai.hyundaicanfd import CanBus from opendbc.car.hyundai.values import HyundaiFlags, HyundaiStarPilotFlags, CAR, DBC, Buttons, CarControllerParams, \ - hyundai_cancel_button_enables_cruise, ALT_BUS_LDA_BUTTON_CARS + hyundai_cancel_button_enables_cruise from opendbc.car.interfaces import CarStateBase ButtonType = structs.CarState.ButtonEvent.Type @@ -25,7 +25,6 @@ BUTTONS_DICT = {Buttons.RES_ACCEL: ButtonType.accelCruise, Buttons.SET_DECEL: Bu IONIQ_6_BLINDSPOT_RIGHT_MASK = 0x08 IONIQ_6_BLINDSPOT_LEFT_MASK = 0x10 CANFD_CAMERA_LEAD_MIN_DISTANCE = 0.1 -ALT_BUS_LDA_BUTTON_BURST_DEBOUNCE_NS = int(1.3e9) def get_non_scc_cruise_signals(CP) -> tuple[str, str, str, str, str]: @@ -75,8 +74,6 @@ class CarState(CarStateBase): self.cruise_buttons: deque = deque([Buttons.NONE] * PREV_BUTTON_SAMPLES, maxlen=PREV_BUTTON_SAMPLES) self.main_buttons: deque = deque([Buttons.NONE] * PREV_BUTTON_SAMPLES, maxlen=PREV_BUTTON_SAMPLES) self.lda_button = 0 - self.lda_button_raw = 0 - self.lda_button_last_raw_rise_ts_nanos = 0 self.left_paddle = 0 self.mode_button = 0 self.custom_button = 0 @@ -171,30 +168,9 @@ class CarState(CarStateBase): return False - def create_alt_bus_lda_button_events(self, cp_alt: CANParser) -> list[structs.CarState.ButtonEvent]: - raw_lda_button = int(cp_alt.vl["CLU13"]["CF_Clu_LdwsLkasSW"]) - raw_lda_button_ts_nanos = cp_alt.ts_nanos["CLU13"]["CF_Clu_LdwsLkasSW"] - button_events: list[structs.CarState.ButtonEvent] = [] - - # The G90 cluster pulses this bit multiple times per physical LKAS press burst. - # Collapse each burst into a single synthetic press/release pair so downstream - # button actions behave like a normal momentary wheel button. - if raw_lda_button and not self.lda_button_raw: - if self.lda_button_last_raw_rise_ts_nanos == 0 or \ - raw_lda_button_ts_nanos - self.lda_button_last_raw_rise_ts_nanos > ALT_BUS_LDA_BUTTON_BURST_DEBOUNCE_NS: - button_events = [ - structs.CarState.ButtonEvent(pressed=True, type=ButtonType.lkas), - structs.CarState.ButtonEvent(pressed=False, type=ButtonType.lkas), - ] - self.lda_button_last_raw_rise_ts_nanos = raw_lda_button_ts_nanos - - self.lda_button_raw = raw_lda_button - return button_events - def update(self, can_parsers, starpilot_toggles) -> structs.CarState: cp = can_parsers[Bus.pt] cp_cam = can_parsers[Bus.cam] - cp_alt = can_parsers.get(Bus.alt) if self.CP.flags & HyundaiFlags.CANFD: return self.update_canfd(can_parsers) @@ -328,18 +304,14 @@ class CarState(CarStateBase): prev_cruise_buttons = self.cruise_buttons[-1] prev_main_buttons = self.main_buttons[-1] prev_lda_button = self.lda_button - lkas_button_events = [] self.cruise_buttons.extend(cp.vl_all["CLU11"]["CF_Clu_CruiseSwState"]) self.main_buttons.extend(cp.vl_all["CLU11"]["CF_Clu_CruiseSwMain"]) - if self.CP.carFingerprint in ALT_BUS_LDA_BUTTON_CARS and cp_alt is not None: - lkas_button_events = self.create_alt_bus_lda_button_events(cp_alt) - elif self.CP.flags & HyundaiFlags.HAS_LDA_BUTTON: + if self.CP.flags & HyundaiFlags.HAS_LDA_BUTTON: self.lda_button = cp.vl["BCM_PO_11"]["LDA_BTN"] - lkas_button_events = create_button_events(self.lda_button, prev_lda_button, {1: ButtonType.lkas}) ret.buttonEvents = [*self.create_cruise_button_events(self.cruise_buttons[-1], prev_cruise_buttons), *create_button_events(self.main_buttons[-1], prev_main_buttons, {1: ButtonType.mainCruise}), - *lkas_button_events] + *create_button_events(self.lda_button, prev_lda_button, {1: ButtonType.lkas})] ret.blockPcmEnable = not self.recent_button_interaction() @@ -538,10 +510,7 @@ class CarState(CarStateBase): if CP.flags & HyundaiFlags.NON_SCC and not (CP.flags & HyundaiFlags.NON_SCC_NO_FCA): msgs.append(("FCA11", 0)) # Non-SCC trims can stop publishing FCA11; don't let it poison canValid - parsers = { + return { Bus.pt: CANParser(DBC[CP.carFingerprint][Bus.pt], msgs, 0), Bus.cam: CANParser(DBC[CP.carFingerprint][Bus.pt], [], 2), } - if CP.carFingerprint in ALT_BUS_LDA_BUTTON_CARS: - parsers[Bus.alt] = CANParser(DBC[CP.carFingerprint][Bus.pt], [("CLU13", 0)], 1) - return parsers diff --git a/opendbc_repo/opendbc/car/hyundai/interface.py b/opendbc_repo/opendbc/car/hyundai/interface.py index 20be4c02af..c159e11433 100644 --- a/opendbc_repo/opendbc/car/hyundai/interface.py +++ b/opendbc_repo/opendbc/car/hyundai/interface.py @@ -5,7 +5,7 @@ from opendbc.car.hyundai.values import HyundaiFlags, CAR, DBC, CarControllerPara CANFD_UNSUPPORTED_LONGITUDINAL_CAR, \ CANFD_SECURITYACCESS_CAR, \ UNSUPPORTED_LONGITUDINAL_CAR, HyundaiSafetyFlags, \ - hyundai_cancel_button_enables_cruise, ALT_BUS_LDA_BUTTON_CARS + hyundai_cancel_button_enables_cruise from opendbc.car.hyundai.radar_interface import RADAR_START_ADDR from opendbc.car.interfaces import CarInterfaceBase, ACCEL_MIN from opendbc.car.disable_ecu import disable_ecu, ecu_log @@ -139,7 +139,7 @@ class CarInterface(CarInterfaceBase): ret.safetyConfigs[0].safetyParam |= HyundaiSafetyFlags.CAMERA_SCC.value # These cars have the LFA button on the steering wheel - if candidate in ALT_BUS_LDA_BUTTON_CARS or 0x391 in fingerprint[0] or ret.flags & HyundaiFlags.CAN_CANFD_BLENDED: + if 0x391 in fingerprint[0] or ret.flags & HyundaiFlags.CAN_CANFD_BLENDED: ret.flags |= HyundaiFlags.HAS_LDA_BUTTON.value if ret.flags & HyundaiFlags.CAN_CANFD_BLENDED: ret.safetyConfigs[-1].safetyParam |= HyundaiSafetyFlags.CAN_CANFD_BLENDED.value diff --git a/opendbc_repo/opendbc/car/hyundai/tests/test_hyundai.py b/opendbc_repo/opendbc/car/hyundai/tests/test_hyundai.py index 1b25409054..3d65dd6db3 100644 --- a/opendbc_repo/opendbc/car/hyundai/tests/test_hyundai.py +++ b/opendbc_repo/opendbc/car/hyundai/tests/test_hyundai.py @@ -10,8 +10,7 @@ from opendbc.car.fw_versions import build_fw_dict, match_fw_to_car from opendbc.car.hyundai.carcontroller import CarController, Ioniq6LongitudinalTuningState, GenesisG90LongitudinalTuningState, \ update_ioniq_6_longitudinal_tuning, \ update_genesis_g90_longitudinal_tuning -from opendbc.car.hyundai.carstate import CarState, decode_canfd_camera_lead, decode_ioniq_6_blindspot_radar_state, \ - ALT_BUS_LDA_BUTTON_BURST_DEBOUNCE_NS +from opendbc.car.hyundai.carstate import CarState, decode_canfd_camera_lead, decode_ioniq_6_blindspot_radar_state from opendbc.car.hyundai.interface import CarInterface from opendbc.car.hyundai import hyundaican, hyundaicanfd from opendbc.car.hyundai.hyundaicanfd import CanBus @@ -19,8 +18,7 @@ from opendbc.car.hyundai.radar_interface import RADAR_START_ADDR from opendbc.car.hyundai.values import CAMERA_SCC_CAR, CANFD_CAR, CAN_GEARS, CAR, CHECKSUM, DATE_FW_ECUS, \ HYBRID_CAR, EV_CAR, FW_QUERY_CONFIG, LEGACY_SAFETY_MODE_CAR, CANFD_FUZZY_WHITELIST, \ UNSUPPORTED_LONGITUDINAL_CAR, PLATFORM_CODE_ECUS, HYUNDAI_VERSION_REQUEST_LONG, \ - CarControllerParams, DBC, HyundaiFlags, get_platform_codes, HyundaiSafetyFlags, Buttons, \ - HyundaiStarPilotSafetyFlags + CarControllerParams, DBC, HyundaiFlags, get_platform_codes, HyundaiSafetyFlags, Buttons LongCtrlState = CarControl.Actuators.LongControlState from opendbc.car.hyundai.fingerprints import FW_VERSIONS @@ -211,47 +209,6 @@ class TestHyundaiFingerprint: assert CP.vEgoStopping == pytest.approx(0.8) assert CP.stoppingDecelRate == pytest.approx(0.55) - def test_genesis_g90_sets_has_lkas_button_flag(self): - toggles = get_test_toggles() - CP = CarInterface.get_params(CAR.GENESIS_G90, gen_empty_fingerprint(), [], True, False, False, toggles) - FPCP = CarInterface.get_starpilot_params(CAR.GENESIS_G90, gen_empty_fingerprint(), [], CP, toggles) - - assert CP.flags & HyundaiFlags.HAS_LDA_BUTTON - assert FPCP.safetyConfigs[-1].safetyParam & HyundaiStarPilotSafetyFlags.HAS_LDA_BUTTON - - def test_genesis_g90_lkas_button_uses_clu13_on_alt_bus(self): - toggles = get_test_toggles() - CP = CarInterface.get_params(CAR.GENESIS_G90, gen_empty_fingerprint(), [], True, False, False, toggles) - FPCP = CarInterface.get_starpilot_params(CAR.GENESIS_G90, gen_empty_fingerprint(), [], CP, toggles) - - car_state = CarState(CP, FPCP) - can_parsers = car_state.get_can_parsers(CP) - packer = CANPacker(DBC[CP.carFingerprint][Bus.pt]) - - assert Bus.alt in can_parsers - - can_parsers[Bus.alt].update([(1, [packer.make_can_msg("CLU13", 1, {"CF_Clu_LdwsLkasSW": 1})])]) - ret, _ = car_state.update(can_parsers, toggles) - assert [(be.type, be.pressed) for be in ret.buttonEvents] == [(ButtonType.lkas, True), (ButtonType.lkas, False)] - - can_parsers[Bus.alt].update([(2, [packer.make_can_msg("CLU13", 1, {"CF_Clu_LdwsLkasSW": 0})])]) - ret, _ = car_state.update(can_parsers, toggles) - assert len(ret.buttonEvents) == 0 - - can_parsers[Bus.alt].update([(3, [packer.make_can_msg("CLU13", 1, {"CF_Clu_LdwsLkasSW": 1})])]) - ret, _ = car_state.update(can_parsers, toggles) - assert len(ret.buttonEvents) == 0 - - quiet_ts = ALT_BUS_LDA_BUTTON_BURST_DEBOUNCE_NS + 3 - can_parsers[Bus.alt].update([(quiet_ts, [packer.make_can_msg("CLU13", 1, {"CF_Clu_LdwsLkasSW": 0})])]) - ret, _ = car_state.update(can_parsers, toggles) - assert len(ret.buttonEvents) == 0 - - next_press_ts = ALT_BUS_LDA_BUTTON_BURST_DEBOUNCE_NS + 4 - can_parsers[Bus.alt].update([(next_press_ts, [packer.make_can_msg("CLU13", 1, {"CF_Clu_LdwsLkasSW": 1})])]) - ret, _ = car_state.update(can_parsers, toggles) - assert [(be.type, be.pressed) for be in ret.buttonEvents] == [(ButtonType.lkas, True), (ButtonType.lkas, False)] - def test_palisade_2023_longitudinal_params_soften_final_stop_hold(self): toggles = get_test_toggles() CP = CarInterface.get_params(CAR.HYUNDAI_PALISADE_2023, gen_empty_fingerprint(), [], True, False, False, toggles) diff --git a/opendbc_repo/opendbc/car/hyundai/values.py b/opendbc_repo/opendbc/car/hyundai/values.py index 60d7f1d52b..87ca27d91e 100644 --- a/opendbc_repo/opendbc/car/hyundai/values.py +++ b/opendbc_repo/opendbc/car/hyundai/values.py @@ -759,11 +759,6 @@ CANCEL_BUTTON_ENABLE_CARS = frozenset({ }) -ALT_BUS_LDA_BUTTON_CARS = frozenset({ - CAR.GENESIS_G90, -}) - - def hyundai_cancel_button_enables_cruise(car_fingerprint) -> bool: return car_fingerprint in CANCEL_BUTTON_ENABLE_CARS