From 7de437c621b2c55074aa4e627a649e00b40633f6 Mon Sep 17 00:00:00 2001 From: royjr Date: Tue, 22 Oct 2024 11:55:20 -0400 Subject: [PATCH 01/26] init --- opendbc/car/hyundai/carstate.py | 2 +- opendbc/car/hyundai/fingerprints.py | 8 ++++++++ opendbc/car/hyundai/values.py | 7 +++++++ opendbc/car/torque_data/override.toml | 1 + 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/opendbc/car/hyundai/carstate.py b/opendbc/car/hyundai/carstate.py index 9406d858fb..094dac1877 100644 --- a/opendbc/car/hyundai/carstate.py +++ b/opendbc/car/hyundai/carstate.py @@ -218,7 +218,7 @@ def update_canfd(self, cp, cp_cam) -> structs.CarState: # TODO: alt signal usage may be described by cp.vl['BLINKERS']['USE_ALT_LAMP'] left_blinker_sig, right_blinker_sig = "LEFT_LAMP", "RIGHT_LAMP" - if self.CP.carFingerprint == CAR.HYUNDAI_KONA_EV_2ND_GEN: + if self.CP.carFingerprint in (CAR.HYUNDAI_KONA_EV_2ND_GEN, CAR.HYUNDAI_SONATA_HEV_2024): left_blinker_sig, right_blinker_sig = "LEFT_LAMP_ALT", "RIGHT_LAMP_ALT" ret.leftBlinker, ret.rightBlinker = self.update_blinker_from_lamp(50, cp.vl["BLINKERS"][left_blinker_sig], cp.vl["BLINKERS"][right_blinker_sig]) diff --git a/opendbc/car/hyundai/fingerprints.py b/opendbc/car/hyundai/fingerprints.py index 7496e2bff0..0bf67abe90 100644 --- a/opendbc/car/hyundai/fingerprints.py +++ b/opendbc/car/hyundai/fingerprints.py @@ -936,6 +936,14 @@ b'\xf1\x00DN8HMFC AT USA LHD 1.00 1.07 99211-L1000 211223', ], }, + CAR.HYUNDAI_SONATA_HEV_2024: { + (Ecu.fwdRadar, 0x7d0, None): [ + b'\xf1\x00DN8_ RDR ----- 1.00 1.00 99110-L1800 ', + ], + (Ecu.fwdCamera, 0x7c4, None): [ + b'\xf1\x00DN8HMFC AT USA LHD 1.00 1.01 99211-L1800 230512', + ], + }, CAR.KIA_SORENTO: { (Ecu.fwdCamera, 0x7c4, None): [ b'\xf1\x00UMP LKAS AT KOR LHD 1.00 1.00 95740-C5550 S30', diff --git a/opendbc/car/hyundai/values.py b/opendbc/car/hyundai/values.py index 2eeb337636..81caa709ee 100644 --- a/opendbc/car/hyundai/values.py +++ b/opendbc/car/hyundai/values.py @@ -307,6 +307,13 @@ class CAR(Platforms): HYUNDAI_SONATA.specs, flags=HyundaiFlags.MANDO_RADAR | HyundaiFlags.CHECKSUM_CRC8 | HyundaiFlags.HYBRID, ) + HYUNDAI_SONATA_HEV_2024 = HyundaiCanFDPlatformConfig( + [HyundaiCarDocs("Hyundai Sonata Hybrid 2024", "All", car_parts=CarParts.common([CarHarness.hyundai_a]))], + CarSpecs(mass=1616, wheelbase=2.84, steerRatio=13.27 * 1.15, tireStiffnessFactor=0.65), + flags=HyundaiFlags.HYBRID, + # TODO: confirm steerRatio increase + # TODO: confirm tireStiffnessFactor + ) HYUNDAI_IONIQ_5 = HyundaiCanFDPlatformConfig( [ HyundaiCarDocs("Hyundai Ioniq 5 (Non-US only) 2022-24", "All", car_parts=CarParts.common([CarHarness.hyundai_q])), diff --git a/opendbc/car/torque_data/override.toml b/opendbc/car/torque_data/override.toml index aad06e8e3e..571cb32fd5 100644 --- a/opendbc/car/torque_data/override.toml +++ b/opendbc/car/torque_data/override.toml @@ -72,6 +72,7 @@ legend = ["LAT_ACCEL_FACTOR", "MAX_LAT_ACCEL_MEASURED", "FRICTION"] "HYUNDAI_STARIA_4TH_GEN" = [1.8, 2.0, 0.15] "GENESIS_GV70_ELECTRIFIED_1ST_GEN" = [1.9, 1.9, 0.09] "GENESIS_G80_2ND_GEN_FL" = [2.5819356441497803, 2.5, 0.11244568973779678] +"HYUNDAI_SONATA_HEV_2024" = [2.5, 2.5, 0.1] # Dashcam or fallback configured as ideal car "MOCK" = [10.0, 10, 0.0] From 55239df4eb4522a6809b46e080cb7378022f81d3 Mon Sep 17 00:00:00 2001 From: royjr Date: Sun, 3 Nov 2024 20:31:37 -0500 Subject: [PATCH 02/26] remove hybrid flag --- opendbc/car/hyundai/values.py | 1 - 1 file changed, 1 deletion(-) diff --git a/opendbc/car/hyundai/values.py b/opendbc/car/hyundai/values.py index 81caa709ee..bcf1e9e226 100644 --- a/opendbc/car/hyundai/values.py +++ b/opendbc/car/hyundai/values.py @@ -310,7 +310,6 @@ class CAR(Platforms): HYUNDAI_SONATA_HEV_2024 = HyundaiCanFDPlatformConfig( [HyundaiCarDocs("Hyundai Sonata Hybrid 2024", "All", car_parts=CarParts.common([CarHarness.hyundai_a]))], CarSpecs(mass=1616, wheelbase=2.84, steerRatio=13.27 * 1.15, tireStiffnessFactor=0.65), - flags=HyundaiFlags.HYBRID, # TODO: confirm steerRatio increase # TODO: confirm tireStiffnessFactor ) From 2fca39078f04c4f1da637f28b7e1c78adfc585c5 Mon Sep 17 00:00:00 2001 From: royjr Date: Thu, 7 Nov 2024 18:34:34 -0500 Subject: [PATCH 03/26] Update routes.py --- opendbc/car/tests/routes.py | 1 + 1 file changed, 1 insertion(+) diff --git a/opendbc/car/tests/routes.py b/opendbc/car/tests/routes.py index 2e1eca29a0..5039455bbe 100644 --- a/opendbc/car/tests/routes.py +++ b/opendbc/car/tests/routes.py @@ -180,6 +180,7 @@ class CarTestRoute(NamedTuple): CarTestRoute("82e9cdd3f43bf83e|2021-05-15--02-42-51", HYUNDAI.HYUNDAI_ELANTRA_2021), CarTestRoute("715ac05b594e9c59|2021-06-20--16-21-07", HYUNDAI.HYUNDAI_ELANTRA_HEV_2021), CarTestRoute("7120aa90bbc3add7|2021-08-02--07-12-31", HYUNDAI.HYUNDAI_SONATA_HYBRID), + CarTestRoute("bc40c72b728178f2/000000d2--d08ba01f7d", HYUNDAI.HYUNDAI_SONATA_HEV_2024), CarTestRoute("715ac05b594e9c59|2021-10-27--23-24-56", HYUNDAI.GENESIS_G70_2020), CarTestRoute("6b0d44d22df18134|2023-05-06--10-36-55", HYUNDAI.GENESIS_GV80), From faabf235a6c8825df68cb4fab6a5efcde696a46b Mon Sep 17 00:00:00 2001 From: royjr Date: Sat, 9 Nov 2024 13:12:06 -0500 Subject: [PATCH 04/26] better route --- opendbc/car/tests/routes.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opendbc/car/tests/routes.py b/opendbc/car/tests/routes.py index 5039455bbe..4e7b445cc0 100644 --- a/opendbc/car/tests/routes.py +++ b/opendbc/car/tests/routes.py @@ -180,7 +180,7 @@ class CarTestRoute(NamedTuple): CarTestRoute("82e9cdd3f43bf83e|2021-05-15--02-42-51", HYUNDAI.HYUNDAI_ELANTRA_2021), CarTestRoute("715ac05b594e9c59|2021-06-20--16-21-07", HYUNDAI.HYUNDAI_ELANTRA_HEV_2021), CarTestRoute("7120aa90bbc3add7|2021-08-02--07-12-31", HYUNDAI.HYUNDAI_SONATA_HYBRID), - CarTestRoute("bc40c72b728178f2/000000d2--d08ba01f7d", HYUNDAI.HYUNDAI_SONATA_HEV_2024), + CarTestRoute("bc40c72b728178f2/00000006--ee76ae8c42", HYUNDAI.HYUNDAI_SONATA_HEV_2024), CarTestRoute("715ac05b594e9c59|2021-10-27--23-24-56", HYUNDAI.GENESIS_G70_2020), CarTestRoute("6b0d44d22df18134|2023-05-06--10-36-55", HYUNDAI.GENESIS_GV80), From 36853811fa2517d53cd64a64d32289e2329eef65 Mon Sep 17 00:00:00 2001 From: royjr Date: Thu, 21 Nov 2024 17:50:17 -0500 Subject: [PATCH 05/26] remove todo --- opendbc/car/hyundai/values.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/opendbc/car/hyundai/values.py b/opendbc/car/hyundai/values.py index 8fa474307b..e0eae939da 100644 --- a/opendbc/car/hyundai/values.py +++ b/opendbc/car/hyundai/values.py @@ -310,8 +310,6 @@ class CAR(Platforms): HYUNDAI_SONATA_HEV_2024 = HyundaiCanFDPlatformConfig( [HyundaiCarDocs("Hyundai Sonata Hybrid 2024", "All", car_parts=CarParts.common([CarHarness.hyundai_a]))], CarSpecs(mass=1616, wheelbase=2.84, steerRatio=13.27 * 1.15, tireStiffnessFactor=0.65), - # TODO: confirm steerRatio increase - # TODO: confirm tireStiffnessFactor ) HYUNDAI_IONIQ_5 = HyundaiCanFDPlatformConfig( [ From 35689ca74120c113c8fce0a3478d0eae7a0df5fa Mon Sep 17 00:00:00 2001 From: royjr Date: Thu, 21 Nov 2024 17:50:31 -0500 Subject: [PATCH 06/26] use default tireStiffnessFactor --- opendbc/car/hyundai/values.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opendbc/car/hyundai/values.py b/opendbc/car/hyundai/values.py index e0eae939da..9239341825 100644 --- a/opendbc/car/hyundai/values.py +++ b/opendbc/car/hyundai/values.py @@ -309,7 +309,7 @@ class CAR(Platforms): ) HYUNDAI_SONATA_HEV_2024 = HyundaiCanFDPlatformConfig( [HyundaiCarDocs("Hyundai Sonata Hybrid 2024", "All", car_parts=CarParts.common([CarHarness.hyundai_a]))], - CarSpecs(mass=1616, wheelbase=2.84, steerRatio=13.27 * 1.15, tireStiffnessFactor=0.65), + CarSpecs(mass=1616, wheelbase=2.84, steerRatio=13.27 * 1.15), ) HYUNDAI_IONIQ_5 = HyundaiCanFDPlatformConfig( [ From 6874314ce8d426409f6b658f6aeb608c646d6702 Mon Sep 17 00:00:00 2001 From: royjr Date: Thu, 21 Nov 2024 17:50:48 -0500 Subject: [PATCH 07/26] remove steerRatio factor --- opendbc/car/hyundai/values.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opendbc/car/hyundai/values.py b/opendbc/car/hyundai/values.py index 9239341825..e0468da998 100644 --- a/opendbc/car/hyundai/values.py +++ b/opendbc/car/hyundai/values.py @@ -309,7 +309,7 @@ class CAR(Platforms): ) HYUNDAI_SONATA_HEV_2024 = HyundaiCanFDPlatformConfig( [HyundaiCarDocs("Hyundai Sonata Hybrid 2024", "All", car_parts=CarParts.common([CarHarness.hyundai_a]))], - CarSpecs(mass=1616, wheelbase=2.84, steerRatio=13.27 * 1.15), + CarSpecs(mass=1616, wheelbase=2.84, steerRatio=13.27), ) HYUNDAI_IONIQ_5 = HyundaiCanFDPlatformConfig( [ From 77c11a66f2f6d99b8f3bbbec8ccaef9b8a8850f6 Mon Sep 17 00:00:00 2001 From: royjr Date: Thu, 28 Nov 2024 18:06:34 -0500 Subject: [PATCH 08/26] add new messages --- opendbc/dbc/hyundai_canfd.dbc | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/opendbc/dbc/hyundai_canfd.dbc b/opendbc/dbc/hyundai_canfd.dbc index 1ef67c044a..1802ef92f6 100644 --- a/opendbc/dbc/hyundai_canfd.dbc +++ b/opendbc/dbc/hyundai_canfd.dbc @@ -658,6 +658,19 @@ BO_ 1264 LOCAL_TIME: 8 XXX SG_ MINUTES : 21|6@0+ (1,0) [0|63] "" XXX SG_ SECONDS : 31|8@0+ (1,0) [0|59] "" XXX +BO_ 353 NEW_MSG_161: 32 XXX + SG_ CHECKSUM : 0|16@1+ (1,0) [0|65535] "" XXX + SG_ COUNTER : 16|8@1+ (1,0) [0|255] "" XXX + SG_ LKA_ICON : 30|2@1+ (1,0) [0|3] "" XXX + SG_ SSC_CONDITIONS_NOT_MET : 154|1@0+ (1,0) [0|1] "" XXX + SG_ LFA_ICON : 224|1@0+ (1,0) [0|1] "" XXX + +BO_ 354 NEW_MSG_162: 32 XXX + SG_ CHECKSUM : 0|16@1+ (1,0) [0|65535] "" XXX + SG_ COUNTER : 16|8@1+ (1,0) [0|255] "" XXX + SG_ FAULT_1 : 219|1@0+ (1,0) [0|1] "" XXX + SG_ FAULT_2 : 246|1@0+ (1,0) [0|1] "" XXX + CM_ 272 "Alternative LKAS message, used on cars such as 2023 Ioniq 6, 2nd gen Kona. Matches LKAS except size is 32 bytes"; CM_ 676 "Contains signals with detailed lane line information. Used by ADAS ECU on HDA 2 vehicles to operate LFA."; CM_ 866 "Contains signals with detailed lane line information. Used by ADAS ECU on HDA 2 vehicles to operate LFA. Used on cars that use message 272."; From fc402f627f26de93ad4d0e44ca4aefef29a0a8ce Mon Sep 17 00:00:00 2001 From: royjr Date: Thu, 28 Nov 2024 18:11:50 -0500 Subject: [PATCH 09/26] block faults --- opendbc/car/hyundai/carcontroller.py | 1 + opendbc/car/hyundai/carstate.py | 8 +++++++- opendbc/car/hyundai/hyundaicanfd.py | 8 ++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/opendbc/car/hyundai/carcontroller.py b/opendbc/car/hyundai/carcontroller.py index b0ef691edc..c66379051e 100644 --- a/opendbc/car/hyundai/carcontroller.py +++ b/opendbc/car/hyundai/carcontroller.py @@ -117,6 +117,7 @@ def update(self, CC, CS, now_nanos): # LFA and HDA icons if self.frame % 5 == 0 and (not hda2 or hda2_long): can_sends.append(hyundaicanfd.create_lfahda_cluster(self.packer, self.CAN, CC.enabled)) + can_sends.append(hyundaicanfd.block_faults(self.packer, self.CAN, CC.enabled, CS.block_faults)) # blinkers if hda2 and self.CP.flags & HyundaiFlags.ENABLE_BLINKERS: diff --git a/opendbc/car/hyundai/carstate.py b/opendbc/car/hyundai/carstate.py index 9f63bbec3e..9938ea7505 100644 --- a/opendbc/car/hyundai/carstate.py +++ b/opendbc/car/hyundai/carstate.py @@ -50,6 +50,7 @@ def __init__(self, CP): self.buttons_counter = 0 self.cruise_info = {} + self.block_faults = {} # On some cars, CLU15->CF_Clu_VehicleSpeed can oscillate faster than the dash updates. Sample at 5 Hz self.cluster_speed = 0 @@ -267,6 +268,8 @@ def update_canfd(self, can_parsers) -> structs.CarState: ret.buttonEvents = [*create_button_events(self.cruise_buttons[-1], prev_cruise_buttons, BUTTONS_DICT), *create_button_events(self.main_buttons[-1], prev_main_buttons, {1: ButtonType.mainCruise})] + self.block_faults = copy.copy(cp_cam.vl["NEW_MSG_162"]) + return ret def get_can_parsers_canfd(self, CP): @@ -314,7 +317,10 @@ def get_can_parsers_canfd(self, CP): cam_messages += [ ("SCC_CONTROL", 50), ] - + cam_messages += [ + ("NEW_MSG_162", 20), + ] + return { Bus.pt: CANParser(DBC[CP.carFingerprint][Bus.pt], pt_messages, CanBus(CP).ECAN), Bus.cam: CANParser(DBC[CP.carFingerprint][Bus.pt], cam_messages, CanBus(CP).CAM), diff --git a/opendbc/car/hyundai/hyundaicanfd.py b/opendbc/car/hyundai/hyundaicanfd.py index d3488ff531..cc3db25070 100644 --- a/opendbc/car/hyundai/hyundaicanfd.py +++ b/opendbc/car/hyundai/hyundaicanfd.py @@ -119,6 +119,14 @@ def create_lfahda_cluster(packer, CAN, enabled): } return packer.make_can_msg("LFAHDA_CLUSTER", CAN.ECAN, values) +def block_faults(packer, CAN, enabled, block_faults): + values = {s: block_faults[s] for s in block_faults.keys()} + values.update({ + "FAULT_1": 0, + "FAULT_2": 0, + }) + return packer.make_can_msg("NEW_MSG_162", CAN.ECAN, values) + def create_acc_control(packer, CAN, enabled, accel_last, accel, stopping, gas_override, set_speed, hud_control): jerk = 5 From d8d59a2e0c3e39c0d3099ae454709ee3b7ef125f Mon Sep 17 00:00:00 2001 From: royjr Date: Thu, 28 Nov 2024 18:38:27 -0500 Subject: [PATCH 10/26] fix whitespace --- opendbc/car/hyundai/carstate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opendbc/car/hyundai/carstate.py b/opendbc/car/hyundai/carstate.py index 9938ea7505..bfdb5e5dfc 100644 --- a/opendbc/car/hyundai/carstate.py +++ b/opendbc/car/hyundai/carstate.py @@ -320,7 +320,7 @@ def get_can_parsers_canfd(self, CP): cam_messages += [ ("NEW_MSG_162", 20), ] - + return { Bus.pt: CANParser(DBC[CP.carFingerprint][Bus.pt], pt_messages, CanBus(CP).ECAN), Bus.cam: CANParser(DBC[CP.carFingerprint][Bus.pt], cam_messages, CanBus(CP).CAM), From 85c4b40fb0cf20c9d8db8672fff097774de1ef2c Mon Sep 17 00:00:00 2001 From: royjr Date: Fri, 6 Dec 2024 11:54:56 -0500 Subject: [PATCH 11/26] better messages --- opendbc/dbc/hyundai_canfd.dbc | 107 ++++++++++++++++++++++++++++++---- 1 file changed, 95 insertions(+), 12 deletions(-) diff --git a/opendbc/dbc/hyundai_canfd.dbc b/opendbc/dbc/hyundai_canfd.dbc index 1802ef92f6..01dded3ccb 100644 --- a/opendbc/dbc/hyundai_canfd.dbc +++ b/opendbc/dbc/hyundai_canfd.dbc @@ -658,18 +658,101 @@ BO_ 1264 LOCAL_TIME: 8 XXX SG_ MINUTES : 21|6@0+ (1,0) [0|63] "" XXX SG_ SECONDS : 31|8@0+ (1,0) [0|59] "" XXX -BO_ 353 NEW_MSG_161: 32 XXX - SG_ CHECKSUM : 0|16@1+ (1,0) [0|65535] "" XXX - SG_ COUNTER : 16|8@1+ (1,0) [0|255] "" XXX - SG_ LKA_ICON : 30|2@1+ (1,0) [0|3] "" XXX - SG_ SSC_CONDITIONS_NOT_MET : 154|1@0+ (1,0) [0|1] "" XXX - SG_ LFA_ICON : 224|1@0+ (1,0) [0|1] "" XXX - -BO_ 354 NEW_MSG_162: 32 XXX - SG_ CHECKSUM : 0|16@1+ (1,0) [0|65535] "" XXX - SG_ COUNTER : 16|8@1+ (1,0) [0|255] "" XXX - SG_ FAULT_1 : 219|1@0+ (1,0) [0|1] "" XXX - SG_ FAULT_2 : 246|1@0+ (1,0) [0|1] "" XXX +BO_ 353 MSG_161: 32 CCNC + SG_ CHECKSUM : 0|16@1+ (1,0) [0|65535] "" XXX + SG_ COUNTER : 16|8@1+ (1,0) [0|255] "" XXX + SG_ FCA_ICON : 24|3@1+ (1,0) [0|7] "" XXX + SG_ FCA_ALT_ICON : 27|3@1+ (1,0) [0|7] "" XXX + SG_ LKA_ICON : 30|3@1+ (1,0) [0|3] "" XXX + SG_ HBA_ICON : 33|3@1+ (1,0) [0|7] "" XXX + SG_ ZEROS_1 : 36|4@1+ (1,0) [0|15] "" XXX + SG_ ZEROS_2 : 40|2@1+ (1,0) [0|3] "" XXX + SG_ FCA_IMAGE : 42|3@1+ (1,0) [0|7] "" XXX + SG_ ZEROS_3 : 45|3@1+ (1,0) [0|7] "" XXX + SG_ ZEROS_4 : 48|3@1+ (1,0) [0|7] "" XXX + SG_ BCA_LEFT : 51|3@1+ (1,0) [0|7] "" XXX + SG_ BCA_RIGHT : 54|3@1+ (1,0) [0|7] "" XXX + SG_ LCA_LEFT_ARROW : 57|3@1+ (1,0) [0|7] "" XXX + SG_ LCA_RIGHT_ARROW : 60|3@1+ (1,0) [0|7] "" XXX + SG_ ZEROS_5 : 63|1@0+ (1,0) [0|1] "" XXX + SG_ CENTERLINE : 64|2@1+ (1,0) [0|3] "" XXX + SG_ TARGET : 66|3@1+ (1,0) [0|7] "" XXX + SG_ TARGET_POSITION : 69|11@1+ (1,0) [0|7] "" XXX + SG_ LANELINE_LEFT : 80|4@1+ (1,0) [0|15] "" XXX + SG_ LANELINE_LEFT_POSITION : 84|6@1+ (1,0) [0|15] "" XXX + SG_ LANELINE_RIGHT : 90|4@1+ (1,0) [0|15] "" XXX + SG_ LANELINE_RIGHT_POSITION : 94|6@1+ (1,0) [0|3] "" XXX + SG_ LANELINE_CURVATURE : 100|5@1- (1,15) [0|31] "" XXX + SG_ LANE_HIGHLIGHT : 105|4@1+ (1,0) [0|15] "" XXX + SG_ LANE_HIGHLIGHT_DISTANCE : 109|11@1+ (1,0) [0|7] "" XXX + SG_ LANE_LEFT : 120|3@1+ (1,0) [0|7] "" XXX + SG_ LANE_RIGHT : 123|3@1+ (1,0) [0|7] "" XXX + SG_ LANE_ZOOM : 126|2@1+ (1,0) [0|3] "" XXX + SG_ ALERTS_1 : 128|6@1+ (1,0) [0|63] "" XXX + SG_ ALERTS_2 : 134|5@1+ (1,0) [0|3] "" XXX + SG_ ALERTS_3 : 139|4@1+ (1,0) [0|15] "" XXX + SG_ ALERTS_4 : 143|9@1+ (1,0) [0|511] "" XXX + SG_ ALERTS_5 : 152|5@1+ (1,0) [0|7] "" XXX + SG_ MUTE : 157|3@1+ (1,0) [0|7] "" XXX + SG_ SOUNDS_1 : 160|4@1+ (1,0) [0|3] "" XXX + SG_ SOUNDS_2 : 164|4@1+ (1,0) [0|3] "" XXX + SG_ SOUNDS_3 : 168|4@1+ (1,0) [0|15] "" XXX + SG_ SOUNDS_4 : 172|3@1+ (1,0) [0|7] "" XXX + SG_ ZEROS_6 : 175|1@0+ (1,0) [0|1] "" XXX + SG_ ZEROS_7 : 176|5@1+ (1,0) [0|31] "" XXX + SG_ SETSPEED_HUD : 181|3@1+ (1,0) [0|3] "" XXX + SG_ DISTANCE_LEAD : 184|5@1+ (1,0) [0|31] "" XXX + SG_ DISTANCE_CAR : 189|3@1+ (1,0) [0|7] "" XXX + SG_ DISTANCE_SPACING : 192|4@1+ (1,0) [0|15] "" XXX + SG_ DISTANCE : 196|4@1+ (1,0) [0|7] "" XXX + SG_ SETSPEED_SPEED : 200|8@1+ (1,0) [0|255] "" XXX + SG_ SETSPEED : 208|4@1+ (1,0) [0|3] "" XXX + SG_ HDA_ICON : 212|4@1+ (1,0) [0|3] "" XXX + SG_ SHIFT_ICON : 216|4@1+ (1,0) [0|15] "" XXX + SG_ NAV_ICON : 220|4@1+ (1,0) [0|3] "" XXX + SG_ LFA_ICON : 224|4@1+ (1,0) [0|3] "" XXX + SG_ LCA_LEFT_ICON : 228|4@1+ (1,0) [0|15] "" XXX + SG_ LCA_RIGHT_ICON : 232|4@1+ (1,0) [0|15] "" XXX + SG_ BACKGROUND : 236|4@1+ (1,0) [0|15] "" XXX + SG_ DAW_ICON : 240|3@1+ (1,0) [0|7] "" XXX + SG_ CAR_CIRCLE : 243|3@1+ (1,0) [0|7] "" XXX + SG_ ZEROS_8 : 246|2@1+ (1,0) [0|3] "" XXX + SG_ ZEROS_9 : 248|8@1+ (1,0) [0|255] "" XXX + +BO_ 354 MSG_162: 32 CCNC + SG_ CHECKSUM : 0|16@1+ (1,0) [0|65535] "" XXX + SG_ COUNTER : 16|8@1+ (1,0) [0|255] "" XXX + SG_ SPEEDLIMIT_STYLE : 24|4@1+ (1,0) [0|7] "" XXX + SG_ SPEEDLIMIT_FLASH : 28|4@1+ (1,0) [0|15] "" XXX + SG_ SPEEDLIMIT : 32|8@1+ (1,0) [0|255] "" XXX + SG_ SIGNS : 40|8@1+ (1,0) [0|15] "" XXX + SG_ SPEEDLIMIT_WEATHER : 48|4@1+ (1,0) [0|15] "" XXX + SG_ VIBRATE : 52|3@1+ (1,0) [0|7] "" XXX + SG_ LEAD : 64|5@1+ (1,0) [0|31] "" XXX + SG_ LEAD_DISTANCE : 69|11@1+ (1,0) [0|2047] "" XXX + SG_ LEAD_LATERAL : 80|7@1+ (1,0) [0|127] "" XXX + SG_ LEAD2 : 88|5@1+ (1,0) [0|31] "" XXX + SG_ LEAD2_DISTANCE : 93|11@1+ (1,0) [0|2047] "" XXX + SG_ LEAD2_LATERAL : 104|7@1+ (1,0) [0|127] "" XXX + SG_ LEAD3 : 112|5@1+ (1,0) [0|31] "" XXX + SG_ LEAD3_DISTANCE : 117|11@1+ (1,0) [0|2047] "" XXX + SG_ LEAD3_LATERAL : 128|7@1+ (1,0) [0|127] "" XXX + SG_ LEAD4 : 136|5@1+ (1,0) [0|31] "" XXX + SG_ LEAD4_DISTANCE : 141|11@1+ (1,0) [0|2047] "" XXX + SG_ LEAD4_LATERAL : 152|7@1+ (1,0) [0|127] "" XXX + SG_ FAULT_FSS : 213|3@1+ (1,0) [0|7] "" XXX + SG_ FAULT_FCA : 216|3@1+ (1,0) [0|7] "" XXX + SG_ FAULT_LSS : 219|3@1+ (1,0) [0|7] "" XXX + SG_ FAULT_SLA : 222|3@1+ (1,0) [0|7] "" XXX + SG_ FAULT_DAW : 225|3@1+ (1,0) [0|7] "" XXX + SG_ FAULT_HBA : 228|3@1+ (1,0) [0|7] "" XXX + SG_ FAULT_SCC : 231|3@1+ (1,0) [0|7] "" XXX + SG_ FAULT_LFA : 234|3@1+ (1,0) [0|7] "" XXX + SG_ FAULT_HDA : 237|3@1+ (1,0) [0|7] "" XXX + SG_ FAULT_LCA : 240|3@1+ (1,0) [0|7] "" XXX + SG_ FAULT_HDP : 243|3@1+ (1,0) [0|7] "" XXX + SG_ FAULT_DAS : 246|3@1+ (1,0) [0|7] "" XXX + SG_ FAULT_ESS : 249|3@1+ (1,0) [0|7] "" XXX CM_ 272 "Alternative LKAS message, used on cars such as 2023 Ioniq 6, 2nd gen Kona. Matches LKAS except size is 32 bytes"; CM_ 676 "Contains signals with detailed lane line information. Used by ADAS ECU on HDA 2 vehicles to operate LFA."; From 2fb07dd239b4dd84df2b7147f359e78498aaf68e Mon Sep 17 00:00:00 2001 From: royjr Date: Fri, 6 Dec 2024 11:56:02 -0500 Subject: [PATCH 12/26] Update carcontroller.py --- opendbc/car/hyundai/carcontroller.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/opendbc/car/hyundai/carcontroller.py b/opendbc/car/hyundai/carcontroller.py index c66379051e..13334cef13 100644 --- a/opendbc/car/hyundai/carcontroller.py +++ b/opendbc/car/hyundai/carcontroller.py @@ -115,9 +115,11 @@ def update(self, CC, CS, now_nanos): self.CP.flags & HyundaiFlags.CANFD_HDA2_ALT_STEERING)) # LFA and HDA icons - if self.frame % 5 == 0 and (not hda2 or hda2_long): + if self.frame % 5 == 0 and (not hda2 or hda2_long) and self.car_fingerprint not in (CAR.HYUNDAI_SONATA_HEV_2024,): can_sends.append(hyundaicanfd.create_lfahda_cluster(self.packer, self.CAN, CC.enabled)) - can_sends.append(hyundaicanfd.block_faults(self.packer, self.CAN, CC.enabled, CS.block_faults)) + if self.frame % 5 == 0 and (not hda2 or hda2_long) and self.car_fingerprint in (CAR.HYUNDAI_SONATA_HEV_2024,): + can_sends.append(hyundaicanfd.create_msg_161(self.packer, self.CAN, CC.enabled, CS.msg_161)) + can_sends.append(hyundaicanfd.create_msg_162(self.packer, self.CAN, CC.enabled, CS.msg_162)) # blinkers if hda2 and self.CP.flags & HyundaiFlags.ENABLE_BLINKERS: From 7db6b7f8ea5ffe08edb2421141e9308e052cbfb9 Mon Sep 17 00:00:00 2001 From: royjr Date: Fri, 6 Dec 2024 11:56:45 -0500 Subject: [PATCH 13/26] Update carstate.py --- opendbc/car/hyundai/carstate.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/opendbc/car/hyundai/carstate.py b/opendbc/car/hyundai/carstate.py index bfdb5e5dfc..ac0fccf0e7 100644 --- a/opendbc/car/hyundai/carstate.py +++ b/opendbc/car/hyundai/carstate.py @@ -50,7 +50,8 @@ def __init__(self, CP): self.buttons_counter = 0 self.cruise_info = {} - self.block_faults = {} + self.msg_161 = {} + self.msg_162 = {} # On some cars, CLU15->CF_Clu_VehicleSpeed can oscillate faster than the dash updates. Sample at 5 Hz self.cluster_speed = 0 @@ -230,8 +231,9 @@ def update_canfd(self, can_parsers) -> structs.CarState: ret.leftBlinker, ret.rightBlinker = self.update_blinker_from_lamp(50, cp.vl["BLINKERS"][left_blinker_sig], cp.vl["BLINKERS"][right_blinker_sig]) if self.CP.enableBsm: - ret.leftBlindspot = cp.vl["BLINDSPOTS_REAR_CORNERS"]["FL_INDICATOR"] != 0 - ret.rightBlindspot = cp.vl["BLINDSPOTS_REAR_CORNERS"]["FR_INDICATOR"] != 0 + alt = "_ALT" if self.CP.carFingerprint == CAR.HYUNDAI_SONATA_HEV_2024 else "" + ret.leftBlindspot = cp.vl["BLINDSPOTS_REAR_CORNERS"][f"FL_INDICATOR{alt}"] != 0 + ret.rightBlindspot = cp.vl["BLINDSPOTS_REAR_CORNERS"][f"FR_INDICATOR{alt}"] != 0 # cruise state # CAN FD cars enable on main button press, set available if no TCS faults preventing engagement @@ -268,7 +270,9 @@ def update_canfd(self, can_parsers) -> structs.CarState: ret.buttonEvents = [*create_button_events(self.cruise_buttons[-1], prev_cruise_buttons, BUTTONS_DICT), *create_button_events(self.main_buttons[-1], prev_main_buttons, {1: ButtonType.mainCruise})] - self.block_faults = copy.copy(cp_cam.vl["NEW_MSG_162"]) + if self.CP.carFingerprint in (CAR.HYUNDAI_SONATA_HEV_2024,): + self.msg_161 = copy.copy(cp_cam.vl["MSG_161"]) + self.msg_162 = copy.copy(cp_cam.vl["MSG_162"]) return ret @@ -317,9 +321,11 @@ def get_can_parsers_canfd(self, CP): cam_messages += [ ("SCC_CONTROL", 50), ] - cam_messages += [ - ("NEW_MSG_162", 20), - ] + if self.CP.carFingerprint in (CAR.HYUNDAI_SONATA_HEV_2024,): + cam_messages += [ + ("MSG_161", 20), + ("MSG_162", 20), + ] return { Bus.pt: CANParser(DBC[CP.carFingerprint][Bus.pt], pt_messages, CanBus(CP).ECAN), From c4f23f56bc0de58d9dfe6add03231c0b929dffe9 Mon Sep 17 00:00:00 2001 From: royjr Date: Fri, 6 Dec 2024 11:58:11 -0500 Subject: [PATCH 14/26] Update hyundaicanfd.py --- opendbc/car/hyundai/hyundaicanfd.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/opendbc/car/hyundai/hyundaicanfd.py b/opendbc/car/hyundai/hyundaicanfd.py index cc3db25070..f090e923ff 100644 --- a/opendbc/car/hyundai/hyundaicanfd.py +++ b/opendbc/car/hyundai/hyundaicanfd.py @@ -119,14 +119,27 @@ def create_lfahda_cluster(packer, CAN, enabled): } return packer.make_can_msg("LFAHDA_CLUSTER", CAN.ECAN, values) -def block_faults(packer, CAN, enabled, block_faults): - values = {s: block_faults[s] for s in block_faults.keys()} +def create_msg_161(packer, CAN, enabled, msg_161): + values = msg_161.copy() values.update({ - "FAULT_1": 0, - "FAULT_2": 0, + "LFA_ICON": 2 if enabled else 0, + "LKA_ICON": 4 if enabled else 0, + "DAW_ICON": 0, }) - return packer.make_can_msg("NEW_MSG_162", CAN.ECAN, values) - + if values.get("ALERTS_5") == 5: # use_switch_or_pedal_to_accelerate + values["ALERTS_5"] = 0 + if values.get("ALERTS_2") == 5: # coffee + values.update({"ALERTS_2": 0, "SOUNDS_2": 0}) + return packer.make_can_msg("MSG_161", CAN.ECAN, values) + +def create_msg_162(packer, CAN, enabled, msg_162): + values = msg_162.copy() + values.update({ + "FAULT_LSS": 0, + "FAULT_HDA": 0, + "FAULT_DAS": 0, + }) + return packer.make_can_msg("MSG_162", CAN.ECAN, values) def create_acc_control(packer, CAN, enabled, accel_last, accel, stopping, gas_override, set_speed, hud_control): jerk = 5 From 290a358e140137cc77b76ea5428e6e857cfe007e Mon Sep 17 00:00:00 2001 From: royjr Date: Fri, 6 Dec 2024 12:12:40 -0500 Subject: [PATCH 15/26] add blindspot alt --- opendbc/dbc/hyundai_canfd.dbc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/opendbc/dbc/hyundai_canfd.dbc b/opendbc/dbc/hyundai_canfd.dbc index 01dded3ccb..900a04e21d 100644 --- a/opendbc/dbc/hyundai_canfd.dbc +++ b/opendbc/dbc/hyundai_canfd.dbc @@ -599,6 +599,8 @@ BO_ 442 BLINDSPOTS_REAR_CORNERS: 24 XXX SG_ FL_INDICATOR : 46|6@0+ (1,0) [0|1] "" XXX SG_ FR_INDICATOR : 54|6@0+ (1,0) [0|63] "" XXX SG_ RIGHT_BLOCKED : 64|1@0+ (1,0) [0|1] "" XXX + SG_ FL_INDICATOR_ALT : 138|1@0+ (1,0) [0|1] "" XXX + SG_ FR_INDICATOR_ALT : 141|1@0+ (1,0) [0|1] "" XXX BO_ 874 BLINDSPOTS_FRONT_CORNER_2: 16 XXX SG_ COUNTER : 16|8@1+ (1,0) [0|255] "" XXX From 61c5db079f1dbc86256b775e06ca428a6dce32d6 Mon Sep 17 00:00:00 2001 From: royjr Date: Sat, 7 Dec 2024 16:05:37 -0500 Subject: [PATCH 16/26] update lanelines --- opendbc/car/hyundai/hyundaicanfd.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/opendbc/car/hyundai/hyundaicanfd.py b/opendbc/car/hyundai/hyundaicanfd.py index f090e923ff..7dd9b7e986 100644 --- a/opendbc/car/hyundai/hyundaicanfd.py +++ b/opendbc/car/hyundai/hyundaicanfd.py @@ -124,6 +124,9 @@ def create_msg_161(packer, CAN, enabled, msg_161): values.update({ "LFA_ICON": 2 if enabled else 0, "LKA_ICON": 4 if enabled else 0, + "LANELINE_LEFT": 2 if enabled else 0, + "LANELINE_RIGHT": 2 if enabled else 0, + "CENTERLINE": 1 if enabled else 0, "DAW_ICON": 0, }) if values.get("ALERTS_5") == 5: # use_switch_or_pedal_to_accelerate From 5f3063eb85cb4118287465a7846d7f57e29f8d9e Mon Sep 17 00:00:00 2001 From: royjr Date: Sat, 7 Dec 2024 16:05:48 -0500 Subject: [PATCH 17/26] fix indents --- opendbc/car/hyundai/hyundaicanfd.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/opendbc/car/hyundai/hyundaicanfd.py b/opendbc/car/hyundai/hyundaicanfd.py index 7dd9b7e986..62d8f1694b 100644 --- a/opendbc/car/hyundai/hyundaicanfd.py +++ b/opendbc/car/hyundai/hyundaicanfd.py @@ -130,9 +130,9 @@ def create_msg_161(packer, CAN, enabled, msg_161): "DAW_ICON": 0, }) if values.get("ALERTS_5") == 5: # use_switch_or_pedal_to_accelerate - values["ALERTS_5"] = 0 + values["ALERTS_5"] = 0 if values.get("ALERTS_2") == 5: # coffee - values.update({"ALERTS_2": 0, "SOUNDS_2": 0}) + values.update({"ALERTS_2": 0, "SOUNDS_2": 0}) return packer.make_can_msg("MSG_161", CAN.ECAN, values) def create_msg_162(packer, CAN, enabled, msg_162): From 1628aebebb452442650f3d5982636463a235b752 Mon Sep 17 00:00:00 2001 From: royjr Date: Sat, 7 Dec 2024 16:06:51 -0500 Subject: [PATCH 18/26] Update hyundai_canfd.dbc --- opendbc/dbc/hyundai_canfd.dbc | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/opendbc/dbc/hyundai_canfd.dbc b/opendbc/dbc/hyundai_canfd.dbc index 900a04e21d..9d28bc84c4 100644 --- a/opendbc/dbc/hyundai_canfd.dbc +++ b/opendbc/dbc/hyundai_canfd.dbc @@ -710,7 +710,7 @@ BO_ 353 MSG_161: 32 CCNC SG_ SETSPEED_SPEED : 200|8@1+ (1,0) [0|255] "" XXX SG_ SETSPEED : 208|4@1+ (1,0) [0|3] "" XXX SG_ HDA_ICON : 212|4@1+ (1,0) [0|3] "" XXX - SG_ SHIFT_ICON : 216|4@1+ (1,0) [0|15] "" XXX + SG_ SLA_ICON : 216|4@1+ (1,0) [0|15] "" XXX SG_ NAV_ICON : 220|4@1+ (1,0) [0|3] "" XXX SG_ LFA_ICON : 224|4@1+ (1,0) [0|3] "" XXX SG_ LCA_LEFT_ICON : 228|4@1+ (1,0) [0|15] "" XXX @@ -730,18 +730,31 @@ BO_ 354 MSG_162: 32 CCNC SG_ SIGNS : 40|8@1+ (1,0) [0|15] "" XXX SG_ SPEEDLIMIT_WEATHER : 48|4@1+ (1,0) [0|15] "" XXX SG_ VIBRATE : 52|3@1+ (1,0) [0|7] "" XXX + SG_ ZEROS_1 : 55|1@0+ (1,0) [0|1] "" XXX + SG_ ZEROS_2 : 56|8@1+ (1,0) [0|255] "" XXX SG_ LEAD : 64|5@1+ (1,0) [0|31] "" XXX SG_ LEAD_DISTANCE : 69|11@1+ (1,0) [0|2047] "" XXX SG_ LEAD_LATERAL : 80|7@1+ (1,0) [0|127] "" XXX - SG_ LEAD2 : 88|5@1+ (1,0) [0|31] "" XXX - SG_ LEAD2_DISTANCE : 93|11@1+ (1,0) [0|2047] "" XXX - SG_ LEAD2_LATERAL : 104|7@1+ (1,0) [0|127] "" XXX - SG_ LEAD3 : 112|5@1+ (1,0) [0|31] "" XXX - SG_ LEAD3_DISTANCE : 117|11@1+ (1,0) [0|2047] "" XXX - SG_ LEAD3_LATERAL : 128|7@1+ (1,0) [0|127] "" XXX - SG_ LEAD4 : 136|5@1+ (1,0) [0|31] "" XXX - SG_ LEAD4_DISTANCE : 141|11@1+ (1,0) [0|2047] "" XXX - SG_ LEAD4_LATERAL : 152|7@1+ (1,0) [0|127] "" XXX + SG_ ZEROS_3 : 87|1@0+ (1,0) [0|1] "" XXX + SG_ LEAD_ALT : 88|5@1+ (1,0) [0|31] "" XXX + SG_ LEAD_ALT_DISTANCE : 93|11@1+ (1,0) [0|2047] "" XXX + SG_ LEAD_ALT_LATERAL : 104|7@1+ (1,0) [0|127] "" XXX + SG_ ZEROS_4 : 111|1@0+ (1,0) [0|1] "" XXX + SG_ LEAD_LEFT : 112|5@1+ (1,0) [0|31] "" XXX + SG_ LEAD_LEFT_DISTANCE : 117|11@1+ (1,0) [0|2047] "" XXX + SG_ LEAD_LEFT_LATERAL : 128|7@1+ (1,0) [0|127] "" XXX + SG_ ZEROS_5 : 135|1@0+ (1,0) [0|1] "" XXX + SG_ LEAD_RIGHT : 136|5@1+ (1,0) [0|31] "" XXX + SG_ LEAD_RIGHT_DISTANCE : 141|11@1+ (1,0) [0|2047] "" XXX + SG_ LEAD_RIGHT_LATERAL : 152|7@1+ (1,0) [0|127] "" XXX + SG_ ZEROS_6 : 159|1@0+ (1,0) [0|1] "" XXX + SG_ ZEROS_7 : 160|8@1+ (1,0) [0|255] "" XXX + SG_ ZEROS_8 : 168|8@1+ (1,0) [0|255] "" XXX + SG_ ZEROS_9 : 176|8@1+ (1,0) [0|255] "" XXX + SG_ ZEROS_10 : 184|8@1+ (1,0) [0|255] "" XXX + SG_ ZEROS_11 : 192|8@1+ (1,0) [0|255] "" XXX + SG_ ZEROS_12 : 200|8@1+ (1,0) [0|255] "" XXX + SG_ ZEROS_13 : 208|5@1+ (1,0) [0|31] "" XXX SG_ FAULT_FSS : 213|3@1+ (1,0) [0|7] "" XXX SG_ FAULT_FCA : 216|3@1+ (1,0) [0|7] "" XXX SG_ FAULT_LSS : 219|3@1+ (1,0) [0|7] "" XXX @@ -755,6 +768,7 @@ BO_ 354 MSG_162: 32 CCNC SG_ FAULT_HDP : 243|3@1+ (1,0) [0|7] "" XXX SG_ FAULT_DAS : 246|3@1+ (1,0) [0|7] "" XXX SG_ FAULT_ESS : 249|3@1+ (1,0) [0|7] "" XXX + SG_ ZEROS_14 : 252|4@1+ (1,0) [0|15] "" XXX CM_ 272 "Alternative LKAS message, used on cars such as 2023 Ioniq 6, 2nd gen Kona. Matches LKAS except size is 32 bytes"; CM_ 676 "Contains signals with detailed lane line information. Used by ADAS ECU on HDA 2 vehicles to operate LFA."; From 3de60d14b0b7e605c4ff0f6adb5d93878b32e57c Mon Sep 17 00:00:00 2001 From: royjr Date: Sun, 8 Dec 2024 16:53:08 -0500 Subject: [PATCH 19/26] better! --- opendbc/car/hyundai/carcontroller.py | 4 +- opendbc/car/hyundai/hyundaicanfd.py | 97 ++++++++++++++++++++++++++-- 2 files changed, 92 insertions(+), 9 deletions(-) diff --git a/opendbc/car/hyundai/carcontroller.py b/opendbc/car/hyundai/carcontroller.py index 13334cef13..2844d7cdd1 100644 --- a/opendbc/car/hyundai/carcontroller.py +++ b/opendbc/car/hyundai/carcontroller.py @@ -118,8 +118,8 @@ def update(self, CC, CS, now_nanos): if self.frame % 5 == 0 and (not hda2 or hda2_long) and self.car_fingerprint not in (CAR.HYUNDAI_SONATA_HEV_2024,): can_sends.append(hyundaicanfd.create_lfahda_cluster(self.packer, self.CAN, CC.enabled)) if self.frame % 5 == 0 and (not hda2 or hda2_long) and self.car_fingerprint in (CAR.HYUNDAI_SONATA_HEV_2024,): - can_sends.append(hyundaicanfd.create_msg_161(self.packer, self.CAN, CC.enabled, CS.msg_161)) - can_sends.append(hyundaicanfd.create_msg_162(self.packer, self.CAN, CC.enabled, CS.msg_162)) + can_sends.append(hyundaicanfd.create_msg_161(self.packer, self.CAN, CC.enabled, CS.msg_161, self.CP, hud_control, CS, self.frame)) + can_sends.append(hyundaicanfd.create_msg_162(self.packer, self.CAN, CC.enabled, CS.msg_162, self.CP, hud_control)) # blinkers if hda2 and self.CP.flags & HyundaiFlags.ENABLE_BLINKERS: diff --git a/opendbc/car/hyundai/hyundaicanfd.py b/opendbc/car/hyundai/hyundaicanfd.py index 62d8f1694b..1d66888f65 100644 --- a/opendbc/car/hyundai/hyundaicanfd.py +++ b/opendbc/car/hyundai/hyundaicanfd.py @@ -1,6 +1,8 @@ from opendbc.car import CanBusBase from opendbc.car.common.numpy_fast import clip from opendbc.car.hyundai.values import HyundaiFlags +from openpilot.common.conversions import Conversions as CV +from openpilot.common.params import Params class CanBus(CanBusBase): @@ -119,29 +121,110 @@ def create_lfahda_cluster(packer, CAN, enabled): } return packer.make_can_msg("LFAHDA_CLUSTER", CAN.ECAN, values) -def create_msg_161(packer, CAN, enabled, msg_161): +def read_variables_from_file(file_path): + variables = {} + with open(file_path, 'r') as file: + for line in file: + line = line.strip() + if not line or len(line.split()) != 2: + continue + name, value = line.split() + variables[name] = int(value) + return variables + +def create_msg_161(packer, CAN, enabled, msg_161, cp, hud_control, car_state, frame): values = msg_161.copy() + + # HIDE ALERTS + if values.get("ALERTS_5") == 5: # USE SWITCH OR PEDAL TO ACCELERATE + values["ALERTS_5"] = 0 + if values.get("ALERTS_2") == 5: # CONSIDER TAKING A BREAK + values.update({"ALERTS_2": 0, "SOUNDS_2": 0, "DAW_ICON": 0}) + + # LANELINES + curvature = { + i: (31 if i == -1 else 13 - abs(i + 15)) if i < 0 else 15 + i + for i in range(-15, 16) + } values.update({ + "LANELINE_CURVATURE": curvature.get(max(-15, min(int(car_state.out.steeringAngleDeg / 4), 15)), 14) if enabled else 15, "LFA_ICON": 2 if enabled else 0, "LKA_ICON": 4 if enabled else 0, "LANELINE_LEFT": 2 if enabled else 0, "LANELINE_RIGHT": 2 if enabled else 0, "CENTERLINE": 1 if enabled else 0, - "DAW_ICON": 0, }) - if values.get("ALERTS_5") == 5: # use_switch_or_pedal_to_accelerate - values["ALERTS_5"] = 0 - if values.get("ALERTS_2") == 5: # coffee - values.update({"ALERTS_2": 0, "SOUNDS_2": 0}) + + # LANE DEPARTURE + if hud_control.leftLaneDepart: + values["LANELINE_LEFT"] = 4 if (frame // 50) % 2 == 0 else 1 + if hud_control.rightLaneDepart: + values["LANELINE_RIGHT"] = 4 if (frame // 50) % 2 == 0 else 1 + + if cp.openpilotLongitudinalControl: + # HIDE ALERTS + if values.get("ALERTS_5") == 4: # SMART CRUISE CONTROL CONDITIONS NOT MET + values["ALERTS_5"] = 0 + + # SETSPEED + values["SETSPEED"] = 3 if enabled else 1 + values["SETSPEED_HUD"] = 2 if enabled else 1 + values["SETSPEED_SPEED"] = 25 if (s := int(round(car_state.out.vCruiseCluster * CV.KPH_TO_MPH))) > 100 else s + + # DISTANCE + if 1 <= hud_control.leadDistanceBars <= 3: + values["DISTANCE"] = hud_control.leadDistanceBars + values["DISTANCE_SPACING"] = 1 if enabled else 0 + values["DISTANCE_LEAD"] = 2 if enabled and hud_control.leadVisible else 1 if enabled else 0 + values["DISTANCE_CAR"] = 2 if enabled else 1 + values["ALERTS_3"] = hud_control.leadDistanceBars + 6 + else: + values["DISTANCE"] = 0 + values["DISTANCE_SPACING"] = 0 + values["DISTANCE_LEAD"] = 0 + values["DISTANCE_CAR"] = 0 + + # BACKGROUND + values["BACKGROUND"] = 3 if enabled and Params().get_bool("ExperimentalMode") else 1 if enabled else 7 + + try: + values.update(read_variables_from_file('/data/openpilot/opendbc/car/hyundai/MSG_161.txt')) + except FileNotFoundError: + print('MSG_161 not ready') return packer.make_can_msg("MSG_161", CAN.ECAN, values) -def create_msg_162(packer, CAN, enabled, msg_162): +def create_msg_162(packer, CAN, enabled, msg_162, cp, hud_control): values = msg_162.copy() + + # HIDE FAULTS values.update({ "FAULT_LSS": 0, "FAULT_HDA": 0, "FAULT_DAS": 0, }) + + # LANE DEPARTURE + if hud_control.leftLaneDepart or hud_control.rightLaneDepart: + values["VIBRATE"] = 1 + + if cp.openpilotLongitudinalControl: + # LEAD + + # *** TODO *** + # LEAD_DISTANCE + # LEAD_LATERAL + + if hud_control.leadVisible: + values["LEAD"] = 2 if enabled else 1 + values["LEAD_DISTANCE"] = 100 + else: + values["LEAD"] = 0 + values["LEAD_DISTANCE"] = 0 + + try: + values.update(read_variables_from_file('/data/openpilot/opendbc/car/hyundai/MSG_162.txt')) + except FileNotFoundError: + print('MSG_162 not ready') return packer.make_can_msg("MSG_162", CAN.ECAN, values) def create_acc_control(packer, CAN, enabled, accel_last, accel, stopping, gas_override, set_speed, hud_control): From 4a68d3b789d3865717bbbbef99a87a68f2b442bd Mon Sep 17 00:00:00 2001 From: royjr Date: Sun, 8 Dec 2024 18:27:07 -0500 Subject: [PATCH 20/26] even better --- opendbc/car/hyundai/carcontroller.py | 2 +- opendbc/car/hyundai/hyundaicanfd.py | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/opendbc/car/hyundai/carcontroller.py b/opendbc/car/hyundai/carcontroller.py index 2844d7cdd1..fb0496e964 100644 --- a/opendbc/car/hyundai/carcontroller.py +++ b/opendbc/car/hyundai/carcontroller.py @@ -118,7 +118,7 @@ def update(self, CC, CS, now_nanos): if self.frame % 5 == 0 and (not hda2 or hda2_long) and self.car_fingerprint not in (CAR.HYUNDAI_SONATA_HEV_2024,): can_sends.append(hyundaicanfd.create_lfahda_cluster(self.packer, self.CAN, CC.enabled)) if self.frame % 5 == 0 and (not hda2 or hda2_long) and self.car_fingerprint in (CAR.HYUNDAI_SONATA_HEV_2024,): - can_sends.append(hyundaicanfd.create_msg_161(self.packer, self.CAN, CC.enabled, CS.msg_161, self.CP, hud_control, CS, self.frame)) + can_sends.append(hyundaicanfd.create_msg_161(self.packer, self.CAN, CC.enabled, CS.msg_161, self.CP, hud_control, CS, CC, self.frame)) can_sends.append(hyundaicanfd.create_msg_162(self.packer, self.CAN, CC.enabled, CS.msg_162, self.CP, hud_control)) # blinkers diff --git a/opendbc/car/hyundai/hyundaicanfd.py b/opendbc/car/hyundai/hyundaicanfd.py index 1d66888f65..784ea1a675 100644 --- a/opendbc/car/hyundai/hyundaicanfd.py +++ b/opendbc/car/hyundai/hyundaicanfd.py @@ -132,7 +132,7 @@ def read_variables_from_file(file_path): variables[name] = int(value) return variables -def create_msg_161(packer, CAN, enabled, msg_161, cp, hud_control, car_state, frame): +def create_msg_161(packer, CAN, enabled, msg_161, car_params, hud_control, car_state, car_control, frame): values = msg_161.copy() # HIDE ALERTS @@ -155,13 +155,20 @@ def create_msg_161(packer, CAN, enabled, msg_161, cp, hud_control, car_state, fr "CENTERLINE": 1 if enabled else 0, }) + # LCA + if enabled: + values["LCA_LEFT_ICON"] = 0 if car_state.out.leftBlindspot else 2 if car_control.leftBlinker else 1 + values["LCA_RIGHT_ICON"] = 0 if car_state.out.rightBlindspot else 2 if car_control.rightBlinker else 1 + else: + values.update({"LCA_LEFT_ICON": 0, "LCA_RIGHT_ICON": 0}) + # LANE DEPARTURE if hud_control.leftLaneDepart: values["LANELINE_LEFT"] = 4 if (frame // 50) % 2 == 0 else 1 if hud_control.rightLaneDepart: values["LANELINE_RIGHT"] = 4 if (frame // 50) % 2 == 0 else 1 - if cp.openpilotLongitudinalControl: + if car_params.openpilotLongitudinalControl: # HIDE ALERTS if values.get("ALERTS_5") == 4: # SMART CRUISE CONTROL CONDITIONS NOT MET values["ALERTS_5"] = 0 @@ -193,7 +200,7 @@ def create_msg_161(packer, CAN, enabled, msg_161, cp, hud_control, car_state, fr print('MSG_161 not ready') return packer.make_can_msg("MSG_161", CAN.ECAN, values) -def create_msg_162(packer, CAN, enabled, msg_162, cp, hud_control): +def create_msg_162(packer, CAN, enabled, msg_162, car_params, hud_control): values = msg_162.copy() # HIDE FAULTS @@ -207,7 +214,7 @@ def create_msg_162(packer, CAN, enabled, msg_162, cp, hud_control): if hud_control.leftLaneDepart or hud_control.rightLaneDepart: values["VIBRATE"] = 1 - if cp.openpilotLongitudinalControl: + if car_params.openpilotLongitudinalControl: # LEAD # *** TODO *** From 5adcc7f15e2910ea1fc8f92d06d8963e808944ee Mon Sep 17 00:00:00 2001 From: royjr Date: Sun, 8 Dec 2024 18:43:43 -0500 Subject: [PATCH 21/26] debugless --- opendbc/car/hyundai/hyundaicanfd.py | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/opendbc/car/hyundai/hyundaicanfd.py b/opendbc/car/hyundai/hyundaicanfd.py index 784ea1a675..c599c1fd55 100644 --- a/opendbc/car/hyundai/hyundaicanfd.py +++ b/opendbc/car/hyundai/hyundaicanfd.py @@ -121,17 +121,6 @@ def create_lfahda_cluster(packer, CAN, enabled): } return packer.make_can_msg("LFAHDA_CLUSTER", CAN.ECAN, values) -def read_variables_from_file(file_path): - variables = {} - with open(file_path, 'r') as file: - for line in file: - line = line.strip() - if not line or len(line.split()) != 2: - continue - name, value = line.split() - variables[name] = int(value) - return variables - def create_msg_161(packer, CAN, enabled, msg_161, car_params, hud_control, car_state, car_control, frame): values = msg_161.copy() @@ -194,10 +183,6 @@ def create_msg_161(packer, CAN, enabled, msg_161, car_params, hud_control, car_s # BACKGROUND values["BACKGROUND"] = 3 if enabled and Params().get_bool("ExperimentalMode") else 1 if enabled else 7 - try: - values.update(read_variables_from_file('/data/openpilot/opendbc/car/hyundai/MSG_161.txt')) - except FileNotFoundError: - print('MSG_161 not ready') return packer.make_can_msg("MSG_161", CAN.ECAN, values) def create_msg_162(packer, CAN, enabled, msg_162, car_params, hud_control): @@ -228,10 +213,6 @@ def create_msg_162(packer, CAN, enabled, msg_162, car_params, hud_control): values["LEAD"] = 0 values["LEAD_DISTANCE"] = 0 - try: - values.update(read_variables_from_file('/data/openpilot/opendbc/car/hyundai/MSG_162.txt')) - except FileNotFoundError: - print('MSG_162 not ready') return packer.make_can_msg("MSG_162", CAN.ECAN, values) def create_acc_control(packer, CAN, enabled, accel_last, accel, stopping, gas_override, set_speed, hud_control): From 09bd8d80b6e1328198a800ea2e9d3354ea1cf985 Mon Sep 17 00:00:00 2001 From: royjr Date: Sun, 8 Dec 2024 18:45:57 -0500 Subject: [PATCH 22/26] ew --- opendbc/car/hyundai/hyundaicanfd.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/opendbc/car/hyundai/hyundaicanfd.py b/opendbc/car/hyundai/hyundaicanfd.py index c599c1fd55..83ef26e438 100644 --- a/opendbc/car/hyundai/hyundaicanfd.py +++ b/opendbc/car/hyundai/hyundaicanfd.py @@ -200,12 +200,8 @@ def create_msg_162(packer, CAN, enabled, msg_162, car_params, hud_control): values["VIBRATE"] = 1 if car_params.openpilotLongitudinalControl: + # *** TODO *** LEAD_DISTANCE/LEAD_LATERAL # LEAD - - # *** TODO *** - # LEAD_DISTANCE - # LEAD_LATERAL - if hud_control.leadVisible: values["LEAD"] = 2 if enabled else 1 values["LEAD_DISTANCE"] = 100 From 2de6be67de1fb4a46f61ee266688697632e0e0a5 Mon Sep 17 00:00:00 2001 From: royjr Date: Sun, 8 Dec 2024 18:52:34 -0500 Subject: [PATCH 23/26] wrong one --- opendbc/car/hyundai/hyundaicanfd.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opendbc/car/hyundai/hyundaicanfd.py b/opendbc/car/hyundai/hyundaicanfd.py index 83ef26e438..5e0c5a589a 100644 --- a/opendbc/car/hyundai/hyundaicanfd.py +++ b/opendbc/car/hyundai/hyundaicanfd.py @@ -1,7 +1,7 @@ from opendbc.car import CanBusBase +from opendbc.car.common.conversions import Conversions as CV from opendbc.car.common.numpy_fast import clip from opendbc.car.hyundai.values import HyundaiFlags -from openpilot.common.conversions import Conversions as CV from openpilot.common.params import Params From 0a78aa3bdce45596309f2abe5787cb42eabec839 Mon Sep 17 00:00:00 2001 From: royjr Date: Sun, 8 Dec 2024 19:22:51 -0500 Subject: [PATCH 24/26] no params --- opendbc/car/hyundai/hyundaicanfd.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/opendbc/car/hyundai/hyundaicanfd.py b/opendbc/car/hyundai/hyundaicanfd.py index 5e0c5a589a..a3fa43bdca 100644 --- a/opendbc/car/hyundai/hyundaicanfd.py +++ b/opendbc/car/hyundai/hyundaicanfd.py @@ -2,7 +2,6 @@ from opendbc.car.common.conversions import Conversions as CV from opendbc.car.common.numpy_fast import clip from opendbc.car.hyundai.values import HyundaiFlags -from openpilot.common.params import Params class CanBus(CanBusBase): @@ -181,7 +180,7 @@ def create_msg_161(packer, CAN, enabled, msg_161, car_params, hud_control, car_s values["DISTANCE_CAR"] = 0 # BACKGROUND - values["BACKGROUND"] = 3 if enabled and Params().get_bool("ExperimentalMode") else 1 if enabled else 7 + values["BACKGROUND"] = 1 if enabled else 7 return packer.make_can_msg("MSG_161", CAN.ECAN, values) From e6948aa3cfcd46dcaca29dabc5969c480f53369f Mon Sep 17 00:00:00 2001 From: royjr Date: Sun, 8 Dec 2024 21:08:26 -0500 Subject: [PATCH 25/26] more --- opendbc/car/hyundai/hyundaicanfd.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/opendbc/car/hyundai/hyundaicanfd.py b/opendbc/car/hyundai/hyundaicanfd.py index a3fa43bdca..28f025d283 100644 --- a/opendbc/car/hyundai/hyundaicanfd.py +++ b/opendbc/car/hyundai/hyundaicanfd.py @@ -135,7 +135,7 @@ def create_msg_161(packer, CAN, enabled, msg_161, car_params, hud_control, car_s for i in range(-15, 16) } values.update({ - "LANELINE_CURVATURE": curvature.get(max(-15, min(int(car_state.out.steeringAngleDeg / 4), 15)), 14) if enabled else 15, + "LANELINE_CURVATURE": curvature.get(max(-15, min(int(car_state.out.steeringAngleDeg / 3), 15)), 14) if enabled else 15, "LFA_ICON": 2 if enabled else 0, "LKA_ICON": 4 if enabled else 0, "LANELINE_LEFT": 2 if enabled else 0, From fc4895ab21efffdc6de726887b5482a8c3cb7a02 Mon Sep 17 00:00:00 2001 From: royjr Date: Mon, 9 Dec 2024 19:57:00 -0500 Subject: [PATCH 26/26] better --- opendbc/car/hyundai/hyundaicanfd.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/opendbc/car/hyundai/hyundaicanfd.py b/opendbc/car/hyundai/hyundaicanfd.py index 28f025d283..bdc1c626fb 100644 --- a/opendbc/car/hyundai/hyundaicanfd.py +++ b/opendbc/car/hyundai/hyundaicanfd.py @@ -145,10 +145,13 @@ def create_msg_161(packer, CAN, enabled, msg_161, car_params, hud_control, car_s # LCA if enabled: - values["LCA_LEFT_ICON"] = 0 if car_state.out.leftBlindspot else 2 if car_control.leftBlinker else 1 - values["LCA_RIGHT_ICON"] = 0 if car_state.out.rightBlindspot else 2 if car_control.rightBlinker else 1 - else: - values.update({"LCA_LEFT_ICON": 0, "LCA_RIGHT_ICON": 0}) + speed_below_threshold = car_state.out.vEgo < 8.94 + values.update({ + "LCA_LEFT_ICON": 0 if car_state.out.leftBlindspot or speed_below_threshold else 2 if car_control.leftBlinker else 1, + "LCA_RIGHT_ICON": 0 if car_state.out.rightBlindspot or speed_below_threshold else 2 if car_control.rightBlinker else 1, + "LCA_LEFT_ARROW": 2 if car_control.leftBlinker else 0, + "LCA_RIGHT_ARROW": 2 if car_control.rightBlinker else 0, + }) # LANE DEPARTURE if hud_control.leftLaneDepart: @@ -164,7 +167,7 @@ def create_msg_161(packer, CAN, enabled, msg_161, car_params, hud_control, car_s # SETSPEED values["SETSPEED"] = 3 if enabled else 1 values["SETSPEED_HUD"] = 2 if enabled else 1 - values["SETSPEED_SPEED"] = 25 if (s := int(round(car_state.out.vCruiseCluster * CV.KPH_TO_MPH))) > 100 else s + values["SETSPEED_SPEED"] = 25 if (s := round(car_state.out.vCruiseCluster * CV.KPH_TO_MPH)) > 100 else s # DISTANCE if 1 <= hud_control.leadDistanceBars <= 3: