From 85a2f5b786511d8523af42a2c0c125e5cd549554 Mon Sep 17 00:00:00 2001 From: firestar5683 <168790843+firestar5683@users.noreply.github.com> Date: Sat, 21 Nov 2026 20:18:49 -0600 Subject: [PATCH] =?UTF-8?q?Enable=20stock=20cruise=20steering=20on=20the?= =?UTF-8?q?=202015=E2=80=9317=20Subaru=20Outback?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../opendbc/car/subaru/carcontroller.py | 2 +- opendbc_repo/opendbc/car/subaru/interface.py | 3 +- opendbc_repo/opendbc/car/subaru/values.py | 1 + .../opendbc/safety/modes/subaru_preglobal.h | 31 ++++++++++++++++--- opendbc_repo/opendbc/safety/safety.h | 10 +++++- 5 files changed, 40 insertions(+), 7 deletions(-) diff --git a/opendbc_repo/opendbc/car/subaru/carcontroller.py b/opendbc_repo/opendbc/car/subaru/carcontroller.py index 1a203bf5df..f41d77a7fb 100644 --- a/opendbc_repo/opendbc/car/subaru/carcontroller.py +++ b/opendbc_repo/opendbc/car/subaru/carcontroller.py @@ -218,7 +218,7 @@ class CarController(CarControllerBase): if lkas_alert_msg is not None: can_sends.append(lkas_alert_msg) if self.CP.flags & SubaruFlags.PREGLOBAL: - if self.frame % 5 == 0: + if self.CP.carFingerprint != CAR.SUBARU_OUTBACK_PREGLOBAL and self.frame % 5 == 0: # 1 = main, 2 = set shallow, 3 = set deep, 4 = resume shallow, 5 = resume deep # disengage ACC when OP is disengaged if pcm_cancel_cmd: diff --git a/opendbc_repo/opendbc/car/subaru/interface.py b/opendbc_repo/opendbc/car/subaru/interface.py index 0d5570ccd9..ec32fdf84d 100644 --- a/opendbc_repo/opendbc/car/subaru/interface.py +++ b/opendbc_repo/opendbc/car/subaru/interface.py @@ -131,7 +131,8 @@ class CarInterface(CarInterfaceBase): ret.steerActuatorDelay = 0.15 elif candidate == CAR.SUBARU_OUTBACK_PREGLOBAL: - pass + ret.dashcamOnly = False + ret.safetyConfigs[0].safetyParam = SubaruSafetyFlags.PREGLOBAL_OUTBACK_STOCK_ACC.value else: raise ValueError(f"unknown car: {candidate}") diff --git a/opendbc_repo/opendbc/car/subaru/values.py b/opendbc_repo/opendbc/car/subaru/values.py index 496160b0c0..dc7b2b03c1 100644 --- a/opendbc_repo/opendbc/car/subaru/values.py +++ b/opendbc_repo/opendbc/car/subaru/values.py @@ -71,6 +71,7 @@ class SubaruSafetyFlags(IntFlag): GEN2 = 1 LONG = 2 PREGLOBAL_REVERSED_DRIVER_TORQUE = 4 + PREGLOBAL_OUTBACK_STOCK_ACC = 8 LKAS_ANGLE = 16 D_PLATFORM = 64 FIXED_ANGLE_LIMITS = 128 diff --git a/opendbc_repo/opendbc/safety/modes/subaru_preglobal.h b/opendbc_repo/opendbc/safety/modes/subaru_preglobal.h index cc10569f3c..e137608223 100644 --- a/opendbc_repo/opendbc/safety/modes/subaru_preglobal.h +++ b/opendbc_repo/opendbc/safety/modes/subaru_preglobal.h @@ -17,7 +17,14 @@ #define SUBARU_PG_MAIN_BUS 0U #define SUBARU_PG_CAM_BUS 2U +#define SUBARU_PG_OUTBACK_STOCK_ACC 8U + static bool subaru_pg_reversed_driver_torque = false; +static bool subaru_pg_stock_acc = false; + +static uint8_t subaru_preglobal_counter(const CANPacket_t *msg) { + return msg->data[1] & 0xFU; +} static void subaru_preglobal_rx_hook(const CANPacket_t *msg) { if (msg_matches(msg, MSG_SUBARU_PG_Steering_Torque, SUBARU_PG_MAIN_BUS)) { @@ -68,7 +75,12 @@ static bool subaru_preglobal_tx_hook(const CANPacket_t *msg) { bool steer_req = (msg->data[3] >> 0) & 1U; - if (steer_torque_cmd_checks(desired_torque, steer_req, SUBARU_PG_STEERING_LIMITS)) { + uint8_t checksum = 0U; + for (int i = 0; i < 7; i++) { + checksum += msg->data[i]; + } + if (steer_torque_cmd_checks(desired_torque, steer_req, SUBARU_PG_STEERING_LIMITS) || + (subaru_pg_stock_acc && (checksum != msg->data[7]))) { tx = false; } } @@ -82,8 +94,12 @@ static safety_config subaru_preglobal_init(uint16_t param) { {MSG_SUBARU_PG_ES_LKAS, SUBARU_PG_MAIN_BUS, 8, .check_relay = true}, }; - // TODO: do checksum and counter checks after adding the signals to the outback dbc file - static const RxCheck subaru_preglobal_rx_checks[] = { + static const CanMsg SUBARU_PG_STOCK_ACC_TX_MSGS[] = { + {MSG_SUBARU_PG_ES_LKAS, SUBARU_PG_MAIN_BUS, 8, .check_relay = true}, + }; + + // Only Throttle has a verified payload counter for the 2015–17 Outback. + static RxCheck subaru_preglobal_rx_checks[] = { {.msg = {{MSG_SUBARU_PG_Throttle, SUBARU_PG_MAIN_BUS, 8, 100U, .ignore_checksum = true, .ignore_counter = true, .ignore_quality_flag = true}, { 0 }, { 0 }}}, {.msg = {{MSG_SUBARU_PG_Steering_Torque, SUBARU_PG_MAIN_BUS, 8, 50U, .ignore_checksum = true, .ignore_counter = true, .ignore_quality_flag = true}, { 0 }, { 0 }}}, {.msg = {{MSG_SUBARU_PG_CruiseControl, SUBARU_PG_MAIN_BUS, 8, 50U, .ignore_checksum = true, .ignore_counter = true, .ignore_quality_flag = true}, { 0 }, { 0 }}}, @@ -94,11 +110,18 @@ static safety_config subaru_preglobal_init(uint16_t param) { const uint16_t SUBARU_PG_PARAM_REVERSED_DRIVER_TORQUE = 4; subaru_pg_reversed_driver_torque = GET_FLAG(param, SUBARU_PG_PARAM_REVERSED_DRIVER_TORQUE); - return BUILD_SAFETY_CFG(subaru_preglobal_rx_checks, SUBARU_PG_TX_MSGS); + subaru_pg_stock_acc = param == SUBARU_PG_OUTBACK_STOCK_ACC; + subaru_preglobal_rx_checks[0].msg[0].ignore_counter = !subaru_pg_stock_acc; + subaru_preglobal_rx_checks[0].msg[0].max_counter = subaru_pg_stock_acc ? 15U : 0U; + // Leave the stock EyeSight cruise frame on the normal forwarding path. + safety_config config = subaru_pg_stock_acc ? BUILD_SAFETY_CFG(subaru_preglobal_rx_checks, SUBARU_PG_STOCK_ACC_TX_MSGS) : + BUILD_SAFETY_CFG(subaru_preglobal_rx_checks, SUBARU_PG_TX_MSGS); + return config; } const safety_hooks subaru_preglobal_hooks = { .init = subaru_preglobal_init, .rx = subaru_preglobal_rx_hook, .tx = subaru_preglobal_tx_hook, + .get_counter = subaru_preglobal_counter, }; diff --git a/opendbc_repo/opendbc/safety/safety.h b/opendbc_repo/opendbc/safety/safety.h index d74cfe7d28..63328c206c 100644 --- a/opendbc_repo/opendbc/safety/safety.h +++ b/opendbc_repo/opendbc/safety/safety.h @@ -451,6 +451,7 @@ int set_safety_hooks(uint16_t mode, uint16_t param) { {SAFETY_HYUNDAI, &hyundai_hooks}, {SAFETY_CHRYSLER, &chrysler_hooks}, {SAFETY_SUBARU, &subaru_hooks}, + {SAFETY_SUBARU_PREGLOBAL, &subaru_preglobal_hooks}, {SAFETY_VOLKSWAGEN_MQB, &volkswagen_mqb_hooks}, {SAFETY_VOLKSWAGEN_MEB, &volkswagen_meb_hooks}, {SAFETY_NISSAN, &nissan_hooks}, @@ -469,7 +470,6 @@ int set_safety_hooks(uint16_t mode, uint16_t param) { {SAFETY_CHRYSLER_CUSW, &chrysler_cusw_hooks}, {SAFETY_PSA, &psa_hooks}, {SAFETY_BYD, &byd_hooks}, - {SAFETY_SUBARU_PREGLOBAL, &subaru_preglobal_hooks}, {SAFETY_VOLKSWAGEN_MLB, &volkswagen_mlb_hooks}, {SAFETY_VOLKSWAGEN_PQ, &volkswagen_pq_hooks}, {SAFETY_ALLOUTPUT, &alloutput_hooks}, @@ -526,6 +526,14 @@ int set_safety_hooks(uint16_t mode, uint16_t param) { int hook_config_count = sizeof(safety_hook_registry) / sizeof(safety_hook_config); for (int i = 0; i < hook_config_count; i++) { if (safety_hook_registry[i].id == mode) { +#ifndef ALLOW_DEBUG + if ((mode == SAFETY_SUBARU_PREGLOBAL) && (param != SUBARU_PG_OUTBACK_STOCK_ACC)) { + current_hooks = &nooutput_hooks; + current_safety_mode = SAFETY_NOOUTPUT; + current_safety_param = 0; + continue; + } +#endif if ((mode == SAFETY_VOLVO) && ((param > 2U) && (param != 5U))) { current_hooks = &nooutput_hooks; current_safety_mode = SAFETY_NOOUTPUT;