Share early Subaru steering and Cruise MAIN AOL

This commit is contained in:
firestar5683
2026-11-22 22:31:35 -06:00
parent bb4840ab89
commit 6ccf23ddb6
13 changed files with 51 additions and 42 deletions
+3 -4
View File
@@ -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, GLOBAL_ES_ADDR, CanBus, SubaruFlags, SubaruSafetyFlags
from opendbc.car.subaru.values import CAR, 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))
@@ -99,9 +99,8 @@ class CarInterface(CarInterfaceBase):
ret.lateralTuning.pid.kiBP, ret.lateralTuning.pid.kpBP = [[0., 20.], [0., 20.]]
ret.lateralTuning.pid.kpV, ret.lateralTuning.pid.kiV = [[0.0025, 0.1], [0.00025, 0.01]]
elif candidate in (CAR.SUBARU_IMPREZA, CAR.SUBARU_CROSSTREK_2018):
if candidate == CAR.SUBARU_CROSSTREK_2018:
ret.safetyConfigs[0].safetyParam = SubaruSafetyFlags.CROSSTREK_2018.value
elif candidate in EARLY_GLOBAL_TORQUE_CARS:
ret.safetyConfigs[0].safetyParam = SubaruSafetyFlags.EARLY_GLOBAL_TORQUE.value
ret.steerActuatorDelay = 0.4 # end-to-end angle controller
ret.lateralTuning.init('pid')
ret.lateralTuning.pid.kf = 0.00005
+4 -2
View File
@@ -2,10 +2,10 @@
from opendbc.car import structs
from opendbc.car.subaru.stock_aol import IMPREZA_MAIN_AOL
from opendbc.car.subaru.values import CAR, SubaruFlags
from opendbc.car.subaru.values import CAR, EARLY_GLOBAL_TORQUE_CARS, SubaruFlags, SubaruSafetyFlags
STOP_AND_GO = 8
SUPPORTED = frozenset((CAR.SUBARU_ASCENT, CAR.SUBARU_IMPREZA, CAR.SUBARU_IMPREZA_2020, CAR.SUBARU_FORESTER))
SUPPORTED = EARLY_GLOBAL_TORQUE_CARS | {CAR.SUBARU_ASCENT, CAR.SUBARU_IMPREZA_2020, CAR.SUBARU_FORESTER}
def eligible(cp):
@@ -16,6 +16,8 @@ def eligible(cp):
return False
word &= ~IMPREZA_MAIN_AOL
words = (0, 8, 512, 520) if cp.carFingerprint == CAR.SUBARU_IMPREZA_2020 else (0, 8)
if cp.carFingerprint in EARLY_GLOBAL_TORQUE_CARS:
words = (SubaruSafetyFlags.EARLY_GLOBAL_TORQUE, SubaruSafetyFlags.EARLY_GLOBAL_TORQUE | STOP_AND_GO)
return bool(
cp.brand == 'subaru'
and cp.carFingerprint in SUPPORTED
+4 -4
View File
@@ -1,6 +1,6 @@
"""Exact stock-cruise Subaru independent-lateral configuration contract."""
from opendbc.car import structs
from opendbc.car.subaru.values import CAR, SubaruFlags, SubaruSafetyFlags
from opendbc.car.subaru.values import CAR, EARLY_GLOBAL_TORQUE_CARS, SubaruFlags, SubaruSafetyFlags
AOL_EXPERIENCE = 32
IMPREZA_MAIN_AOL = 4096
@@ -24,8 +24,8 @@ def qualified(cp, *, marked_only=False):
static = int(CAR[cp.carFingerprint].config.flags)
allowed = int(SubaruFlags.HAS_BSM | SubaruFlags.SEND_INFOTAINMENT | SubaruFlags.SMOOTHING_BOUND)
expected = int(SubaruSafetyFlags.GEN2) if static & SubaruFlags.GLOBAL_GEN2 else 0
if cp.carFingerprint == CAR.SUBARU_CROSSTREK_2018:
expected |= int(SubaruSafetyFlags.CROSSTREK_2018)
if cp.carFingerprint in EARLY_GLOBAL_TORQUE_CARS:
expected |= int(SubaruSafetyFlags.EARLY_GLOBAL_TORQUE) | (word & 8)
if cp.carFingerprint == CAR.SUBARU_OUTBACK_2023:
expected |= int(SubaruSafetyFlags.D_PLATFORM)
allowed |= int(SubaruFlags.STOP_START_OFF)
@@ -52,7 +52,7 @@ def qualified(cp, *, marked_only=False):
return False
if cp.carFingerprint == CAR.SUBARU_IMPREZA_2020 and word == 512:
expected |= 512
if cp.carFingerprint in (CAR.SUBARU_ASCENT, CAR.SUBARU_IMPREZA, CAR.SUBARU_IMPREZA_2020, CAR.SUBARU_FORESTER) and word in (8, 520):
if cp.carFingerprint in (CAR.SUBARU_ASCENT, CAR.SUBARU_IMPREZA_2020, CAR.SUBARU_FORESTER) and word in (8, 520):
expected |= 8
if cp.carFingerprint == CAR.SUBARU_IMPREZA_2020:
expected |= word & 512
+5 -2
View File
@@ -37,7 +37,7 @@ class CarControllerParams:
self.STEER_MAX = 1000
self.STEER_DELTA_UP = 40
self.STEER_DELTA_DOWN = 40
elif CP.carFingerprint == CAR.SUBARU_CROSSTREK_2018:
elif CP.carFingerprint in EARLY_GLOBAL_TORQUE_CARS:
self.STEER_MAX = 3071
elif CP.carFingerprint == CAR.SUBARU_IMPREZA_2020:
self.STEER_DELTA_UP = 35
@@ -73,7 +73,7 @@ class SubaruSafetyFlags(IntFlag):
GEN2 = 1
LONG = 2
PREGLOBAL_REVERSED_DRIVER_TORQUE = 4
CROSSTREK_2018 = 8192
EARLY_GLOBAL_TORQUE = 8192
PREGLOBAL_OUTBACK_STOCK_ACC = 8
LKAS_ANGLE = 16
D_PLATFORM = 64
@@ -277,6 +277,9 @@ SUBARU_ALT_VERSION_REQUEST = bytes([uds.SERVICE_TYPE.READ_DATA_BY_IDENTIFIER]) +
SUBARU_ALT_VERSION_RESPONSE = bytes([uds.SERVICE_TYPE.READ_DATA_BY_IDENTIFIER + 0x40]) + \
p16(0xf100)
EARLY_GLOBAL_TORQUE_CARS = frozenset((CAR.SUBARU_IMPREZA, CAR.SUBARU_CROSSTREK_2018))
FW_QUERY_CONFIG = FwQueryConfig(
validate_fw_match=validate_fw_match,
fw_version_regex=br"(?:[\x00-\xff]{4,5}|[\x00-\xff]{8}|[\x00-\xff]{10})",
+8 -8
View File
@@ -177,11 +177,11 @@ static void subaru_rx_hook(const CANPacket_t *msg) {
subaru_avh_rx(msg);
}
static bool subaru_crosstrek_2018 = false;
static bool subaru_early_global_torque = false;
static bool subaru_tx_hook(const CANPacket_t *msg) {
const TorqueSteeringLimits SUBARU_STEERING_LIMITS = SUBARU_STEERING_LIMITS_GENERATOR(2047, 50, 70);
const TorqueSteeringLimits SUBARU_CROSSTREK_STEERING_LIMITS = SUBARU_STEERING_LIMITS_GENERATOR(3071, 50, 70);
const TorqueSteeringLimits SUBARU_EARLY_GLOBAL_STEERING_LIMITS = SUBARU_STEERING_LIMITS_GENERATOR(3071, 50, 70);
const TorqueSteeringLimits SUBARU_GEN2_STEERING_LIMITS = SUBARU_STEERING_LIMITS_GENERATOR(1000, 40, 40);
const AngleSteeringLimits SUBARU_ANGLE_STEERING_LIMITS = {
.max_angle = (subaru_forester_angle ? 650 : SUBARU_JACOBW_MAX_ANGLE) * 100,
@@ -239,7 +239,7 @@ static bool subaru_tx_hook(const CANPacket_t *msg) {
bool steer_req = (msg->data[3] >> 5) & 1U;
const TorqueSteeringLimits limits = subaru_crosstrek_2018 ? SUBARU_CROSSTREK_STEERING_LIMITS :
const TorqueSteeringLimits limits = subaru_early_global_torque ? SUBARU_EARLY_GLOBAL_STEERING_LIMITS :
(subaru_gen2 ? SUBARU_GEN2_STEERING_LIMITS : SUBARU_STEERING_LIMITS);
violation |= steer_torque_cmd_checks(desired_torque, steer_req, limits);
}
@@ -291,10 +291,10 @@ static bool subaru_tx_hook(const CANPacket_t *msg) {
}
static safety_config subaru_init(uint16_t raw_param) {
const bool crosstrek_bit = GET_FLAG(raw_param, 8192U);
subaru_crosstrek_2018 = (raw_param == 8192U) &&
const bool early_global_bit = GET_FLAG(raw_param, 8192U);
subaru_early_global_torque = ((raw_param == 8192U) || (raw_param == 8200U)) &&
(((unsigned int)alternative_experience == 0U) || ((unsigned int)alternative_experience == 32U));
uint16_t param = subaru_crosstrek_2018 ? 0U : raw_param;
uint16_t param = subaru_early_global_torque ? (raw_param & ~8192U) : raw_param;
const bool impreza_main = (param == 4096U) || (param == 4104U) || (param == 4608U) || (param == 4616U);
if (impreza_main) {
param &= ~4096U;
@@ -420,7 +420,7 @@ static safety_config subaru_init(uint16_t raw_param) {
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_crosstrek_2018);
subaru_aol_main_arm = subaru_aol_enabled && ((param == 17U) || impreza_main || subaru_d_platform || legacy_2025 || subaru_early_global_torque);
if (subaru_aol_enabled) {
static const AolSafetyPolicy policy = {
.reset = subaru_aol_reset,
@@ -493,7 +493,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)) || (crosstrek_bit && !subaru_crosstrek_2018)) {
(impreza_main && ((unsigned int)alternative_experience != 32U)) || (early_global_bit && !subaru_early_global_torque)) {
ret.tx_msgs = NULL;
ret.tx_msgs_len = 0;
}
@@ -5,7 +5,7 @@ from opendbc.safety.tests.libsafety import libsafety_py
from opendbc.safety.tests import test_subaru_stock_aol as stock_module
@pytest.fixture(params=(17, 145, 209, 401, 465, 4096, 4104, 4608, 4616, 8192))
@pytest.fixture(params=(17, 145, 209, 401, 465, 4096, 4104, 4608, 4616, 8192, 8200))
def owner(request):
item = stock_module.TestSubaruStockAol(methodName='runTest')
item.setUp()
@@ -144,7 +144,7 @@ def test_legacy_2025_cvt_manual_gears():
item.tearDown()
@pytest.mark.parametrize('param, experience, max_torque', [(0, 0, 2047), (8192, 0, 3071), (8192, 32, 3071)])
@pytest.mark.parametrize('param, experience, max_torque', [(0, 0, 2047), (8192, 0, 3071), (8192, 32, 3071), (8200, 0, 3071), (8200, 32, 3071)])
def test_early_crosstrek_steering_limit(param, experience, max_torque):
item = stock_module.TestSubaruStockAol(methodName='runTest')
item.setUp()
@@ -168,7 +168,7 @@ def test_early_crosstrek_steering_limit(param, experience, max_torque):
item.tearDown()
@pytest.mark.parametrize('param, experience', [(8193, 32), (8194, 0), (8192, 33)])
@pytest.mark.parametrize('param, experience', [(8193, 32), (8194, 0), (8192, 33), (8200, 33), (8201, 32)])
def test_early_crosstrek_rejects_mixed_safety_settings(param, experience):
item = stock_module.TestSubaruStockAol(methodName='runTest')
item.setUp()
@@ -47,7 +47,7 @@ class TestSubaruStockAol(unittest.TestCase):
('ES_Status', {'Cruise_Activated': int(cruise)}, 2 if self.param == 16 else 1),
('ES_DashStatus', {'Cruise_On': int(main)}, 2),
]
if not omit_distance and self.param in (17, 145, 209, 401, 465, 1169, 1425, 4096, 4104, 4608, 4616, 8192):
if not omit_distance and self.param in (17, 145, 209, 401, 465, 1169, 1425, 4096, 4104, 4608, 4616, 8192, 8200):
frames.append(('ES_Distance', {'Cruise_Fault': int(acc_fault)},
1 if self.param in (17, 145, 209, 401, 465, 1169, 1425) else 2))
if not omit_gear:
@@ -97,7 +97,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 == 4096U) || (word == 4104U) || (word == 4608U) || (word == 4616U) || (word == 8192U) || (word == 8200U);
assert(aol_capable(subaru, 11U, VEHICLE_REGISTRY) == expected);
subaru.capability_flags = 0U;
assert(!aol_capable(subaru, 11U, VEHICLE_REGISTRY));
+4 -3
View File
@@ -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, SubaruSafetyFlags
from opendbc.car.subaru.values import CAR, EARLY_GLOBAL_TORQUE_CARS, SubaruSafetyFlags
from openpilot.starpilot.aol.intent import AolCardIntent
from openpilot.starpilot.aol.policy import AolVehiclePolicy
@@ -100,7 +100,8 @@ 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, int(SubaruSafetyFlags.CROSSTREK_2018))
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)
def native_accepts_cp(cp, model, param):
@@ -122,7 +123,7 @@ def ordinary_axis_request_allowed(cp, state):
def create_intent(cp, settings):
main_arm = (cp.carFingerprint in (CAR.SUBARU_CROSSTREK_2025, CAR.SUBARU_IMPREZA_2025) or
(cp.carFingerprint in (CAR.SUBARU_IMPREZA_2020, CAR.SUBARU_LEGACY_2025, CAR.SUBARU_OUTBACK_2023, CAR.SUBARU_CROSSTREK_2018) and qualified(cp)))
(cp.carFingerprint in EARLY_GLOBAL_TORQUE_CARS | {CAR.SUBARU_IMPREZA_2020, CAR.SUBARU_LEGACY_2025, CAR.SUBARU_OUTBACK_2023} and qualified(cp)))
return SubaruStockCardIntent(settings, main_arm=main_arm,
allow_manumatic=(cp.carFingerprint == CAR.SUBARU_LEGACY_2025))
+1 -1
View File
@@ -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 == 4096U) || (param == 4104U) || (param == 4608U) || (param == 4616U) || (param == 8192U) || (param == 8200U);
}
inline constexpr AolSafetyProfile SUBARU_AOL_PROFILE{11U, subaru_aol_param, true};
@@ -48,18 +48,19 @@ class CallerRow(TypedDict):
@pytest.mark.parametrize("aol", [False, True])
@pytest.mark.parametrize('candidate,software', [(CAR.SUBARU_ASCENT, False), (CAR.SUBARU_IMPREZA, False),
@pytest.mark.parametrize('candidate,software', [(CAR.SUBARU_ASCENT, False), (CAR.SUBARU_IMPREZA, False), (CAR.SUBARU_CROSSTREK_2018, False),
(CAR.SUBARU_IMPREZA_2020, False), (CAR.SUBARU_FORESTER, False),
(CAR.SUBARU_IMPREZA_2020, True)])
def test_sng_actual_stock_callers(candidate, software, aol, subaru_native_pair, tmp_path):
fw = firmware_records(candidate, FW_VERSIONS, "subaru")
early_global = candidate in (CAR.SUBARU_IMPREZA, CAR.SUBARU_CROSSTREK_2018)
fw = firmware_records(CAR.SUBARU_IMPREZA if early_global else candidate, FW_VERSIONS, "subaru")
rows: list[CallerRow] = []
with actual_factory(
candidate,
gen_empty_fingerprint(),
fw,
"0" * 17,
manual=False,
manual=candidate == CAR.SUBARU_CROSSTREK_2018,
aol=aol,
preferences={"SubaruSNG": True, "SubaruRedneckCruise": software},
) as (
@@ -73,6 +74,8 @@ def test_sng_actual_stock_callers(candidate, software, aol, subaru_native_pair,
assert cp.pcmCruise and not cp.openpilotLongitudinalControl and not cp.alphaLongitudinalAvailable
assert cp.alternativeExperience == (32 if aol else 0) and not cp.dashcamOnly
expected_word = (520 if software else 8) | (IMPREZA_MAIN_AOL if aol and candidate == CAR.SUBARU_IMPREZA_2020 else 0)
if early_global:
expected_word |= 8192
assert cp.safetyConfigs[0].safetyParam == expected_word and cp.autoResumeSng
sd, controls = SelfdriveD(CP=cp), Controls()
stream = CompleteCan(ci)
@@ -456,7 +456,7 @@ def test_actual_full_engage_brake_reverse_temporary_recovery_mainoff(candidate,
if 240 <= tick < 255:
assert not command.latActive and bool(intent and intent.lateralArmed) == aol and row['cardLatch'] == aol and row['permission'] == 0, row
main_rearm = aol and candidate in (CAR.SUBARU_CROSSTREK_2025, CAR.SUBARU_IMPREZA_2025, CAR.SUBARU_IMPREZA_2020,
CAR.SUBARU_LEGACY_2025, CAR.SUBARU_OUTBACK_2023, CAR.SUBARU_CROSSTREK_2018)
CAR.SUBARU_LEGACY_2025, CAR.SUBARU_OUTBACK_2023, CAR.SUBARU_CROSSTREK_2018, CAR.SUBARU_IMPREZA)
if 330 <= tick < (350 if main_rearm else 400):
assert not command.latActive and not bool(intent and intent.allowedLatch), row
if rearm_on_brake and 355 <= tick < 365:
@@ -487,14 +487,15 @@ def test_actual_early_subaru_automatic_startup(vin, expected):
firmware = firmware_records(CAR.SUBARU_IMPREZA, FW_VERSIONS, 'subaru')
with actual_factory(expected, gen_empty_fingerprint(), firmware, vin, manual=False,
firmware_candidate=CAR.SUBARU_IMPREZA) as (card, _, _):
assert card.CP.safetyConfigs[0].safetyParam == (8192 if expected == CAR.SUBARU_CROSSTREK_2018 else 0)
assert card.CP.safetyConfigs[0].safetyParam == 8192
assert card.CP.pcmCruise and not card.CP.openpilotLongitudinalControl
def test_actual_early_crosstrek_main_only(subaru_native_pair, tmp_path):
@pytest.mark.parametrize("candidate", [CAR.SUBARU_IMPREZA, CAR.SUBARU_CROSSTREK_2018])
def test_actual_early_subaru_main_only(candidate, subaru_native_pair, tmp_path):
firmware = firmware_records(CAR.SUBARU_IMPREZA, FW_VERSIONS, 'subaru')
test_actual_full_engage_brake_reverse_temporary_recovery_mainoff(
CAR.SUBARU_CROSSTREK_2018, subaru_native_pair, tmp_path, manual=True, main_only=True, firmware=firmware)
candidate, subaru_native_pair, tmp_path, manual=True, main_only=True, firmware=firmware)
@pytest.mark.parametrize('candidate', [CAR.SUBARU_CROSSTREK_2025, CAR.SUBARU_IMPREZA_2025, CAR.SUBARU_LEGACY_2025, CAR.SUBARU_FORESTER, CAR.SUBARU_OUTBACK])
@@ -31,14 +31,14 @@ class TestVehicleSelection(unittest.TestCase):
self.assertTrue(self.owner.choose(None, selected.platform).verified)
self.assertEqual(startup_candidate(self.params), CAR.HYUNDAI_ELANTRA_HEV_2024)
def test_early_crosstrek_has_separate_factory_safety_profile(self):
def test_early_subaru_models_share_factory_safety_profile(self):
from opendbc.car.subaru.interface import CarInterface
from opendbc.car.subaru.values import CAR as SUBARU, CarControllerParams, SubaruSafetyFlags
catalog = {choice.platform: choice.label for choice in choices()}
for platform, label, torque, safety_word in (
(SUBARU.SUBARU_IMPREZA, "Subaru Impreza 2017-19", 2047, 0),
(SUBARU.SUBARU_CROSSTREK_2018, "Subaru Crosstrek 2018-19", 3071, SubaruSafetyFlags.CROSSTREK_2018),
for platform, label in (
(SUBARU.SUBARU_IMPREZA, "Subaru Impreza 2017-19"),
(SUBARU.SUBARU_CROSSTREK_2018, "Subaru Crosstrek 2018-19"),
):
self.assertEqual(catalog[platform], label)
self.assertTrue(self.owner.choose(self.owner.snapshot().raw, str(platform)).verified)
@@ -48,8 +48,8 @@ class TestVehicleSelection(unittest.TestCase):
self.assertEqual(cp.carFingerprint, platform)
self.assertTrue(cp.pcmCruise)
self.assertFalse(cp.openpilotLongitudinalControl)
self.assertEqual(cp.safetyConfigs[0].safetyParam, safety_word)
self.assertEqual(CarControllerParams(cp).STEER_MAX, torque)
self.assertEqual(cp.safetyConfigs[0].safetyParam, SubaruSafetyFlags.EARLY_GLOBAL_TORQUE)
self.assertEqual(CarControllerParams(cp).STEER_MAX, 3071)
def test_multiple_documented_trims_share_neutral_platform_choice(self):
from opendbc.car.hyundai.values import CAR as HYUNDAI