From 4abda004044c85d137a12013dafd39e36b51f044 Mon Sep 17 00:00:00 2001 From: firestar5683 <168790843+firestar5683@users.noreply.github.com> Date: Mon, 4 May 2026 12:15:57 -0500 Subject: [PATCH] i6 --- .../opendbc/car/hyundai/carcontroller.py | 4 +- opendbc_repo/opendbc/car/hyundai/carstate.py | 5 ++ .../opendbc/car/hyundai/hyundaicanfd.py | 11 +++-- .../opendbc/car/hyundai/tests/test_hyundai.py | 48 +++++++++++++++++++ selfdrive/controls/lib/latcontrol_torque.py | 8 ++-- selfdrive/controls/tests/test_latcontrol.py | 6 +-- 6 files changed, 71 insertions(+), 11 deletions(-) diff --git a/opendbc_repo/opendbc/car/hyundai/carcontroller.py b/opendbc_repo/opendbc/car/hyundai/carcontroller.py index 711bd932e..59b05e9b0 100644 --- a/opendbc_repo/opendbc/car/hyundai/carcontroller.py +++ b/opendbc_repo/opendbc/car/hyundai/carcontroller.py @@ -438,9 +438,11 @@ class CarController(CarControllerBase): use_ioniq_6_smoothed_accel = use_ioniq_6_dynamic_long_tuning and CC.actuators.accel >= self._ioniq_6_long_tuning.actual_accel # steering control + preserve_stock_lkas = self.CP.carFingerprint == CAR.HYUNDAI_IONIQ_6 and not self.long_active_ecu can_sends.extend(hyundaicanfd.create_steering_messages(self.packer, self.CP, self.CAN, CC.enabled, apply_steer_req, apply_torque, apply_angle, - CS.stock_lfa_msg)) + CS.stock_lfa_msg, + CS.stock_lkas_msg if preserve_stock_lkas else None)) # prevent LFA from activating on LKA steering cars by sending "no lane lines detected" to ADAS ECU if self.frame % 5 == 0 and lka_steering: diff --git a/opendbc_repo/opendbc/car/hyundai/carstate.py b/opendbc_repo/opendbc/car/hyundai/carstate.py index 44f528727..cafe7cdd3 100644 --- a/opendbc_repo/opendbc/car/hyundai/carstate.py +++ b/opendbc_repo/opendbc/car/hyundai/carstate.py @@ -89,6 +89,7 @@ class CarState(CarStateBase): self.cruise_info = {} self.msg_364 = {} + self.stock_lkas_msg = {} self.stock_lfa_msg = {} self.stock_lfahda_cluster_msg = {} self.stock_blinker_stalks_ts = 0 @@ -400,8 +401,11 @@ class CarState(CarStateBase): ret.accFaulted = cp.vl["TCS"]["ACCEnable"] != 0 # 0 ACC CONTROL ENABLED, 1-3 ACC CONTROL DISABLED if self.CP.flags & HyundaiFlags.CANFD_LKA_STEERING: + lkas_msg = "LKAS_ALT" if self.CP.flags & HyundaiFlags.CANFD_LKA_STEERING_ALT else "LKAS" self.lfa_block_msg = copy.copy(cp_cam.vl["CAM_0x362"] if self.CP.flags & HyundaiFlags.CANFD_LKA_STEERING_ALT else cp_cam.vl["CAM_0x2a4"]) + if cp_cam.ts_nanos[lkas_msg]["CHECKSUM"] > 0: + self.stock_lkas_msg = copy.copy(cp_cam.vl[lkas_msg]) if cp.ts_nanos["LFA"]["CHECKSUM"] > 0: self.stock_lfa_msg = copy.copy(cp.vl["LFA"]) if cp.ts_nanos["LFAHDA_CLUSTER"]["CHECKSUM"] > 0: @@ -446,6 +450,7 @@ class CarState(CarStateBase): ] if CP.flags & HyundaiFlags.CANFD_LKA_STEERING: msgs.append(("FR_CMR_02_100ms", 10)) + cam_msgs.append(("LKAS_ALT" if CP.flags & HyundaiFlags.CANFD_LKA_STEERING_ALT else "LKAS", 0)) else: cam_msgs.append(("FR_CMR_02_100ms", 0)) # optional: not all non-LKA CANFD cars have this on CAM bus msgs += [ diff --git a/opendbc_repo/opendbc/car/hyundai/hyundaicanfd.py b/opendbc_repo/opendbc/car/hyundai/hyundaicanfd.py index 89863b7ef..37d0f65a1 100644 --- a/opendbc_repo/opendbc/car/hyundai/hyundaicanfd.py +++ b/opendbc_repo/opendbc/car/hyundai/hyundaicanfd.py @@ -91,7 +91,8 @@ def _create_angle_adas_cmd_msg(packer, CAN, apply_angle: float, lat_active: bool return packer.make_can_msg("ADAS_CMD_35_10ms", CAN.ECAN, values) -def create_steering_messages(packer, CP, CAN, enabled, lat_active, apply_torque, apply_angle, lfa_base_values=None): +def create_steering_messages(packer, CP, CAN, enabled, lat_active, apply_torque, apply_angle, + lfa_base_values=None, lkas_base_values=None): control_values = { "LKA_MODE": 2, "LKA_ICON": 2 if enabled else 1, @@ -101,8 +102,12 @@ def create_steering_messages(packer, CP, CAN, enabled, lat_active, apply_torque, "STEER_MODE": 0, } - lkas_values = copy.copy(control_values) - lkas_values["LKA_AVAILABLE"] = 0 + if lkas_base_values: + lkas_values = {k: v for k, v in lkas_base_values.items() if k not in ("CHECKSUM", "COUNTER")} + lkas_values.update(control_values) + else: + lkas_values = copy.copy(control_values) + lkas_values["LKA_AVAILABLE"] = 0 if lfa_base_values: # Preserve stock UI/status fields and only override the actuation-relevant signals. diff --git a/opendbc_repo/opendbc/car/hyundai/tests/test_hyundai.py b/opendbc_repo/opendbc/car/hyundai/tests/test_hyundai.py index fb930afda..cd383e825 100644 --- a/opendbc_repo/opendbc/car/hyundai/tests/test_hyundai.py +++ b/opendbc_repo/opendbc/car/hyundai/tests/test_hyundai.py @@ -586,6 +586,54 @@ class TestHyundaiFingerprint: assert parser.vl["LFA"]["STEER_REQ"] == 1 assert parser.vl["LFA"]["LKA_ICON"] == 2 + def test_ioniq_6_lkas_alt_helper_preserves_stock_camera_fields(self): + CP = CarParams.new_message() + CP.carFingerprint = CAR.HYUNDAI_IONIQ_6 + CP.flags = int(HyundaiFlags.CANFD | HyundaiFlags.CANFD_LKA_STEERING | HyundaiFlags.CANFD_LKA_STEERING_ALT) + + packer = CANPacker(DBC[CP.carFingerprint][Bus.pt]) + can_bus = CanBus(CP) + parser = CANParser(DBC[CP.carFingerprint][Bus.pt], [("LKAS_ALT", 0)], can_bus.ACAN) + + stock_lkas = { + "CHECKSUM": 1234, + "COUNTER": 42, + "LKA_MODE": 6, + "LKA_AVAILABLE": 3, + "LKA_WARNING": 1, + "LKA_ICON": 1, + "FCA_SYSWARN": 1, + "TORQUE_REQUEST": 17, + "STEER_REQ": 0, + "LFA_BUTTON": 1, + "LKA_ASSIST": 1, + "STEER_MODE": 5, + "NEW_SIGNAL_2": 2, + "LKAS_ANGLE_ACTIVE": 1, + "HAS_LANE_SAFETY": 1, + "ADAS_StrAnglReqVal": 12.3, + "ADAS_ACIAnglTqRedcGainVal": 0.42, + "DAMP_FACTOR": 0x70, + } + + msgs = hyundaicanfd.create_steering_messages(packer, CP, can_bus, True, True, 123, 0.0, + lkas_base_values=stock_lkas) + lkas_msgs = [msg for msg in msgs if msg[0] == 0x110] + assert len(lkas_msgs) == 1 + + parser.update([(1, lkas_msgs)]) + + assert parser.can_valid + assert parser.vl["LKAS_ALT"]["LKA_AVAILABLE"] == 3 + assert parser.vl["LKAS_ALT"]["LKA_WARNING"] == 1 + assert parser.vl["LKAS_ALT"]["FCA_SYSWARN"] == 1 + assert parser.vl["LKAS_ALT"]["LFA_BUTTON"] == 1 + assert parser.vl["LKAS_ALT"]["HAS_LANE_SAFETY"] == 1 + assert parser.vl["LKAS_ALT"]["DAMP_FACTOR"] == 0x70 + assert parser.vl["LKAS_ALT"]["TORQUE_REQUEST"] == 123 + assert parser.vl["LKAS_ALT"]["STEER_REQ"] == 1 + assert parser.vl["LKAS_ALT"]["LKA_ICON"] == 2 + def test_ioniq_6_blindspot_status_helper_regenerates_counter_checksum(self): CP = CarParams.new_message() CP.carFingerprint = CAR.HYUNDAI_IONIQ_6 diff --git a/selfdrive/controls/lib/latcontrol_torque.py b/selfdrive/controls/lib/latcontrol_torque.py index b53839348..01fa674bc 100644 --- a/selfdrive/controls/lib/latcontrol_torque.py +++ b/selfdrive/controls/lib/latcontrol_torque.py @@ -222,8 +222,8 @@ GENESIS_G90_UNWIND_FRICTION_REDUCTION_RIGHT = 0.22 IONIQ_6_FF_GAIN_LEFT = 0.040 IONIQ_6_FF_GAIN_RIGHT = 0.000 -IONIQ_6_BASE_LAT_ACCEL_FACTOR_MULT = 1.24 -IONIQ_6_BASE_FRICTION_THRESHOLD = 0.36 +IONIQ_6_BASE_LAT_ACCEL_FACTOR_MULT = 1.23 +IONIQ_6_BASE_FRICTION_THRESHOLD = 0.35 IONIQ_6_FF_ONSET = 0.10 IONIQ_6_FF_ONSET_WIDTH = 0.04 IONIQ_6_FF_CUTOFF = 0.48 @@ -256,9 +256,9 @@ IONIQ_6_LOW_MID_CENTER_TAPER_LAT_WIDTH = 0.06 IONIQ_6_LOW_MID_CENTER_TAPER_SPEED_MIN = 8.5 IONIQ_6_LOW_MID_CENTER_TAPER_SPEED_MAX = 16.5 IONIQ_6_LOW_MID_CENTER_TAPER_SPEED_WIDTH = 1.5 -IONIQ_6_DIRECTIONAL_TAPER_LAT_START = 0.15 +IONIQ_6_DIRECTIONAL_TAPER_LAT_START = 0.19 IONIQ_6_DIRECTIONAL_TAPER_LAT_END = 0.90 -IONIQ_6_DIRECTIONAL_TAPER_LAT_WIDTH = 0.08 +IONIQ_6_DIRECTIONAL_TAPER_LAT_WIDTH = 0.06 IONIQ_6_DIRECTIONAL_TAPER_BASE_LEFT = 0.16 IONIQ_6_DIRECTIONAL_TAPER_BASE_RIGHT = 0.54 IONIQ_6_DIRECTIONAL_TAPER_UNWIND_LEFT = 1.46 diff --git a/selfdrive/controls/tests/test_latcontrol.py b/selfdrive/controls/tests/test_latcontrol.py index 59a7d4e71..e54db8f37 100644 --- a/selfdrive/controls/tests/test_latcontrol.py +++ b/selfdrive/controls/tests/test_latcontrol.py @@ -260,7 +260,7 @@ class TestLatControl: assert get_ioniq_6_output_taper_scale(1.2, 0.0, 25.0) > 0.94 def test_ioniq_6_friction_threshold_curve(self): - base = max(get_friction_threshold(6.0), 0.36) + base = max(get_friction_threshold(6.0), 0.35) left_turn_in = get_ioniq_6_friction_threshold(6.0, 0.5, 0.8) right_turn_in = get_ioniq_6_friction_threshold(6.0, -0.5, -0.8) left_unwind = get_ioniq_6_friction_threshold(6.0, 0.5, -0.8) @@ -268,7 +268,7 @@ class TestLatControl: assert max(left_turn_in, right_turn_in) < base assert left_unwind >= base assert right_unwind >= base - assert get_ioniq_6_friction_threshold(25.0, 0.0, 0.0) >= 0.36 + assert get_ioniq_6_friction_threshold(25.0, 0.0, 0.0) >= 0.35 def test_ioniq_6_friction_scale_curve(self): base = get_ioniq_6_friction_scale(25.0, 0.5, 0.8) @@ -369,7 +369,7 @@ class TestLatControl: _, _, lac_log = controller.update(True, CS, VM, params, False, 0.0025, False, 0.2, None, None, starpilot_toggles) assert lac_log.active - assert controller.torque_params.latAccelFactor == pytest.approx(3.0 * 1.24) + assert controller.torque_params.latAccelFactor == pytest.approx(3.0 * 1.23) def test_ioniq_6_update_path_does_not_post_taper_output(self, monkeypatch): base_controller, VM, CS, params, starpilot_toggles = self._build_torque_controller(HYUNDAI.HYUNDAI_IONIQ_6)