Restore Toyota factory cruise selection in Vehicle Settings

This commit is contained in:
firestar5683
2026-11-22 22:14:27 -06:00
parent 6c2f6fc048
commit b5931c365d
6 changed files with 97 additions and 10 deletions
@@ -12,6 +12,36 @@ from opendbc.safety import ALTERNATIVE_EXPERIENCE
SteerControlType = structs.CarParams.SteerControlType
CAMERA_TORQUE_CARS = frozenset((
CAR.TOYOTA_ALPHARD_TSS2, CAR.TOYOTA_AVALON_TSS2, CAR.TOYOTA_CAMRY_TSS2, CAR.TOYOTA_COROLLA_TSS2,
CAR.TOYOTA_HIGHLANDER_TSS2, CAR.TOYOTA_PRIUS_TSS2, CAR.TOYOTA_RAV4_TSS2, CAR.TOYOTA_MIRAI,
CAR.LEXUS_ES_TSS2, CAR.LEXUS_NX_TSS2, CAR.LEXUS_LC_TSS2, CAR.LEXUS_RX_TSS2,
CAR.LEXUS_IS_TSS2, CAR.LEXUS_RC_TSS2,
))
def camera_stock_acc_supported(cp) -> bool:
required = ToyotaFlags.TSS2 | ToyotaFlags.NO_DSU | ToyotaFlags.RAISED_ACCEL_LIMIT
allowed = required | ToyotaFlags.HYBRID | ToyotaFlags.HAS_BSM
if (cp is None or cp.brand != "toyota" or cp.carFingerprint not in CAMERA_TORQUE_CARS or
cp.notCar or cp.passive or cp.dashcamOnly or cp.secOcRequired or cp.alphaLongitudinalAvailable or not cp.pcmCruise or
cp.steerControlType != SteerControlType.torque or len(cp.safetyConfigs) != 1 or
cp.flags & required != required or int(cp.flags) & ~int(allowed)):
return False
config = cp.safetyConfigs[0]
expected = EPS_SCALE[cp.carFingerprint]
if not cp.openpilotLongitudinalControl:
expected |= int(ToyotaSafetyFlags.STOCK_LONGITUDINAL)
return config.safetyModel == structs.CarParams.SafetyModel.toyota and config.safetyParam == expected
def prepare_camera_stock_acc(cp, requested: bool) -> None:
if requested and camera_stock_acc_supported(cp):
cp.openpilotLongitudinalControl = False
cp.autoResumeSng = False
cp.safetyConfigs[0].safetyParam |= int(ToyotaSafetyFlags.STOCK_LONGITUDINAL)
def toyota_auto_hold_supported(CP) -> bool:
from opendbc.car.toyota import pedal, pedal_composite
if not (CP.brand == "toyota" and CP.carFingerprint in TOYOTA_AUTO_HOLD_CARS and
+3 -6
View File
@@ -28,12 +28,6 @@ AOL_WORDS = frozenset((
SECOC_TORQUE_CARS = frozenset((CAR.TOYOTA_SIENNA_4TH_GEN, CAR.TOYOTA_RAV4_PRIME, CAR.TOYOTA_YARIS))
RADAR_TORQUE_CARS = frozenset((CAR.TOYOTA_CHR_TSS2, CAR.TOYOTA_RAV4_TSS2_2022))
CAMERA_TORQUE_CARS = frozenset((
CAR.TOYOTA_ALPHARD_TSS2, CAR.TOYOTA_AVALON_TSS2, CAR.TOYOTA_CAMRY_TSS2, CAR.TOYOTA_COROLLA_TSS2,
CAR.TOYOTA_HIGHLANDER_TSS2, CAR.TOYOTA_PRIUS_TSS2, CAR.TOYOTA_RAV4_TSS2, CAR.TOYOTA_MIRAI,
CAR.LEXUS_ES_TSS2, CAR.LEXUS_NX_TSS2, CAR.LEXUS_LC_TSS2, CAR.LEXUS_RX_TSS2,
CAR.LEXUS_IS_TSS2, CAR.LEXUS_RC_TSS2,
))
def secoc_qualified(cp, *, marked_only=False):
@@ -155,6 +149,9 @@ def qualified(cp, *, marked_only=False):
from opendbc.car.toyota.prius_longitudinal import configured as prius_filter_configured
if cp is not None and prius_filter_configured(cp):
return cp.alternativeExperience in ((32,) if marked_only else (0, 32))
from opendbc.car.toyota.interface import CAMERA_TORQUE_CARS, camera_stock_acc_supported
if camera_stock_acc_supported(cp) and not cp.openpilotLongitudinalControl:
return cp.alternativeExperience in ((32,) if marked_only else (0, 32))
if (cp is None or cp.brand != 'toyota' or cp.carFingerprint not in CAMERA_TORQUE_CARS | RADAR_TORQUE_CARS or
cp.notCar or cp.passive or cp.dashcamOnly or not cp.pcmCruise or
(cp.carFingerprint not in RADAR_TORQUE_CARS and not cp.openpilotLongitudinalControl) or
@@ -13,6 +13,52 @@ from openpilot.starpilot.vehicle_preferences import VehicleStartupPreferences
class TestVehicleStartupPreferences(unittest.TestCase):
def test_toyota_camera_stock_acc_uses_saved_preference(self):
from opendbc.car.toyota.interface import CAMERA_TORQUE_CARS, camera_stock_acc_supported
from openpilot.starpilot.car.toyota.aol import qualified
from openpilot.starpilot.ui.feature_settings_owner import FeatureSettingsOwner
from openpilot.starpilot.vehicle_preferences import toyota_disable_long_supported
for candidate in sorted(CAMERA_TORQUE_CARS):
for hybrid in (False, True):
fw = [structs.CarParams.CarFw(ecu=structs.CarParams.Ecu.hybrid)] if hybrid else []
for raw, stock in ((None, False), (b"0", False), (b"1", True)):
with self.subTest(candidate=candidate, hybrid=hybrid, stock=stock):
self.raw("DisableOpenpilotLongitudinal", raw)
prefs = VehicleStartupPreferences.read(self.params, enabled=True)
cp = car_helpers.interfaces[candidate].get_params(candidate, gen_empty_fingerprint(), fw, False, False, False)
self.assertTrue(camera_stock_acc_supported(cp))
cp = prefs.prepare(cp)
prefs.finalize(cp)
self.assertEqual(cp.openpilotLongitudinalControl, not stock)
self.assertEqual(cp.safetyConfigs[0].safetyParam, 585 if stock else 73)
self.assertEqual(cp.autoResumeSng, not stock)
self.assertTrue(cp.pcmCruise)
self.assertTrue(qualified(cp))
owner = FeatureSettingsOwner(self.params, lambda _: True, vehicle_fingerprint=lambda cp=cp: cp.carFingerprint,
vehicle_params=lambda cp=cp: cp)
rows = owner.snapshot("vehicle", parked=True, system_long=not stock, lateral_context=True, metric=False).rows
row = next(row for row in rows if row.key == "DisableOpenpilotLongitudinal")
self.assertTrue(row.available)
self.assertEqual(row.value, "On" if stock else "Off")
for candidate in (CAR.TOYOTA_HIGHLANDER, CAR.TOYOTA_RAV4_TSS2_2023, CAR.TOYOTA_RAV4_PRIME):
cp = car_helpers.interfaces[candidate].get_params(candidate, gen_empty_fingerprint(), [], False, False, False)
self.assertFalse(toyota_disable_long_supported(cp))
def test_toyota_existing_sdsu_stock_fallback_keeps_vehicle_setting(self):
from opendbc.car.toyota.tests.test_rav4h_filter import factory
from openpilot.starpilot.vehicle_preferences import toyota_disable_long_supported
self.raw("DisableOpenpilotLongitudinal", b"1")
prefs = VehicleStartupPreferences.read(self.params, enabled=True)
for size in (4, 8):
cp = factory(fp={0: {0x2FF: size}, 1: {}, 2: {}}, car=CAR.TOYOTA_HIGHLANDER)
self.assertTrue(toyota_disable_long_supported(cp))
cp = prefs.prepare(cp)
prefs.finalize(cp)
self.assertFalse(cp.openpilotLongitudinalControl)
self.assertTrue(toyota_disable_long_supported(cp))
def test_gm_tune_startup_requires_exact_saved_selection(self):
for raw, expected in ((None, 0), (b"0", 0), (b"1", 1), (b"2", 0),
(b"3", 0), (b"1\n", 0), (b"true", 0)):
@@ -333,12 +333,13 @@ class FeatureSettingsOwner:
return False
def _bolt_disable_capability(self) -> tuple | None:
from openpilot.starpilot.vehicle_preferences import bolt_disable_supported
from openpilot.starpilot.vehicle_preferences import bolt_disable_supported, toyota_disable_long_supported
from opendbc.car.gm.startup_preferences import disable_long_supported
cp = self.vehicle_params()
try:
from opendbc.car.volkswagen.meb_modes import supported as meb_stock_supported
if cp is None or not (bolt_disable_supported(cp) or disable_long_supported(cp) or meb_stock_supported(cp)):
if cp is None or not (bolt_disable_supported(cp) or disable_long_supported(cp) or meb_stock_supported(cp) or
toyota_disable_long_supported(cp)):
return None
return (str(cp.carFingerprint), str(cp.brand), bool(cp.openpilotLongitudinalControl),
bool(cp.pcmCruise), int(cp.flags),
+14 -1
View File
@@ -2,7 +2,7 @@ from dataclasses import dataclass, field
from openpilot.starpilot.car.subaru.smoothing import Snapshot, read_snapshot, prepare as prepare_smoothing
from opendbc.car.gm.startup_preferences import prepare_disable_longitudinal
from opendbc.car.toyota.interface import apply_toyota_auto_hold
from opendbc.car.toyota.interface import apply_toyota_auto_hold, prepare_camera_stock_acc
from opendbc.car.toyota.values import ToyotaFlags
from openpilot.starpilot.saved_source import read_saved
from openpilot.starpilot.car.tesla.radar_settings import RadarSettings
@@ -17,6 +17,17 @@ def bolt_disable_supported(cp) -> bool:
is_bolt_pedal_profile(cp, stock_only=True) or is_bolt_pedal_stock_denied(cp))
def toyota_disable_long_supported(cp) -> bool:
if cp is None or cp.brand != "toyota" or cp.alphaLongitudinalAvailable:
return False
from opendbc.car.toyota import advert_filter, angle_control, dsu_bypass, pedal, prius_longitudinal, rav4h_filter
from opendbc.car.toyota.interface import camera_stock_acc_supported
return camera_stock_acc_supported(cp) or any(module.configured(cp) for module in (
prius_longitudinal, rav4h_filter, pedal, advert_filter, angle_control, dsu_bypass,
))
@dataclass(frozen=True)
class VehicleStartupPreferences:
controller_selection: bytes | None = field(default=None, kw_only=True)
@@ -227,6 +238,7 @@ class VehicleStartupPreferences:
prepare_bypass_stock(cp)
self._prepare_bolt(cp, fingerprints)
prepare_disable_longitudinal(cp, self.disable_bolt_long)
prepare_camera_stock_acc(cp, self.disable_bolt_long)
self._prepare_camera_pedal(cp)
apply_gm_auto_hold(cp, self.gm_auto_hold)
apply_volt_one_pedal(cp, self.volt_one_pedal and not self.disable_bolt_long, self.gm_auto_hold)
@@ -273,6 +285,7 @@ class VehicleStartupPreferences:
prepare_bypass_stock(cp)
self._prepare_bolt(cp)
prepare_disable_longitudinal(cp, self.disable_bolt_long)
prepare_camera_stock_acc(cp, self.disable_bolt_long)
self._prepare_camera_pedal(cp)
apply_gm_auto_hold(cp, self.gm_auto_hold and admitted_hold)
apply_volt_one_pedal(cp, self.volt_one_pedal and admitted_one_pedal and not self.disable_bolt_long, self.gm_auto_hold and admitted_hold)
+1 -1
View File
@@ -1 +1 @@
{"protected_inventory_sha256": "678dc2f8d2f5fc29730d07311a725c11099fead34e0515c6b87fad21dc3205ea", "schema_version": 1}
{"protected_inventory_sha256": "e6cda84eed8ca7c5489c741e04204ba698fb9093cc3b351551955101c4ec326e", "schema_version": 1}