Enable stock cruise steering on the 2015–17 Subaru Outback

This commit is contained in:
firestar5683
2026-11-21 20:23:31 -06:00
45 changed files with 81 additions and 11 deletions
@@ -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:
+2 -1
View File
@@ -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}")
@@ -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
@@ -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,
};
+9 -1
View File
@@ -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;
@@ -0,0 +1,36 @@
"""Release steering admission for the 2015–17 Outback with stock EyeSight cruise."""
import unittest
from opendbc.car.structs import CarParams
from opendbc.car.subaru.values import SubaruSafetyFlags
from opendbc.safety.tests.libsafety import libsafety_py
class TestOutbackPreglobalStockAcc(unittest.TestCase):
def setUp(self):
self.safety = libsafety_py.libsafety
self.addCleanup(self.safety.set_safety_hooks, CarParams.SafetyModel.noOutput, 0)
self.safety.init_tests()
self.assertEqual(self.safety.set_safety_hooks(CarParams.SafetyModel.subaruPreglobal,
SubaruSafetyFlags.PREGLOBAL_OUTBACK_STOCK_ACC), 0)
def test_stock_cruise_forwarding_and_steering_relay(self):
self.assertEqual(self.safety.safety_fwd_hook(2, 0x161), 0)
self.assertEqual(self.safety.safety_fwd_hook(2, 0x164), -1)
self.assertFalse(self.safety.safety_tx_hook(libsafety_py.make_CANPacket(0x161, 0, bytes(8))))
self.assertFalse(self.safety.safety_tx_hook(libsafety_py.make_CANPacket(0x164, 2, bytes(8))))
self.assertTrue(self.safety.safety_tx_hook(libsafety_py.make_CANPacket(0x164, 0, bytes(8))))
self.assertFalse(self.safety.safety_tx_hook(libsafety_py.make_CANPacket(0x164, 0, bytes(7) + b"\x01")))
self.safety.set_relay_malfunction(True)
self.assertEqual(self.safety.safety_fwd_hook(2, 0x161), -1)
self.assertFalse(self.safety.safety_tx_hook(libsafety_py.make_CANPacket(0x164, 0, bytes(8))))
def test_stuck_throttle_counter_withdraws_controls(self):
throttle = libsafety_py.make_CANPacket(0x140, 0, bytes(8))
for counter in range(16):
throttle.data[1] = counter
self.assertTrue(self.safety.safety_rx_hook(throttle))
self.safety.set_controls_allowed(True)
for _ in range(16):
self.safety.safety_rx_hook(throttle)
self.assertFalse(self.safety.get_controls_allowed())
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+2 -2
View File
@@ -1,4 +1,4 @@
#pragma once
extern const uint8_t gitversion[19];
const uint8_t gitversion[19] = "DEV-122a2480-DEBUG";
extern const uint8_t gitversion[29];
const uint8_t gitversion[29] = "DEV-85a2f5b7-Pf38f504f-DEBUG";
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+1 -1
View File
@@ -1 +1 @@
DEV-122a2480-DEBUG
DEV-85a2f5b7-Pf38f504f-DEBUG
Binary file not shown.
+1 -1
View File
@@ -1 +1 @@
{"protected_inventory_sha256": "fce226495a44895f2eb0db2ef0b4abff5ebf0f1d95a9750b7ee1fbba72a0d94f", "schema_version": 1}
{"protected_inventory_sha256": "26321174828233e3136aa75c881c6365761dc3f00d457fa44dcb24aaecc8ab05", "schema_version": 1}
+1
View File
@@ -579,6 +579,7 @@ RELEASE_TARGETS = (
"opendbc_repo/opendbc/safety/tests/test_subaru_avh_startup.py",
"opendbc_repo/opendbc/safety/tests/test_subaru_forester_angle.py",
"opendbc_repo/opendbc/safety/tests/test_subaru_receive_guards.py",
"opendbc_repo/opendbc/safety/tests/test_subaru_preglobal_stock_acc.py",
"opendbc_repo/opendbc/safety/tests/test_subaru_outback_angle.py",
'openpilot/starpilot/car/toyota/tests/test_matrix_stock_caller_native.py',
'opendbc_repo/opendbc/safety/tests/test_toyota_matrix_stock_aol.py',