diff --git a/opendbc_repo/opendbc/car/hyundai/canfd_lfa_status.py b/opendbc_repo/opendbc/car/hyundai/canfd_lfa_status.py index 0ed00009ac..bc80d0bb85 100644 --- a/opendbc_repo/opendbc/car/hyundai/canfd_lfa_status.py +++ b/opendbc_repo/opendbc/car/hyundai/canfd_lfa_status.py @@ -141,6 +141,10 @@ class CANFDLfaStatus: return (((body[4] >> 6) | ((body[5] & 1) << 2)) == 4 and body[7] >> 4 == 15 and not body[6] & 0xF0) + def steering_active_current(self, now_ns): + return (self.eps_active and self.eps_healthy and + 0 < self.eps_observed_ns <= now_ns <= self.eps_observed_ns + MAX_AGE_NS) + def owns_display_status(self, active, now_ns, *, healthy=False): if active and not self.request_active: self.request_since_ns = now_ns diff --git a/opendbc_repo/opendbc/car/hyundai/carcontroller.py b/opendbc_repo/opendbc/car/hyundai/carcontroller.py index 2e1257cf56..da16ad6700 100644 --- a/opendbc_repo/opendbc/car/hyundai/carcontroller.py +++ b/opendbc_repo/opendbc/car/hyundai/carcontroller.py @@ -41,7 +41,7 @@ from opendbc.car.hyundai.torque_ev_scc import eligible as torque_ev_scc_eligible from opendbc.car.hyundai.ccnc_ev_stock import replacement_requested, qualified as qualified_ccnc_ev_stock from opendbc.car.hyundai.angle_tx_recovery import AngleTxRecovery from opendbc.car.hyundai.values import is_blended, HyundaiFlags, HyundaiSafetyFlags, Buttons, CarControllerParams, CAR -from opendbc.car.interfaces import CarControllerBase +from opendbc.car.interfaces import CarControllerBase, V_CRUISE_MAX from opendbc.car.vehicle_model import VehicleModel EV9_OP_LONG_ANGLE_TARGET_MAX = 140.0 @@ -448,6 +448,11 @@ class CarController(CarControllerBase): can_sends = [] stock_popup_owned = False stock_ccnc_owned = False + kona_handoff = (self.CP.carFingerprint == CAR.HYUNDAI_KONA_2ND_GEN and + self.CP.safetyConfigs[-1].safetyParam == KONA_IDLE_AOL_WORD) + show_cruise = CS.out.cruiseState.available and (not kona_handoff or CC.enabled or + 0. < CS.out.vCruiseCluster <= V_CRUISE_MAX) + show_ccnc_lateral = CC.latActive canfd_lfa_icon = (self.canfd_dash_icons.update(self.frame, CC.enabled, CC.latActive) if self.canfd_dash_icons is not None else None) @@ -574,6 +579,8 @@ class CarController(CarControllerBase): stock_lfa = stock_source.current(clock_boot_ns()) if stock_source is not None else None stock_faults = stock_source.last_fault() if stock_source is not None and stock_lfa is None else None stock_owned_status = False + if kona_handoff: + show_ccnc_lateral = bool(apply_steer_req and stock_source is not None and stock_source.steering_active_current(clock_boot_ns())) if stock_source is not None: display_healthy = CS.out.canValid and not (CS.out.canTimeout or CS.out.steerFaultTemporary or CS.out.steerFaultPermanent or CS.out.accFaulted) @@ -584,8 +591,6 @@ class CarController(CarControllerBase): stock_ccnc_owned = stock_source.owns_ccnc_fault_status(clock_boot_ns(), display_sample_ns=CS.ccnc_162_ts_ns, healthy=display_healthy, qualified_warning=stock_owned_status) damping_source = getattr(CS, "stock_lkas_damping", None) - kona_handoff = (self.CP.carFingerprint == CAR.HYUNDAI_KONA_2ND_GEN and - self.CP.safetyConfigs[-1].safetyParam == KONA_IDLE_AOL_WORD) lfa_counter = None if kona_handoff: if (CC.enabled or CC.latActive) and stock_lfa is not None: @@ -628,13 +633,12 @@ class CarController(CarControllerBase): now_nanos - min(CS.ccnc_161_ts_ns, CS.ccnc_162_ts_ns) <= 50_000_000 and abs(CS.ccnc_161_ts_ns - CS.ccnc_162_ts_ns) <= 50_000_000) if fresh_pair: - show_cruise = CS.out.cruiseState.available and (not kona_handoff or CC.enabled) support_current = (CS.ccnc_1b5_ts_ns > 0 and CS.ccnc_1b5_ts_ns <= now_nanos and abs(CS.ccnc_1b5_ts_ns - pair_ts) <= 50_000_000) can_sends.extend(hyundaicanfd.create_ccnc(self.packer, self.CAN, self.CP.openpilotLongitudinalControl, CC.enabled, hud_control, CC.leftBlinker, CC.rightBlinker, CS.ccnc_161.copy(), CS.ccnc_162.copy(), CS.ccnc_1b5 if support_current else None, - CS.is_metric, CS.out, show_cruise, CC.latActive, + CS.is_metric, CS.out, show_cruise, show_ccnc_lateral, owned_lfa_status=(stock_ccnc_owned if self.ccnc_fault_ownership_required else None), owned_cruise_status=kona_handoff)) self.last_ccnc_161_ts_ns = CS.ccnc_161_ts_ns @@ -696,11 +700,11 @@ class CarController(CarControllerBase): lead = (self.torque_ev_lead_inputs.update(CS.torque_ev_camera_lead, hud_control.leadVisible, now_nanos) if self.torque_ev_lead_inputs is not None else fallback_lead(CS.torque_ev_camera_lead, hud_control.leadVisible, self.torque_ev_floor_boot_ns)) - acc_options = torque_ev_scc_options(CS.out.cruiseState.available and (not kona_handoff or CC.enabled), + acc_options = torque_ev_scc_options(show_cruise, CC.actuators.longControlState, lead) if (kona_handoff and CC.longActive and not CC.cruiseControl.override and stopping and not (CS.out.standstill or CS.out.brakePressed or CS.out.gasPressed or hud_control.leadVisible or lead.visible) and - 0.0 < CS.out.vEgo < 3.0 and self.CP.stopAccel < accel < 0.0 and accel >= self.accel_last - 0.02): + 0.0 < CS.out.vEgo < 3.0 and self.CP.stopAccel - 0.02 <= accel < 0.0 and accel >= self.accel_last - 0.02): acc_options["jerk_lower"] = 1.2 elif is_gv70(self.CP): request = scc_request(CC.enabled, CC.cruiseControl.override, stopping, accel, self.accel_last) diff --git a/opendbc_repo/opendbc/car/hyundai/tests/test_kona_ccnc_long_aol.py b/opendbc_repo/opendbc/car/hyundai/tests/test_kona_ccnc_long_aol.py index cfd7944900..01a946dd62 100644 --- a/opendbc_repo/opendbc/car/hyundai/tests/test_kona_ccnc_long_aol.py +++ b/opendbc_repo/opendbc/car/hyundai/tests/test_kona_ccnc_long_aol.py @@ -238,14 +238,16 @@ def test_kona_factory_handoff_is_limited_to_healthy_internal_c4(panda_type, faul assert cp.safetyConfigs[0].safetyParam == expected -@pytest.mark.parametrize('handoff,enabled,hud_mode', ((True, False, 0), (True, True, 2), (False, False, 1))) -def test_kona_handoff_cruise_main_display_follows_star_long_engagement(handoff, enabled, hud_mode): +@pytest.mark.parametrize('handoff,enabled,set_speed,hud_mode', ( + (True, False, 255., 0), (True, False, 40., 1), (True, True, 40., 2), (False, False, 40., 1), +)) +def test_kona_handoff_cruise_main_display_follows_star_long_engagement(handoff, enabled, set_speed, hud_mode): from opendbc.can import CANParser cp = kona_params(CARS[0]) cp.safetyConfigs[0].safetyParam = 0x1C0C if handoff else 0x0C0C cp.alternativeExperience = 32 ci = CarInterface(cp) - ci.CS.out = structs.CarState(cruiseState={'available': True}, vCruiseCluster=40.).as_reader() + ci.CS.out = structs.CarState(cruiseState={'available': True}, vCruiseCluster=set_speed).as_reader() for frame in range(5): ci.apply(structs.CarControl().as_reader(), 950_000_000 + frame * 10_000_000) ci.CS.ccnc_161_ts_ns = ci.CS.ccnc_162_ts_ns = 1_000_000_000 @@ -258,16 +260,20 @@ def test_kona_handoff_cruise_main_display_follows_star_long_engagement(handoff, _, scc_packets = ci.apply(command.as_reader(), 1_010_000_000) assert {0x161, 0x162} <= parser.update((1_000_000_000, packets)) assert 0x1A0 in parser.update((1_010_000_000, scc_packets)) - assert parser.vl['SCC_CONTROL']['MainMode_ACC'] == int(not handoff or enabled) + assert parser.vl['SCC_CONTROL']['MainMode_ACC'] == int(hud_mode != 0) + assert parser.vl['SCC_CONTROL']['ACCMode'] == int(enabled) display = parser.vl['CCNC_0x161'] assert display['SETSPEED_HUD'] == hud_mode - assert display['LFA_ICON'] == 2 + assert display['LFA_ICON'] == (0 if handoff else 2) if handoff: assert display['SETSPEED'] == hud_mode if hud_mode == 0: assert display['DISTANCE'] == 0 assert display['SETSPEED_SPEED'] == 255 assert display['DISTANCE_SPACING'] == 0 + elif handoff and not enabled: + assert display['SETSPEED_SPEED'] == round(set_speed * (1. if ci.CS.is_metric else 0.621371)) + assert display['DISTANCE_SPACING'] == 3 assert parser.vl['CCNC_0x162']['FAULT_LSS'] == 2 assert parser.vl['CCNC_0x162']['FAULT_FCA'] == 1 @@ -278,7 +284,10 @@ def test_kona_handoff_cruise_main_display_follows_star_long_engagement(handoff, (2.4, -1.13, -1.12, False, False, 0x1C0C, 1.2), (1.2, -1.80, -1.78, False, False, 0x1C0C, 1.2), (3.0, -0.60, -0.59, False, False, 0x1C0C, 5.0), - (0.3, -2.00, -1.99, False, False, 0x1C0C, 5.0), + (0.3, -2.00, -1.99, False, False, 0x1C0C, 1.2), + (1.75, -2.01, -2.006, False, False, 0x1C0C, 1.2), + (1.75, -2.01, -1.80, False, False, 0x1C0C, 5.0), + (1.75, -2.10, -2.10, False, False, 0x1C0C, 5.0), (0.3, -0.45, -0.20, False, False, 0x1C0C, 5.0), (0.1, -0.27, -0.26, True, False, 0x1C0C, 5.0), (0.3, -0.27, -0.26, False, True, 0x1C0C, 5.0), @@ -304,3 +313,33 @@ def test_kona_final_braking_jerk(speed, accel, previous, standstill, lead, word, assert values['aReqRaw'] == pytest.approx(accel) assert values['ACCMode'] == values['StopReq'] == 1 assert values['JerkLowerLimit'] == pytest.approx(cap) + + +@pytest.mark.parametrize('eps,age_ms,expected', [(0, 10, 0), (1, 10, 2), (1, 51, 0), (2, 10, 0)]) +def test_kona_handoff_steering_icon_needs_current_eps_feedback(eps, age_ms, expected, monkeypatch): + import time + + from opendbc.can import CANParser + from opendbc.car.hyundai import carcontroller + + cp = kona_params(CARS[0]) + cp.safetyConfigs[0].safetyParam = 0x1C0C + cp.alternativeExperience = 32 + ci = CarInterface(cp) + ci.CS.out = structs.CarState(canValid=True, cruiseState={'available': True}).as_reader() + now = 2_000_000_000 + monkeypatch.setattr(time, 'CLOCK_BOOTTIME', time.CLOCK_MONOTONIC, raising=False) + monkeypatch.setattr(time, 'clock_gettime_ns', lambda _: now) + monkeypatch.setattr(carcontroller, 'clock_boot_ns', lambda: now) + for tick in range(5): + ci.apply(structs.CarControl().as_reader(), now-(5-tick)*10_000_000) + ci.CS.ccnc_161_ts_ns = ci.CS.ccnc_162_ts_ns = now + ci.CS.ccnc_161 = {} + ci.CS.ccnc_162 = {'FAULT_LSS': 2} + mdps = ci.CC.packer.make_can_msg('MDPS', 0, {'MDPS_LkaToiActvSta': eps}) + ci.CS.stock_lfa_status.update([(now - age_ms * 1_000_000, [mdps])]) + _, packets = ci.apply(structs.CarControl(latActive=True).as_reader(), now) + parser = CANParser('hyundai_canfd_generated', [('CCNC_0x161', 0), ('CCNC_0x162', 0)], 0) + assert {0x161, 0x162} <= parser.update((now, packets)) + assert parser.vl['CCNC_0x161']['LFA_ICON'] == expected + assert parser.vl['CCNC_0x162']['FAULT_LSS'] == 2 diff --git a/prebuilt.json b/prebuilt.json index 98aa6a38ea..c45ac7f206 100644 --- a/prebuilt.json +++ b/prebuilt.json @@ -1 +1 @@ -{"protected_inventory_sha256": "ccb2755d88165b8cb1c59a5d243e5f514433bf5e2a1d01427dfb42708a681c84", "schema_version": 1} +{"protected_inventory_sha256": "6f541c58a34990ea7d04c3aeb902b6a20d374a51d919a8169f131efbc49c1220", "schema_version": 1}