From 6f73fad0983ec2f50122e4c2069460492c88971e Mon Sep 17 00:00:00 2001 From: firestar5683 <168790843+firestar5683@users.noreply.github.com> Date: Mon, 23 Nov 2026 16:58:09 -0600 Subject: [PATCH] =?UTF-8?q?Port=20Frogger900=E2=80=99s=202025=20Subaru=20H?= =?UTF-8?q?UD=20and=20AVH=20features?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- opendbc_repo/opendbc/car/subaru/avh.py | 9 +++--- .../opendbc/car/subaru/carcontroller.py | 24 ++++++++------ opendbc_repo/opendbc/car/subaru/interface.py | 6 ++-- opendbc_repo/opendbc/car/subaru/stock_aol.py | 8 ++++- .../subaru/tests/test_ascent_lkas_alert.py | 6 ++-- .../car/subaru/tests/test_output_contract.py | 5 ++- opendbc_repo/opendbc/car/subaru/values.py | 3 ++ opendbc_repo/opendbc/safety/modes/subaru.h | 20 +++++++----- .../tests/test_subaru_gen2_angle_pair.py | 3 +- .../pandad/tests/test_aol_protocol.cc | 2 +- openpilot/starpilot/car/subaru/aol.py | 6 ++-- openpilot/starpilot/car/subaru/aol_policy.h | 2 +- .../starpilot/car/subaru/avh_settings.py | 2 +- .../starpilot/car/subaru/tests/test_avh.py | 6 ++-- .../car/subaru/tests/test_avh_callers.py | 28 +++++++++++------ .../subaru/tests/test_stock_aol_callers.py | 31 +++++++++++++++---- 16 files changed, 109 insertions(+), 52 deletions(-) diff --git a/opendbc_repo/opendbc/car/subaru/avh.py b/opendbc_repo/opendbc/car/subaru/avh.py index 9e897b761a..9a07fb3c01 100644 --- a/opendbc_repo/opendbc/car/subaru/avh.py +++ b/opendbc_repo/opendbc/car/subaru/avh.py @@ -1,4 +1,4 @@ -"""One bounded Legacy AVH ON request; 0x32B is status, never a TX command.""" +"""One bounded Subaru AVH ON request; 0x32B is status, never a TX command.""" AVH_REQUEST = 0x6BB AVH_STATUS = 0x32B @@ -132,13 +132,14 @@ class AvhStartup: def eligible(cp): - from opendbc.car.subaru.startup import supported - return bool(supported(cp) and cp.carFingerprint == 'SUBARU_LEGACY_2025') + from opendbc.car.subaru.stock_aol import qualified + from opendbc.car.subaru.values import CAR, FROGGER_ANGLE_SIBLINGS + return bool(qualified(cp) and cp.carFingerprint in FROGGER_ANGLE_SIBLINGS | {CAR.SUBARU_LEGACY_2025}) def selected(cp): from opendbc.car.subaru.values import SubaruFlags - return bool(eligible(cp) and cp.flags & SubaruFlags.AVH_STARTUP and cp.safetyConfigs[0].safetyParam in (1169, 1425)) + return bool(eligible(cp) and cp.flags & SubaruFlags.AVH_STARTUP and cp.safetyConfigs[0].safetyParam in (1041, 1169, 1425, 3089)) def prepare(cp, enabled): diff --git a/opendbc_repo/opendbc/car/subaru/carcontroller.py b/opendbc_repo/opendbc/car/subaru/carcontroller.py index b19206af38..6407df2c12 100644 --- a/opendbc_repo/opendbc/car/subaru/carcontroller.py +++ b/opendbc_repo/opendbc/car/subaru/carcontroller.py @@ -8,7 +8,7 @@ from opendbc.car.interfaces import CarControllerBase from opendbc.car.subaru import subarucan from opendbc.car.subaru.jacobw_angle import MAX_ANGLE as JACOBW_MAX_ANGLE, filter_angle as jacobw_filter_angle, limit_angle as jacobw_limit_angle from opendbc.car.subaru.stock_aol import qualified as subaru_aol_qualified -from opendbc.car.subaru.values import CAR, DBC, GLOBAL_ES_ADDR, CanBus, CarControllerParams, SubaruFlags +from opendbc.car.subaru.values import CAR, FROGGER_ANGLE_SIBLINGS, DBC, GLOBAL_ES_ADDR, CanBus, CarControllerParams, SubaruFlags from opendbc.car.vehicle_model import VehicleModel # FIXME: These limits aren't exact. The real limit is more than likely over a larger time period and @@ -128,14 +128,15 @@ class CarController(CarControllerBase): return self.aol_dash_green_last def _ascent_lkas_alert(self, CC, CS): - if self.CP.carFingerprint not in (CAR.SUBARU_ASCENT_2023, CAR.SUBARU_LEGACY_2025) or not self.CP.flags & SubaruFlags.ASCENT_LKAS_ALERT: + if (self.CP.carFingerprint not in FROGGER_ANGLE_SIBLINGS | {CAR.SUBARU_ASCENT_2023, CAR.SUBARU_LEGACY_2025} or + not self.CP.flags & SubaruFlags.ASCENT_LKAS_ALERT): return None dat = CS.es_lkas_alert_dat - is_legacy_2025 = self.CP.carFingerprint == CAR.SUBARU_LEGACY_2025 + frogger_hud = self.CP.carFingerprint != CAR.SUBARU_ASCENT_2023 lateral_active = self.angle_was_active and CC.latActive and ( CC.enabled or subaru_aol_qualified(self.CP, marked_only=True) ) - if is_legacy_2025: + if frogger_hud: armed = CS.out.cruiseState.available if self.CP.openpilotLongitudinalControl: acc_lead_visible = bool(CC.longActive and not CS.out.gasPressed and CC.hudControl.leadVisible) @@ -213,7 +214,7 @@ class CarController(CarControllerBase): not legacy_lateral_off and not CS.out.standstill and not CS.out.steerFaultTemporary and not CS.out.steerFaultPermanent) angle_active = self.angle_active(CS, angle_available) - if self.CP.carFingerprint == CAR.SUBARU_LEGACY_2025: + if self.CP.carFingerprint in FROGGER_ANGLE_SIBLINGS | {CAR.SUBARU_LEGACY_2025}: if angle_active and self.angle_was_active and abs(self.apply_angle_last - CS.out.steeringAngleDeg) > 5.0: self.eps_stall_count += 1 if self.eps_stall_count >= 8: @@ -306,7 +307,8 @@ class CarController(CarControllerBase): can_sends.extend(send_sng(self, CC, CS, now_nanos)) # *** alerts and pcm cancel *** - enabled_for_dash_2025 = False + frogger_hud = self.CP.carFingerprint in FROGGER_ANGLE_SIBLINGS | {CAR.SUBARU_LEGACY_2025} + enabled_for_dash_2025 = self.angle_was_active if self.CP.carFingerprint == CAR.SUBARU_LEGACY_2025: enabled_for_dash_2025 = self._legacy_2025_aol_dash_green( hud_control, @@ -341,13 +343,17 @@ class CarController(CarControllerBase): can_sends.append(subarucan.create_es_dashstatus(self.packer, self.frame // 10, CS.es_dashstatus_msg, CC.enabled, self.CP.openpilotLongitudinalControl, CC.longActive, hud_control.leadVisible)) - if self.CP.carFingerprint == CAR.SUBARU_LEGACY_2025: + if frogger_hud: in_drive = CS.out.gearShifter in (structs.CarState.GearShifter.drive, structs.CarState.GearShifter.manumatic) cruise_available = CS.out.cruiseState.available lateral_off = self._legacy_2025_effective_lateral_off(CS, CC) aol_enabled = bool(getattr(CS, "aol_enabled", True)) + if self.CP.carFingerprint in FROGGER_ANGLE_SIBLINGS: + aol_enabled = aol_enabled and subaru_aol_qualified(self.CP, marked_only=True) wheel_ready = bool(cruise_available and aol_enabled) - if not (in_drive and cruise_available) or lateral_off or not hud_control.lanesVisible: + lanes_visible = hud_control.lanesVisible or ( + self.CP.carFingerprint in FROGGER_ANGLE_SIBLINGS and self.angle_was_active) + if not (in_drive and cruise_available) or lateral_off or not lanes_visible: left_line = 0 right_line = 0 left_depart = False @@ -376,7 +382,7 @@ class CarController(CarControllerBase): hud_control.leftLaneDepart, hud_control.rightLaneDepart)) if self.CP.flags & SubaruFlags.SEND_INFOTAINMENT: - if self.CP.carFingerprint == CAR.SUBARU_LEGACY_2025: + if frogger_hud: can_sends.append(subarucan.create_es_infotainment( self.packer, self.frame // 10, CS.es_infotainment_msg, hud_control.visualAlert, audible_alert=hud_control.audibleAlert, legacy_2025=True, diff --git a/opendbc_repo/opendbc/car/subaru/interface.py b/opendbc_repo/opendbc/car/subaru/interface.py index 8d93179700..189ca050c4 100644 --- a/opendbc_repo/opendbc/car/subaru/interface.py +++ b/opendbc_repo/opendbc/car/subaru/interface.py @@ -5,7 +5,7 @@ from opendbc.car.disable_ecu import disable_ecu from opendbc.car.interfaces import CarInterfaceBase from opendbc.car.subaru.carcontroller import CarController from opendbc.car.subaru.carstate import CarState -from opendbc.car.subaru.values import CAR, EARLY_GLOBAL_TORQUE_CARS, GLOBAL_ES_ADDR, CanBus, SubaruFlags, SubaruSafetyFlags +from opendbc.car.subaru.values import CAR, FROGGER_ANGLE_SIBLINGS, EARLY_GLOBAL_TORQUE_CARS, GLOBAL_ES_ADDR, CanBus, SubaruFlags, SubaruSafetyFlags GEN2_ANGLE_PORTS = frozenset((CAR.SUBARU_CROSSTREK_2025, CAR.SUBARU_IMPREZA_2025, CAR.SUBARU_LEGACY_2025, CAR.SUBARU_ASCENT_2023, CAR.SUBARU_FORESTER_2022, CAR.SUBARU_OUTBACK_2023)) @@ -59,7 +59,7 @@ class CarInterface(CarInterfaceBase): if not (ret.flags & SubaruFlags.PREGLOBAL) and 0x323 in fingerprint[2]: ret.flags |= SubaruFlags.SEND_INFOTAINMENT.value - if candidate in (CAR.SUBARU_ASCENT_2023, CAR.SUBARU_LEGACY_2025) and fingerprint[CanBus.camera].get(0x3C4) == 8: + if candidate in FROGGER_ANGLE_SIBLINGS | {CAR.SUBARU_ASCENT_2023, CAR.SUBARU_LEGACY_2025} and fingerprint[CanBus.camera].get(0x3C4) == 8: ret.flags |= SubaruFlags.ASCENT_LKAS_ALERT.value if ret.flags & SubaruFlags.PREGLOBAL: @@ -76,6 +76,8 @@ class CarInterface(CarInterfaceBase): ret.safetyConfigs[0].safetyParam |= SubaruSafetyFlags.LKAS_ANGLE.value if candidate in (CAR.SUBARU_LEGACY_2025, CAR.SUBARU_ASCENT_2023, CAR.SUBARU_OUTBACK_2023): ret.safetyConfigs[0].safetyParam |= SubaruSafetyFlags.FIXED_ANGLE_LIMITS.value + if candidate in FROGGER_ANGLE_SIBLINGS and ret.flags & SubaruFlags.ASCENT_LKAS_ALERT: + ret.safetyConfigs[0].safetyParam |= SubaruSafetyFlags.ASCENT_LKAS_ALERT.value if candidate == CAR.SUBARU_OUTBACK_2023: ret.safetyConfigs[0].safetyParam |= SubaruSafetyFlags.D_PLATFORM.value if candidate == CAR.SUBARU_ASCENT_2023: diff --git a/opendbc_repo/opendbc/car/subaru/stock_aol.py b/opendbc_repo/opendbc/car/subaru/stock_aol.py index 145f3a1ff6..dcf825563c 100644 --- a/opendbc_repo/opendbc/car/subaru/stock_aol.py +++ b/opendbc_repo/opendbc/car/subaru/stock_aol.py @@ -1,6 +1,6 @@ """Exact stock-cruise Subaru independent-lateral configuration contract.""" from opendbc.car import structs -from opendbc.car.subaru.values import CAR, EARLY_GLOBAL_TORQUE_CARS, SubaruFlags, SubaruSafetyFlags +from opendbc.car.subaru.values import CAR, FROGGER_ANGLE_SIBLINGS, EARLY_GLOBAL_TORQUE_CARS, SubaruFlags, SubaruSafetyFlags AOL_EXPERIENCE = 32 IMPREZA_MAIN_AOL = 4096 @@ -37,6 +37,12 @@ def qualified(cp, *, marked_only=False): expected |= int(SubaruSafetyFlags.AVH_STARTUP) if cp.flags & SubaruFlags.STOP_START_OFF: expected |= int(SubaruSafetyFlags.STOP_START_BUTTON) + if cp.carFingerprint in FROGGER_ANGLE_SIBLINGS: + allowed |= int(SubaruFlags.AVH_STARTUP | SubaruFlags.ASCENT_LKAS_ALERT) + if cp.flags & SubaruFlags.AVH_STARTUP: + expected |= int(SubaruSafetyFlags.AVH_STARTUP) + if cp.flags & SubaruFlags.ASCENT_LKAS_ALERT: + expected |= int(SubaruSafetyFlags.ASCENT_LKAS_ALERT) angle = cp.carFingerprint in ANGLE_CARS if angle: expected |= int(SubaruSafetyFlags.LKAS_ANGLE) diff --git a/opendbc_repo/opendbc/car/subaru/tests/test_ascent_lkas_alert.py b/opendbc_repo/opendbc/car/subaru/tests/test_ascent_lkas_alert.py index a5cb77744c..3424d5af8e 100644 --- a/opendbc_repo/opendbc/car/subaru/tests/test_ascent_lkas_alert.py +++ b/opendbc_repo/opendbc/car/subaru/tests/test_ascent_lkas_alert.py @@ -4,7 +4,7 @@ from opendbc.car import structs from opendbc.car.subaru.carcontroller import CarController from opendbc.car.subaru.carstate import CarState from opendbc.car.subaru.interface import CarInterface -from opendbc.car.subaru.values import CAR, DBC, SubaruFlags, SubaruSafetyFlags +from opendbc.car.subaru.values import CAR, DBC, FROGGER_ANGLE_SIBLINGS, SubaruFlags, SubaruSafetyFlags from opendbc.car.subaru import subarucan from opendbc.safety.tests.test_subaru_gen2_angle_pair import TestSubaruGen2AnglePair @@ -18,8 +18,8 @@ class TestAscentLkasAlert(unittest.TestCase): def test_platform_bus_length_gate_preserves_native_identity(self): for car in CAR: cp = self.params(car) - self.assertEqual(bool(cp.flags & SubaruFlags.ASCENT_LKAS_ALERT), car in (CAR.SUBARU_ASCENT_2023, CAR.SUBARU_LEGACY_2025)) - self.assertEqual(bool(cp.safetyConfigs[0].safetyParam & SubaruSafetyFlags.ASCENT_LKAS_ALERT), car == CAR.SUBARU_ASCENT_2023) + self.assertEqual(bool(cp.flags & SubaruFlags.ASCENT_LKAS_ALERT), car in FROGGER_ANGLE_SIBLINGS | {CAR.SUBARU_ASCENT_2023, CAR.SUBARU_LEGACY_2025}) + self.assertEqual(bool(cp.safetyConfigs[0].safetyParam & SubaruSafetyFlags.ASCENT_LKAS_ALERT), car in FROGGER_ANGLE_SIBLINGS | {CAR.SUBARU_ASCENT_2023}) for bus, length in ((0, 8), (1, 8), (2, 4), (2, 16)): cp = self.params(bus=bus, length=length) self.assertFalse(cp.flags & SubaruFlags.ASCENT_LKAS_ALERT) diff --git a/opendbc_repo/opendbc/car/subaru/tests/test_output_contract.py b/opendbc_repo/opendbc/car/subaru/tests/test_output_contract.py index 4271026725..0946262f65 100644 --- a/opendbc_repo/opendbc/car/subaru/tests/test_output_contract.py +++ b/opendbc_repo/opendbc/car/subaru/tests/test_output_contract.py @@ -7,7 +7,7 @@ from opendbc.car import Bus, structs from opendbc.car.subaru import subarucan from opendbc.car.subaru.stock_aol import ANGLE_CARS, TORQUE_CARS from opendbc.car.subaru.tests.test_ascent_angle import setup_controller, step -from opendbc.car.subaru.values import CAR, DBC, SubaruSafetyFlags +from opendbc.car.subaru.values import CAR, DBC, FROGGER_ANGLE_SIBLINGS, SubaruSafetyFlags from opendbc.safety.tests import test_subaru_gen2_angle_pair as pair from opendbc.safety.tests.libsafety import libsafety_py @@ -74,6 +74,9 @@ def test_dash_uses_current_request_without_mutating_physical_template(car, enabl if car == CAR.SUBARU_LEGACY_2025: assert bool(dash['LKAS_ACTIVE']) assert dash['LKAS_Dash_State'] == (2 if expected else (1 if state.out.cruiseState.available else 0)) + elif car in FROGGER_ANGLE_SIBLINGS: + assert bool(dash['LKAS_ACTIVE']) + assert dash['LKAS_Dash_State'] == (2 if expected else (1 if marked and state.out.cruiseState.available else 0)) else: if car in ANGLE_CARS or marked or enabled: assert bool(dash['LKAS_ACTIVE']) == expected diff --git a/opendbc_repo/opendbc/car/subaru/values.py b/opendbc_repo/opendbc/car/subaru/values.py index e9f3707859..7b9ee2c787 100644 --- a/opendbc_repo/opendbc/car/subaru/values.py +++ b/opendbc_repo/opendbc/car/subaru/values.py @@ -280,6 +280,9 @@ SUBARU_ALT_VERSION_RESPONSE = bytes([uds.SERVICE_TYPE.READ_DATA_BY_IDENTIFIER + EARLY_GLOBAL_TORQUE_CARS = frozenset((CAR.SUBARU_IMPREZA, CAR.SUBARU_CROSSTREK_2018)) +FROGGER_ANGLE_SIBLINGS = frozenset((CAR.SUBARU_IMPREZA_2025, CAR.SUBARU_CROSSTREK_2025)) + + FW_QUERY_CONFIG = FwQueryConfig( validate_fw_match=validate_fw_match, fw_version_regex=br"(?:[\x00-\xff]{4,5}|[\x00-\xff]{8}|[\x00-\xff]{10})", diff --git a/opendbc_repo/opendbc/safety/modes/subaru.h b/opendbc_repo/opendbc/safety/modes/subaru.h index 6862f24182..71533a239a 100644 --- a/opendbc_repo/opendbc/safety/modes/subaru.h +++ b/opendbc_repo/opendbc/safety/modes/subaru.h @@ -300,14 +300,15 @@ static safety_config subaru_init(uint16_t raw_param) { param &= ~4096U; } #ifdef ALLOW_DEBUG - const bool avh = ((param == 1169U) || (param == 1425U)) && + const bool avh = ((param == 1169U) || (param == 1425U) || (param == 1041U) || (param == 3089U)) && (((unsigned int)alternative_experience == 0U) || ((unsigned int)alternative_experience == 32U)); #else const bool avh = false; #endif const bool stop_start = ((param == 401U) || (param == 465U) || (avh && (param == 1425U))) && (((unsigned int)alternative_experience == 0U) || ((unsigned int)alternative_experience == 32U)); - const uint16_t base_param = stop_start ? ((param == 465U) ? 209U : 145U) : (avh ? 145U : param); + const uint16_t base_param = stop_start ? ((param == 465U) ? 209U : 145U) : (avh ? (param & ~1024U) : param); + const bool sibling_hud = (base_param == 2065U); static const CanMsg SUBARU_TX_MSGS[] = { SUBARU_BASE_TX_MSGS(SUBARU_MAIN_BUS, MSG_SUBARU_ES_LKAS) SUBARU_COMMON_TX_MSGS(SUBARU_MAIN_BUS) @@ -361,6 +362,10 @@ static safety_config subaru_init(uint16_t raw_param) { {0x390U, SUBARU_ALT_BUS, 8, .check_relay = false}, }; + static const CanMsg SUBARU_SIBLING_AVH_TX_MSGS[] = { + SUBARU_GEN2_ANGLE_TX_MSGS(SUBARU_MAIN_BUS) + {0x6BBU, SUBARU_ALT_BUS, 8, .check_relay = false}, + }; static const CanMsg SUBARU_AVH_TX_MSGS[] = { SUBARU_GEN2_ANGLE_TX_MSGS(SUBARU_MAIN_BUS) {MSG_SUBARU_ES_LKAS_Alert, SUBARU_MAIN_BUS, 8, .check_relay = true}, @@ -401,7 +406,7 @@ static safety_config subaru_init(uint16_t raw_param) { subaru_fixed_angle_limits = GET_FLAG(param, SUBARU_PARAM_FIXED_ANGLE); subaru_angle_invalid = (subaru_lkas_angle && (base_param != (SUBARU_PARAM_GEN2 | SUBARU_PARAM_LKAS_ANGLE)) && (base_param != (SUBARU_PARAM_GEN2 | SUBARU_PARAM_LKAS_ANGLE | SUBARU_PARAM_FIXED_ANGLE)) && - (base_param != (SUBARU_PARAM_GEN2 | SUBARU_PARAM_LKAS_ANGLE | SUBARU_PARAM_FIXED_ANGLE | SUBARU_PARAM_ANGLE_MAIN_BUS)) && !ascent_alert && !subaru_forester_angle && !subaru_d_platform) || + (base_param != (SUBARU_PARAM_GEN2 | SUBARU_PARAM_LKAS_ANGLE | SUBARU_PARAM_FIXED_ANGLE | SUBARU_PARAM_ANGLE_MAIN_BUS)) && !ascent_alert && !sibling_hud && !subaru_forester_angle && !subaru_d_platform) || ((subaru_fixed_angle_limits || subaru_angle_main_bus) && !subaru_lkas_angle); // TODO: re-enable once more work is done on the limits @@ -419,8 +424,8 @@ static safety_config subaru_init(uint16_t raw_param) { subaru_aol_legacy_2025 = legacy_2025; subaru_aol_enabled = ((unsigned int)alternative_experience == 32U) && ((param == 209U) || (param == 465U) || (param == 16U) || (param == 0U) || (param == 1U) || (param == 17U) || (param == 145U) || - avh || (param == 177U) || (param == 401U) || (param == 8U) || (param == 520U) || (param == 512U) || (param == 2225U)); - subaru_aol_main_arm = subaru_aol_enabled && ((param == 17U) || impreza_main || subaru_d_platform || legacy_2025 || subaru_early_global_torque); + avh || sibling_hud || (param == 177U) || (param == 401U) || (param == 8U) || (param == 520U) || (param == 512U) || (param == 2225U)); + subaru_aol_main_arm = subaru_aol_enabled && ((base_param == 17U) || sibling_hud || impreza_main || subaru_d_platform || legacy_2025 || subaru_early_global_torque); if (subaru_aol_enabled) { static const AolSafetyPolicy policy = { .reset = subaru_aol_reset, @@ -454,10 +459,11 @@ static safety_config subaru_init(uint16_t raw_param) { ret = subaru_d_platform ? (stop_start ? BUILD_SAFETY_CFG(subaru_rx_workspace, SUBARU_OUTBACK_STOP_START_TX_MSGS) : BUILD_SAFETY_CFG(subaru_rx_workspace, SUBARU_ASCENT_ANGLE_TX_MSGS_LIST)) : subaru_forester_angle ? BUILD_SAFETY_CFG(subaru_rx_workspace, SUBARU_FORESTER_ANGLE_TX_MSGS) : + avh && (base_param == 17U) ? BUILD_SAFETY_CFG(subaru_rx_workspace, SUBARU_SIBLING_AVH_TX_MSGS) : avh ? (stop_start ? BUILD_SAFETY_CFG(subaru_rx_workspace, SUBARU_AVH_STOP_START_TX_MSGS) : BUILD_SAFETY_CFG(subaru_rx_workspace, SUBARU_AVH_TX_MSGS)) : stop_start ? BUILD_SAFETY_CFG(subaru_rx_workspace, SUBARU_STOP_START_TX_MSGS) : - ascent_alert ? BUILD_SAFETY_CFG(subaru_rx_workspace, SUBARU_ASCENT_ALERT_TX_MSGS) : + (ascent_alert || sibling_hud) ? BUILD_SAFETY_CFG(subaru_rx_workspace, SUBARU_ASCENT_ALERT_TX_MSGS) : legacy_2025 ? BUILD_SAFETY_CFG(subaru_rx_workspace, SUBARU_LEGACY_ANGLE_TX_MSGS) : subaru_angle_main_bus ? BUILD_SAFETY_CFG(subaru_rx_workspace, SUBARU_ASCENT_ANGLE_TX_MSGS_LIST) : BUILD_SAFETY_CFG(subaru_rx_workspace, SUBARU_GEN2_ANGLE_TX_MSGS_LIST); @@ -493,7 +499,7 @@ static safety_config subaru_init(uint16_t raw_param) { } ret.rx_checks_len = rx_count; if ((((unsigned int)alternative_experience == 32U) && !subaru_aol_enabled) || - (impreza_main && ((unsigned int)alternative_experience != 32U)) || (early_global_bit && !subaru_early_global_torque)) { + (impreza_main && ((unsigned int)alternative_experience != 32U)) || (early_global_bit && !subaru_early_global_torque) || (((param == 1041U) || (param == 3089U)) && !avh)) { ret.tx_msgs = NULL; ret.tx_msgs_len = 0; } diff --git a/opendbc_repo/opendbc/safety/tests/test_subaru_gen2_angle_pair.py b/opendbc_repo/opendbc/safety/tests/test_subaru_gen2_angle_pair.py index 99568d24b1..8cd980d406 100644 --- a/opendbc_repo/opendbc/safety/tests/test_subaru_gen2_angle_pair.py +++ b/opendbc_repo/opendbc/safety/tests/test_subaru_gen2_angle_pair.py @@ -139,7 +139,8 @@ class TestSubaruGen2AnglePair(unittest.TestCase): self.arm(cp, frames) _, steer, _ = self.controller(car, cp, frames) invalid_option = 0x200 if car == CAR.SUBARU_LEGACY_2025 else 0x100 - for flags in (SubaruSafetyFlags.LONG, 0x800, invalid_option): + invalid_alert = 0x4000 if car in (CAR.SUBARU_CROSSTREK_2025, CAR.SUBARU_IMPREZA_2025) else 0x800 + for flags in (SubaruSafetyFlags.LONG, invalid_alert, invalid_option): with self.subTest(car=car, flags=flags): self.mode(cp, extra_flags=flags) for frame in required: diff --git a/openpilot/selfdrive/pandad/tests/test_aol_protocol.cc b/openpilot/selfdrive/pandad/tests/test_aol_protocol.cc index fe74bec806..154b25e846 100644 --- a/openpilot/selfdrive/pandad/tests/test_aol_protocol.cc +++ b/openpilot/selfdrive/pandad/tests/test_aol_protocol.cc @@ -129,7 +129,7 @@ int main() { subaru.capability_flags = 1U; const bool expected = (word == 16U) || (word == 0U) || (word == 1U) || (word == 17U) || (word == 209U) || (word == 465U) || (word == 145U) || (word == 1169U) || (word == 1425U) || (word == 401U) || (word == 177U) || (word == 8U) || (word == 520U) || (word == 512U) || (word == 2225U) || - (word == 4096U) || (word == 4104U) || (word == 4608U) || (word == 4616U) || (word == 8192U) || (word == 8200U); + (word == 4096U) || (word == 4104U) || (word == 4608U) || (word == 4616U) || (word == 8192U) || (word == 8200U) || (word == 1041U) || (word == 2065U) || (word == 3089U); assert(aol_capable(subaru, 11U, VEHICLE_REGISTRY) == expected); subaru.capability_flags = 0U; assert(!aol_capable(subaru, 11U, VEHICLE_REGISTRY)); diff --git a/openpilot/starpilot/car/subaru/aol.py b/openpilot/starpilot/car/subaru/aol.py index 676da940ab..a54b2365a0 100644 --- a/openpilot/starpilot/car/subaru/aol.py +++ b/openpilot/starpilot/car/subaru/aol.py @@ -1,7 +1,7 @@ """Subaru physical cruise intent with independent lateral authority.""" from opendbc.car import structs from opendbc.car.subaru.stock_aol import IMPREZA_MAIN_AOL, qualified, temporary_restriction -from opendbc.car.subaru.values import CAR, EARLY_GLOBAL_TORQUE_CARS, SubaruSafetyFlags +from opendbc.car.subaru.values import CAR, EARLY_GLOBAL_TORQUE_CARS, FROGGER_ANGLE_SIBLINGS, SubaruSafetyFlags from openpilot.starpilot.aol.intent import AolCardIntent from openpilot.starpilot.aol.policy import AolVehiclePolicy @@ -115,7 +115,7 @@ def policy_for(cp): def native_profile_supported(model, param): return model == int(structs.CarParams.SafetyModel.subaru) and param in ( 0, 1, 8, 16, 17, 145, 177, 209, 401, 465, 512, 520, 1169, 1425, 2225, 4096, 4104, 4608, 4616, - SubaruSafetyFlags.EARLY_GLOBAL_TORQUE, SubaruSafetyFlags.EARLY_GLOBAL_TORQUE | 8) + SubaruSafetyFlags.EARLY_GLOBAL_TORQUE, SubaruSafetyFlags.EARLY_GLOBAL_TORQUE | 8, 1041, 2065, 3089) def native_accepts_cp(cp, model, param): @@ -248,7 +248,7 @@ def sync_legacy_card_lateral(card, cs, cc) -> None: def sync_legacy_card_aol(card) -> None: cs = getattr(getattr(card, "CI", None), "CS", None) - if cs is not None and getattr(getattr(cs, "CP", None), "carFingerprint", None) == CAR.SUBARU_LEGACY_2025: + if cs is not None and getattr(getattr(cs, "CP", None), "carFingerprint", None) in FROGGER_ANGLE_SIBLINGS | {CAR.SUBARU_LEGACY_2025}: intent = getattr(card, "aol_card_intent", None) settings = getattr(intent, "settings", None) cs.aol_enabled = bool(settings.enabled) if settings is not None else bool(card.params.get_bool("AlwaysOnLateral")) diff --git a/openpilot/starpilot/car/subaru/aol_policy.h b/openpilot/starpilot/car/subaru/aol_policy.h index 0dc7744102..ee8c726f4e 100644 --- a/openpilot/starpilot/car/subaru/aol_policy.h +++ b/openpilot/starpilot/car/subaru/aol_policy.h @@ -5,7 +5,7 @@ inline bool subaru_aol_param(uint16_t param) { return (param == 16U) || (param == 0U) || (param == 1U) || (param == 17U) || (param == 209U) || (param == 465U) || (param == 145U) || (param == 1169U) || (param == 1425U) || (param == 401U) || (param == 177U) || (param == 8U) || (param == 520U) || (param == 512U) || (param == 2225U) || - (param == 4096U) || (param == 4104U) || (param == 4608U) || (param == 4616U) || (param == 8192U) || (param == 8200U); + (param == 4096U) || (param == 4104U) || (param == 4608U) || (param == 4616U) || (param == 8192U) || (param == 8200U) || (param == 1041U) || (param == 2065U) || (param == 3089U); } inline constexpr AolSafetyProfile SUBARU_AOL_PROFILE{11U, subaru_aol_param, true}; diff --git a/openpilot/starpilot/car/subaru/avh_settings.py b/openpilot/starpilot/car/subaru/avh_settings.py index 083d743b5f..7ed4376417 100644 --- a/openpilot/starpilot/car/subaru/avh_settings.py +++ b/openpilot/starpilot/car/subaru/avh_settings.py @@ -1,4 +1,4 @@ -"""Parked software-cruise preference for Dom's Legacy AVH startup request.""" +"""Parked software-cruise preference for the Subaru AVH startup request.""" from opendbc.car.subaru.avh import eligible from openpilot.starpilot.saved_document import commit_exact diff --git a/openpilot/starpilot/car/subaru/tests/test_avh.py b/openpilot/starpilot/car/subaru/tests/test_avh.py index cfed185897..64baad27d7 100644 --- a/openpilot/starpilot/car/subaru/tests/test_avh.py +++ b/openpilot/starpilot/car/subaru/tests/test_avh.py @@ -2,7 +2,7 @@ from dataclasses import replace from pathlib import Path from opendbc.car import gen_empty_fingerprint from opendbc.car.subaru.interface import CarInterface -from opendbc.car.subaru.values import CAR +from opendbc.car.subaru.values import CAR, FROGGER_ANGLE_SIBLINGS from openpilot.common.params import Params from openpilot.starpilot.ui.feature_settings_owner import FeatureSettingsOwner from openpilot.starpilot.ui.feature_settings_state import row_change @@ -46,9 +46,9 @@ def test_only_supported_identity_and_exact_saved_boolean_startup(tmp_path): cp = CarInterface.get_params(car, gen_empty_fingerprint(), [], True, False, False) before = cp.to_dict() choice.prepare(cp) - assert selected(cp) == (expected and car == CAR.SUBARU_LEGACY_2025) + assert selected(cp) == (expected and car in FROGGER_ANGLE_SIBLINGS | {CAR.SUBARU_LEGACY_2025}) assert not cp.openpilotLongitudinalControl and not cp.alphaLongitudinalAvailable - if car != CAR.SUBARU_LEGACY_2025 or not expected: + if car not in FROGGER_ANGLE_SIBLINGS | {CAR.SUBARU_LEGACY_2025} or not expected: assert cp.to_dict() == before diff --git a/openpilot/starpilot/car/subaru/tests/test_avh_callers.py b/openpilot/starpilot/car/subaru/tests/test_avh_callers.py index 694c6bbaf3..7519c1788d 100644 --- a/openpilot/starpilot/car/subaru/tests/test_avh_callers.py +++ b/openpilot/starpilot/car/subaru/tests/test_avh_callers.py @@ -6,7 +6,7 @@ from unittest.mock import patch import pytest from opendbc.can import CANParser from opendbc.car import Bus, gen_empty_fingerprint, structs -from opendbc.car.subaru.values import CAR, DBC +from opendbc.car.subaru.values import CAR, DBC, FROGGER_ANGLE_SIBLINGS from opendbc.car.subaru.fingerprints import FW_VERSIONS from opendbc.safety.tests.libsafety import libsafety_py from openpilot.cereal import messaging @@ -24,18 +24,25 @@ from openpilot.starpilot.car.subaru.tests.native_fixture import subaru_native_pa @pytest.mark.parametrize('enabled', [False, True]) @pytest.mark.parametrize('combined', [False, True]) @pytest.mark.parametrize('aol', [False, True]) -def test_actual_startup_factory_card_controls_native(enabled, combined, aol, subaru_native_pair, tmp_path, configure_delay=0): - candidate = CAR.SUBARU_LEGACY_2025 +def test_actual_startup_factory_card_controls_native(enabled, combined, aol, subaru_native_pair, tmp_path, configure_delay=0, + candidate=CAR.SUBARU_LEGACY_2025, camera_hud=False): fw = firmware_records(candidate, FW_VERSIONS, 'subaru') rows = [] - with actual_factory(candidate, gen_empty_fingerprint(), fw, '0' * 17, manual=False, aol=aol, + fingerprint = gen_empty_fingerprint() + if camera_hud: + fingerprint[2][0x3C4] = 8 + with actual_factory(candidate, fingerprint, fw, '0' * 17, manual=False, aol=aol, preferences={"SubaruAvhStartup": enabled, "SubaruStopStartOff": combined}) as (card, params, matches): cp = card.CP ci = card.CI safety = libsafety_py.libsafety assert cp.pcmCruise and not cp.openpilotLongitudinalControl and not cp.alphaLongitudinalAvailable assert cp.alternativeExperience == (32 if aol else 0) and not cp.dashcamOnly - assert cp.safetyConfigs[0].safetyParam == (145 + (1024 if enabled else 0) + (256 if combined else 0)) + sibling = candidate in FROGGER_ANGLE_SIBLINGS + expected = (2065 if camera_hud else 17) if sibling else 145 + assert cp.safetyConfigs[0].safetyParam == expected + (1024 if enabled else 0) + (256 if combined and not sibling else 0) + if sibling: + assert ci.CC.stop_start is None sd, controls = SelfdriveD(CP=cp), Controls() stream = CompleteCan(ci) base = time.monotonic_ns() + 100_000_000 @@ -190,14 +197,17 @@ def test_actual_startup_factory_card_controls_native(enabled, combined, aol, sub if any(address == 0x322 for address, _, _ in outgoing): dash = dash_decoder.vl['ES_LKAS_State'] expected = ci.CC.angle_was_active if steering_name == 'ES_LKAS_ANGLE' else card.sm['carControl'].latActive - if candidate == 'SUBARU_LEGACY_2025': + if sibling or candidate == CAR.SUBARU_LEGACY_2025: assert bool(dash['LKAS_ACTIVE']), (candidate, tick, expected, dash) + dash_green = ci.CC.aol_dash_green_last if candidate == CAR.SUBARU_LEGACY_2025 else expected if not cs.cruiseState.available or cs.steerFaultTemporary or cs.steerFaultPermanent: assert not ci.CC.aol_dash_green_last, (candidate, tick, dash) if expected: - assert ci.CC.aol_dash_green_last, (candidate, tick, dash) + assert dash_green, (candidate, tick, dash) ready_wheel = cs.cruiseState.available and bool(getattr(ci.CS, 'aol_enabled', True)) - expected_dash = 2 if ci.CC.aol_dash_green_last else (1 if ready_wheel else 0) + if candidate in FROGGER_ANGLE_SIBLINGS: + ready_wheel = ready_wheel and aol + expected_dash = 2 if dash_green else (1 if ready_wheel else 0) assert dash['LKAS_Dash_State'] == expected_dash, (candidate, tick, expected, expected_dash, dash) else: assert bool(dash['LKAS_ACTIVE']) == expected, (candidate, tick, expected, dash) @@ -243,7 +253,7 @@ def test_actual_startup_factory_card_controls_native(enabled, combined, aol, sub assert not command.enabled and not command.latActive and not command.longActive, row assert not safety.get_controls_allowed() and safety.aol_get_permission_mask() == 0, row if configure_delay == 0: - assert bool(stop_start_emissions) == combined + assert bool(stop_start_emissions) == (combined and not sibling) assert dash_emissions >= 20 assert bool(startup_emissions) == enabled assert len(startup_emissions) == (4 if enabled else 0) diff --git a/openpilot/starpilot/car/subaru/tests/test_stock_aol_callers.py b/openpilot/starpilot/car/subaru/tests/test_stock_aol_callers.py index 16bc13b42a..f51147feca 100644 --- a/openpilot/starpilot/car/subaru/tests/test_stock_aol_callers.py +++ b/openpilot/starpilot/car/subaru/tests/test_stock_aol_callers.py @@ -6,7 +6,7 @@ from unittest.mock import patch import pytest from opendbc.can import CANParser from opendbc.car import Bus, gen_empty_fingerprint, structs -from opendbc.car.subaru.values import CAR, DBC +from opendbc.car.subaru.values import CAR, DBC, FROGGER_ANGLE_SIBLINGS from opendbc.car.subaru.fingerprints import FW_VERSIONS from opendbc.safety.tests.libsafety import libsafety_py from openpilot.cereal import log, messaging @@ -25,7 +25,7 @@ from openpilot.starpilot.car.subaru.tests.native_fixture import subaru_native_pa CAR.SUBARU_FORESTER, CAR.SUBARU_OUTBACK]) def test_actual_full_engage_brake_reverse_temporary_recovery_mainoff(candidate, subaru_native_pair, tmp_path, aol=True, manual=False, stop_resume=False, hard_stop_native_first=False, main_only=False, preferences=None, firmware=None, - manual_ratio=None, + manual_ratio=None, camera_hud=False, deadline_gap=False, fixed_angle_handoff=False, host_first_stop=False, source_outage=False, vm_angle_handoff=0, crawl=False, eps_brake_join=False, high_angle_guard=False, main_on_brake=False, guard_brake_release=False, @@ -38,7 +38,10 @@ def test_actual_full_engage_brake_reverse_temporary_recovery_mainoff(candidate, if candidate == CAR.SUBARU_IMPREZA_2025 and firmware is None: from opendbc.car.subaru.tests.test_supported_firmware import recorded_impreza_firmware fw = recorded_impreza_firmware() - with actual_factory(candidate, gen_empty_fingerprint(), fw, '0' * 17, manual=manual, aol=aol, preferences=preferences) as (card, params, matches): + fingerprint = gen_empty_fingerprint() + if camera_hud: + fingerprint[2][0x3C4] = 8 + with actual_factory(candidate, fingerprint, fw, '0' * 17, manual=manual, aol=aol, preferences=preferences) as (card, params, matches): cp = card.CP ci = card.CI safety = libsafety_py.libsafety @@ -193,6 +196,8 @@ def test_actual_full_engage_brake_reverse_temporary_recovery_mainoff(candidate, values['Brake_Pressure_L_R'] = {'Steering_Angle': 101 if 125 <= tick < 148 else 0} else: values['Steering_Torque']['Steer_Warning'] = int(137 <= tick < 148 or temporary) + if camera_hud and candidate in FROGGER_ANGLE_SIBLINGS: + values['ES_LKAS_Alert'] = {'LKAS_Alert': 25, 'LKAS_HUD_Lights': 0} incoming = stream.frames(values, tick=tick) if source_outage: pending_host_can.append((now, incoming)) @@ -335,19 +340,33 @@ def test_actual_full_engage_brake_reverse_temporary_recovery_mainoff(candidate, outgoing = can_capnp_to_list([published['sendcan'].as_builder().to_bytes()], msgtype='sendcan')[0][1] if 'sendcan' in published else [] tx = [(a, d.hex(), b, bool(safety.safety_tx_hook(libsafety_py.make_CANPacket(a, b, d)))) for a, d, b in outgoing] decoder.update([(now, outgoing)]) + if camera_hud and candidate in FROGGER_ANGLE_SIBLINGS: + for address, data, bus, accepted in tx: + if address == 0x3C4: + assert bus == 0 and accepted, (candidate, tick, tx) + stock_chime = bytes((25, 0, 0)) + suppress = ci.CS.out.cruiseState.available and ci.CC.angle_was_active and card.sm['carControl'].latActive + expected_alert = bytes(3) if suppress else stock_chime + assert bytes.fromhex(data)[2:5] == expected_alert, (candidate, tick, data) + assert not (candidate in FROGGER_ANGLE_SIBLINGS and any(frame[0] == 0x390 for frame in tx)) dash_decoder.update([(now, outgoing)]) if any(address == 0x322 for address, _, _ in outgoing): dash = dash_decoder.vl['ES_LKAS_State'] expected = ci.CC.angle_was_active if steering_name == 'ES_LKAS_ANGLE' else card.sm['carControl'].latActive - if candidate == 'SUBARU_LEGACY_2025': + if candidate in FROGGER_ANGLE_SIBLINGS | {CAR.SUBARU_LEGACY_2025}: assert bool(dash['LKAS_ACTIVE']), (candidate, tick, expected, dash) + dash_green = ci.CC.aol_dash_green_last if candidate == CAR.SUBARU_LEGACY_2025 else expected if not cs.cruiseState.available or cs.steerFaultTemporary or cs.steerFaultPermanent: assert not ci.CC.aol_dash_green_last, (candidate, tick, dash) if expected: - assert ci.CC.aol_dash_green_last, (candidate, tick, dash) + assert dash_green, (candidate, tick, dash) ready_wheel = cs.cruiseState.available and bool(getattr(ci.CS, 'aol_enabled', True)) - expected_dash = 2 if ci.CC.aol_dash_green_last else (1 if ready_wheel else 0) + if candidate in FROGGER_ANGLE_SIBLINGS: + ready_wheel = ready_wheel and aol + expected_dash = 2 if dash_green else (1 if ready_wheel else 0) assert dash['LKAS_Dash_State'] == expected_dash, (candidate, tick, expected, expected_dash, dash) + if camera_hud and expected and candidate in FROGGER_ANGLE_SIBLINGS: + assert dash['LKAS_Left_Line_Visible'] and dash['LKAS_Right_Line_Visible'], (candidate, tick, dash) else: assert bool(dash['LKAS_ACTIVE']) == expected, (candidate, tick, expected, dash) assert dash['LKAS_Dash_State'] == (2 if expected else 0), (candidate, tick, expected, dash)