From 879a37a3182ac7f89ce2567ae0115b3b742accde Mon Sep 17 00:00:00 2001 From: ds-sebastian Date: Fri, 27 Nov 2026 01:51:01 -0500 Subject: [PATCH 1/3] Toyota radar-ACC cars: ACC target receiver on C-HR and Yaris too ARS510_RADAR_CAR now follows the RADAR_ACC flag (RAV4 2022 / 2023, C-HR TSS2, Yaris), the same rule commaai/opendbc#3860 uses. The filter, radar-torque and SecOC AOL checks and the pedal and EPS8 checks admit the flag on every car in that set, so no qualification result changes when it is set. Co-Authored-By: Claude Opus 5.5 --- opendbc_repo/opendbc/car/toyota/eps8_sdsu.py | 4 ++-- opendbc_repo/opendbc/car/toyota/pedal.py | 4 ++-- opendbc_repo/opendbc/car/toyota/tests/test_ars510.py | 5 +++++ opendbc_repo/opendbc/car/toyota/values.py | 3 ++- openpilot/starpilot/aol/tests/test_toyota.py | 7 +++---- openpilot/starpilot/car/toyota/aol.py | 9 ++++++--- .../car/toyota/tests/test_radar_preferences.py | 10 +++++++--- 7 files changed, 27 insertions(+), 15 deletions(-) diff --git a/opendbc_repo/opendbc/car/toyota/eps8_sdsu.py b/opendbc_repo/opendbc/car/toyota/eps8_sdsu.py index 877fbe48a6..19ee5a45d2 100644 --- a/opendbc_repo/opendbc/car/toyota/eps8_sdsu.py +++ b/opendbc_repo/opendbc/car/toyota/eps8_sdsu.py @@ -1,7 +1,7 @@ """Eight-byte EPS smartDSU ownership, separate from EPS5 and radar advertisements.""" from opendbc.car import structs -from opendbc.car.toyota.values import CAR, ToyotaFlags +from opendbc.car.toyota.values import ARS510_RADAR_CAR, CAR, ToyotaFlags CARS = frozenset( ( @@ -89,7 +89,7 @@ def configured(cp): if CAR(cp.carFingerprint).config.flags & ToyotaFlags.TSS2: required |= int(ToyotaFlags.RAISED_ACCEL_LIMIT) allowed = required | int(ToyotaFlags.HYBRID | ToyotaFlags.HAS_BSM) - if cp.carFingerprint in (CAR.TOYOTA_RAV4_TSS2_2022, CAR.TOYOTA_RAV4_TSS2_2023): + if cp.carFingerprint in ARS510_RADAR_CAR: allowed |= int(ToyotaFlags.ARS510_RADAR) expected_type = structs.CarParams.SteerControlType.angle if cp.carFingerprint == CAR.TOYOTA_RAV4_TSS2_2023 else structs.CarParams.SteerControlType.torque return bool( diff --git a/opendbc_repo/opendbc/car/toyota/pedal.py b/opendbc_repo/opendbc/car/toyota/pedal.py index ac69f80208..1172d7fff3 100644 --- a/opendbc_repo/opendbc/car/toyota/pedal.py +++ b/opendbc_repo/opendbc/car/toyota/pedal.py @@ -3,7 +3,7 @@ import numpy as np from opendbc.can import CANParser from opendbc.car.toyota.toyotacan import toyota_checksum from opendbc.car import structs, CanData -from opendbc.car.toyota.values import CAR, ToyotaFlags, MIN_ACC_SPEED, PEDAL_TRANSITION +from opendbc.car.toyota.values import ARS510_RADAR_CAR, CAR, ToyotaFlags, MIN_ACC_SPEED, PEDAL_TRANSITION LONG_WORD = 0x2049 STOCK_WORD = 0x2249 @@ -84,7 +84,7 @@ def configured(cp): if angle: required |= ToyotaFlags.ANGLE_CONTROL allowed |= ToyotaFlags.ANGLE_CONTROL - if cp.carFingerprint in (CAR.TOYOTA_RAV4_TSS2_2022, CAR.TOYOTA_RAV4_TSS2_2023): + if cp.carFingerprint in ARS510_RADAR_CAR: allowed |= ToyotaFlags.ARS510_RADAR expected_steer = structs.CarParams.SteerControlType.angle if angle else structs.CarParams.SteerControlType.torque if cp.steerControlType != expected_steer: diff --git a/opendbc_repo/opendbc/car/toyota/tests/test_ars510.py b/opendbc_repo/opendbc/car/toyota/tests/test_ars510.py index a3a2bd6eba..42d95c8efa 100644 --- a/opendbc_repo/opendbc/car/toyota/tests/test_ars510.py +++ b/opendbc_repo/opendbc/car/toyota/tests/test_ars510.py @@ -10,6 +10,11 @@ from opendbc.car.toyota.radar_interface import RadarInterface from opendbc.car.toyota.values import ARS510_RADAR_CAR, CAR, ToyotaFlags +def test_every_radar_acc_car_has_the_continental_radar(): + # same rule as commaai/opendbc#3860: every radar-ACC Toyota (RAV4 2022-25, C-HR, Yaris) carries the ARS510 + assert ARS510_RADAR_CAR == {CAR.TOYOTA_RAV4_TSS2_2022, CAR.TOYOTA_RAV4_TSS2_2023, CAR.TOYOTA_CHR_TSS2, CAR.TOYOTA_YARIS} + + @pytest.mark.parametrize('candidate', list(CAR)) @pytest.mark.parametrize('alpha_long,can_filter', [(False, False), (True, False), (True, True)]) def test_factory_selects_only_live_supported_continental_radar(candidate, alpha_long, can_filter): diff --git a/opendbc_repo/opendbc/car/toyota/values.py b/opendbc_repo/opendbc/car/toyota/values.py index 91f1fbc171..cfe71579c0 100644 --- a/opendbc_repo/opendbc/car/toyota/values.py +++ b/opendbc_repo/opendbc/car/toyota/values.py @@ -652,4 +652,5 @@ def stopping_decel_rate(CP): from opendbc.car.toyota.dom_defaults import stopping_decel_rate as legacy_stopping_rate return legacy_stopping_rate(CP) -ARS510_RADAR_CAR = {CAR.TOYOTA_RAV4_TSS2_2022, CAR.TOYOTA_RAV4_TSS2_2023} +# radar-ACC cars (RAV4 2022-25, C-HR, Yaris) have a Continental ARS510 radar; its ACC target is the radar lead +ARS510_RADAR_CAR = {car for car in CAR if car.config.flags & ToyotaFlags.RADAR_ACC} diff --git a/openpilot/starpilot/aol/tests/test_toyota.py b/openpilot/starpilot/aol/tests/test_toyota.py index e4e32348b8..5474b582d0 100644 --- a/openpilot/starpilot/aol/tests/test_toyota.py +++ b/openpilot/starpilot/aol/tests/test_toyota.py @@ -139,11 +139,10 @@ class TestHighlanderAol(unittest.TestCase): for alpha in (False, True): with self.subTest(car=car, alpha=alpha): cp = CarInterface.get_params(car, gen_empty_fingerprint(), [], alpha, False, False) - cp.flags |= int(ToyotaFlags.ARS510_RADAR) - expected = car == CAR.TOYOTA_RAV4_TSS2_2022 # the ACC target receiver also runs under the radar disable - self.assertEqual(qualified(cp), expected) + cp.flags |= int(ToyotaFlags.ARS510_RADAR) # the ACC target receiver also runs under the radar disable + self.assertTrue(qualified(cp)) cp.alternativeExperience = 32 - self.assertEqual(qualified(cp, marked_only=True), expected) + self.assertTrue(qualified(cp, marked_only=True)) def test_radar_torque_factory_stock_and_alpha_transport(self): from opendbc.car.toyota.carcontroller import CarController diff --git a/openpilot/starpilot/car/toyota/aol.py b/openpilot/starpilot/car/toyota/aol.py index 26eeece016..92166b5f5c 100644 --- a/openpilot/starpilot/car/toyota/aol.py +++ b/openpilot/starpilot/car/toyota/aol.py @@ -2,7 +2,7 @@ from dataclasses import replace from opendbc.car import structs from opendbc.car.toyota.config_cache import cached_config -from opendbc.car.toyota.values import CAR, ToyotaFlags, ToyotaSafetyFlags, EPS_SCALE, uses_toyota_auto_hold_aeb +from opendbc.car.toyota.values import ARS510_RADAR_CAR, CAR, ToyotaFlags, ToyotaSafetyFlags, EPS_SCALE, uses_toyota_auto_hold_aeb from openpilot.starpilot.aol.policy import AolVehiclePolicy from openpilot.starpilot.aol.intent import AolCardIntent, AOL_TOGGLE @@ -38,6 +38,9 @@ def secoc_qualified(cp, *, marked_only=False): if cp.openpilotLongitudinalControl: required |= ToyotaFlags.DISABLE_RADAR allowed = required | ToyotaFlags.HYBRID | ToyotaFlags.HAS_BSM + if radar: + # the ACC target receiver also runs under alpha long's radar disable (DISABLE_RADAR) + allowed |= ToyotaFlags.ARS510_RADAR if (cp is None or cp.brand != 'toyota' or cp.carFingerprint not in SECOC_TORQUE_CARS or cp.notCar or cp.passive or cp.dashcamOnly or not cp.pcmCruise or (not cp.openpilotLongitudinalControl and not radar) or not cp.secOcRequired or not cp.secOcKeyAvailable or @@ -74,7 +77,7 @@ def radar_filter_qualified(cp, *, marked_only=False): if cp.carFingerprint in (CAR.TOYOTA_RAV4_TSS2_2022, CAR.TOYOTA_CHR_TSS2): required |= ToyotaFlags.TSS2 | ToyotaFlags.RADAR_ACC | ToyotaFlags.RAISED_ACCEL_LIMIT allowed = required | ToyotaFlags.HYBRID | ToyotaFlags.HAS_BSM | ToyotaFlags.FILTER_BUTTONS - if cp.carFingerprint == CAR.TOYOTA_RAV4_TSS2_2022: + if cp.carFingerprint in ARS510_RADAR_CAR: allowed |= ToyotaFlags.ARS510_RADAR return bool(cp.flags & required == required and not int(cp.flags) & ~int(allowed)) @@ -181,7 +184,7 @@ def qualified(cp, *, marked_only=False): if hold: return False allowed_flags = required_flags | ToyotaFlags.HYBRID | ToyotaFlags.HAS_BSM - if cp.carFingerprint == CAR.TOYOTA_RAV4_TSS2_2022: + if cp.carFingerprint in ARS510_RADAR_CAR: # the ACC target receiver also runs under alpha long's radar disable (DISABLE_RADAR) allowed_flags |= ToyotaFlags.ARS510_RADAR if cp.flags & required_flags != required_flags or int(cp.flags) & ~int(allowed_flags | ToyotaFlags.AUTO_BRAKE_HOLD): diff --git a/openpilot/starpilot/car/toyota/tests/test_radar_preferences.py b/openpilot/starpilot/car/toyota/tests/test_radar_preferences.py index 3d21392bd5..8a84d82025 100644 --- a/openpilot/starpilot/car/toyota/tests/test_radar_preferences.py +++ b/openpilot/starpilot/car/toyota/tests/test_radar_preferences.py @@ -21,12 +21,15 @@ class FilesystemParams: return str(self.path / key) +ARS510_CARS = [CAR.TOYOTA_RAV4_TSS2_2022, CAR.TOYOTA_RAV4_TSS2_2023, CAR.TOYOTA_CHR_TSS2, CAR.TOYOTA_YARIS] + + def factory(candidate=CAR.TOYOTA_RAV4_TSS2_2022): return CarInterface.get_params(candidate, gen_empty_fingerprint(), [], False, False, False) -@pytest.mark.parametrize('candidate', [CAR.TOYOTA_RAV4_TSS2_2022, CAR.TOYOTA_RAV4_TSS2_2023]) +@pytest.mark.parametrize('candidate', ARS510_CARS) @pytest.mark.parametrize('raw', [None, b'0', b'1', b'2', b'garbage']) def test_retired_choice_cannot_disable_or_change_automatic_receiver(tmp_path, candidate, raw): params = FilesystemParams(tmp_path) @@ -45,7 +48,8 @@ def test_retired_choice_cannot_disable_or_change_automatic_receiver(tmp_path, ca assert cp.openpilotLongitudinalControl == baseline['openpilotLongitudinalControl'] -@pytest.mark.parametrize('candidate', [CAR.TOYOTA_RAV4_TSS2_2022, CAR.TOYOTA_RAV4_TSS2_2023]) +# the SecOC Yaris needs a key to build Car(); its receiver selection is covered by the factory tests +@pytest.mark.parametrize('candidate', [car for car in ARS510_CARS if car != CAR.TOYOTA_YARIS]) def test_automatic_factory_card_and_radard_parse_live_target(candidate): from unittest.mock import patch from opendbc.can import CANPacker @@ -91,7 +95,7 @@ def test_automatic_factory_card_and_radard_parse_live_target(candidate): host.vehicle_startup.close() -@pytest.mark.parametrize('candidate', [CAR.TOYOTA_RAV4_TSS2_2022, CAR.TOYOTA_RAV4_TSS2_2023]) +@pytest.mark.parametrize('candidate', ARS510_CARS) def test_disabled_radar_keeps_acc_target_receiver_without_changing_authority(candidate): # alpha long's UDS disable stops the radar's car-bus output only; the radar bus keeps sending the ACC target from opendbc.car.toyota.ars510_preferences import configure_radar From fbae9da2a20a5c8a4b1f22a3a6e246571dba04b6 Mon Sep 17 00:00:00 2001 From: ds-sebastian Date: Sat, 28 Nov 2026 13:23:32 -0500 Subject: [PATCH 2/3] Toyota radar-ACC cars: stockFcw from the ARS510's PCS alarm As in commaai/opendbc#3860. The radar also reports its PCS alarm on its own bus (PCS_STATE, 0x100), which keeps running when alpha long disables the radar's car-bus output (and with it 0x411). The parser does not require the message, so a quiet radar bus cannot make CAN invalid or time out; the power-up frame (all bits set) is ignored. Co-Authored-By: Claude Opus 5.5 --- opendbc_repo/opendbc/car/toyota/carstate.py | 11 ++++++++++- .../opendbc/car/toyota/tests/test_ars510.py | 17 +++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/opendbc_repo/opendbc/car/toyota/carstate.py b/opendbc_repo/opendbc/car/toyota/carstate.py index 9b18a7a0bf..1b98c05959 100644 --- a/opendbc_repo/opendbc/car/toyota/carstate.py +++ b/opendbc_repo/opendbc/car/toyota/carstate.py @@ -212,6 +212,11 @@ class CarState(CarStateBase): self.acc_type = cp_acc.vl["ACC_CONTROL"]["ACC_TYPE"] ret.stockFcw = bool(cp_acc.vl["PCS_HUD"]["FCW"]) + # ARS510 radar-ACC cars: the radar also reports its PCS alarm on its own bus, which keeps running when openpilot disables the radar + if Bus.radar in can_parsers and self.CP.flags & ToyotaFlags.ARS510_RADAR: + pcs = can_parsers[Bus.radar].vl["PCS_STATE"] + ret.stockFcw = ret.stockFcw or bool(pcs["PCS_ALARM"] and pcs["POWER_UP"] == 0) + # some TSS2 cars have low speed lockout permanently set, so ignore on those cars # these cars are identified by an ACC_TYPE value of 2. # TODO: it is possible to avoid the lockout and gain stop and go if you @@ -413,8 +418,12 @@ class CarState(CarStateBase): if enhanced_bsm.configured(CP): pt_parser = enhanced_bsm.BsmCANParser pt_messages.append(("BSM", math.nan)) - return { + parsers = { Bus.pt: pt_parser(DBC[CP.carFingerprint][Bus.pt], pt_messages, 0, **({"stock_word": CP.safetyConfigs[0].safetyParam} if stock else {"alternate_main": alternate_sdsu_main} if legacy_advert else {})), Bus.cam: CANParser(dbc_name, cam_messages, 2), } + if CP.flags & ToyotaFlags.ARS510_RADAR: + # not required (nan), so a quiet radar bus never makes CAN invalid + parsers[Bus.radar] = CANParser("toyota_tss2_ars510", [("PCS_STATE", math.nan)], 1) + return parsers diff --git a/opendbc_repo/opendbc/car/toyota/tests/test_ars510.py b/opendbc_repo/opendbc/car/toyota/tests/test_ars510.py index 42d95c8efa..d72e7ff2ea 100644 --- a/opendbc_repo/opendbc/car/toyota/tests/test_ars510.py +++ b/opendbc_repo/opendbc/car/toyota/tests/test_ars510.py @@ -97,3 +97,20 @@ def test_rav4_startup_wait_does_not_stall_live_tracks(): outputs = [radar.update([(1_000_000_000 + i * 10_000_000, [])]) for i in range(700)] assert sum(r is not None for r in outputs) == 140 assert all(not r.points and not r.errors.radarUnavailableTemporary for r in outputs if r is not None) + + +@pytest.mark.parametrize('candidate', sorted(ARS510_RADAR_CAR)) +def test_pcs_alarm_sets_stock_fcw_on_ars510_cars(candidate): + from opendbc.can import CANParser + from opendbc.car import Bus + from opendbc.car.toyota.carstate import CarState + cp = CarInterface.get_params(candidate, gen_empty_fingerprint(), [], True, False, False) + radar = CarState.get_can_parsers(cp)[Bus.radar] + assert isinstance(radar, CANParser) and radar.bus == 1 + packer = CANPacker(RADAR_DBC) + seen = [] + for i, values in enumerate(({"PCS_ALARM": 1, "POWER_UP": 255}, {"PCS_ALARM": 0}, {"PCS_ALARM": 1})): + radar.update([(1_000_000_000 + i * 100_000_000, [packer.make_can_msg("PCS_STATE", 1, values)])]) + pcs = radar.vl["PCS_STATE"] + seen.append(bool(pcs["PCS_ALARM"] and pcs["POWER_UP"] == 0)) + assert seen == [False, False, True] and radar.can_valid and not radar.bus_timeout From e1eb30f4b5d40fe3996d76ff4a265f3923ffff6b Mon Sep 17 00:00:00 2001 From: ds-sebastian Date: Sat, 28 Nov 2026 13:23:32 -0500 Subject: [PATCH 3/3] Toyota radar-ACC cars: radarUnavailableTemporary while the ARS510's fault flag is held As in commaai/opendbc#3860. EVENT_STATE (0x196) RADAR_FAULT is held while the radar declares itself blocked (car-bus PCS_DUST), as STATUS_MSG reports on the other TSS2 radars. Across comma's public fleet logs (127 radar-on hours, about 240 cars) two or more consecutive set cycles were seen only then; the single set cycle at power-up is ignored. Co-Authored-By: Claude Opus 5.5 --- .../opendbc/car/toyota/ars510_acc_target.py | 13 +++++++++++-- .../opendbc/car/toyota/tests/test_ars510.py | 12 ++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/opendbc_repo/opendbc/car/toyota/ars510_acc_target.py b/opendbc_repo/opendbc/car/toyota/ars510_acc_target.py index c48b639688..d6bfbc8bb3 100644 --- a/opendbc_repo/opendbc/car/toyota/ars510_acc_target.py +++ b/opendbc_repo/opendbc/car/toyota/ars510_acc_target.py @@ -17,16 +17,22 @@ TARGET_ADDRS = {0x235, 0x237, 0x239} class RadarInterface(RadarInterfaceBase): def __init__(self, CP): super().__init__(CP) - self.rcp = CANParser(RADAR_DBC, [("ACC_TARGET_1", 50), ("ACC_TARGET_2", 50), ("ACC_TARGET_3", 50)], 1) + # EVENT_STATE is not required: it carries the radar's fault flag + self.rcp = CANParser(RADAR_DBC, [("ACC_TARGET_1", 50), ("ACC_TARGET_2", 50), ("ACC_TARGET_3", 50), ("EVENT_STATE", nan)], 1) self.trigger_msg = 0x237 self.updated_messages = set() self.cycle = None self.last_record_t = None + self.fault_cycles = 0 def update(self, can_strings): self.frame += 1 packets = [(nanos, [(addr, dat, src) for addr, dat, src in frames if addr not in TARGET_ADDRS or len(dat) == 8]) for nanos, frames in can_strings] - self.updated_messages.update(self.rcp.update(packets)) + updated = self.rcp.update(packets) + self.updated_messages.update(updated) + if 0x196 in updated: + # RADAR_FAULT is held while the radar declares itself blocked, and set on one cycle at power-up + self.fault_cycles = self.fault_cycles + 1 if self.rcp.vl["EVENT_STATE"]["RADAR_FAULT"] else 0 t = can_strings[-1][0] * 1e-9 if can_strings else None cycle = self.rcp.vl["ACC_TARGET_3"]["TIMESTAMP"] clock_seen = bool(self.rcp.ts_nanos["ACC_TARGET_3"]["TIMESTAMP"]) @@ -45,6 +51,9 @@ class RadarInterface(RadarInterfaceBase): if not self.rcp.can_valid: ret.errors.canError = True return ret + if self.fault_cycles >= 2: + ret.errors.radarUnavailableTemporary = True + return ret target, position = self.rcp.vl["ACC_TARGET_1"], self.rcp.vl["ACC_TARGET_2"] if target["STATE"] == 5 and position["PRESENT"]: diff --git a/opendbc_repo/opendbc/car/toyota/tests/test_ars510.py b/opendbc_repo/opendbc/car/toyota/tests/test_ars510.py index d72e7ff2ea..049f1b7d14 100644 --- a/opendbc_repo/opendbc/car/toyota/tests/test_ars510.py +++ b/opendbc_repo/opendbc/car/toyota/tests/test_ars510.py @@ -99,6 +99,18 @@ def test_rav4_startup_wait_does_not_stall_live_tracks(): assert all(not r.points and not r.errors.radarUnavailableTemporary for r in outputs if r is not None) +def test_acc_target_reports_unavailable_while_the_fault_flag_is_held(): + # EVENT_STATE RADAR_FAULT: one set cycle (power-up) is ignored, two or more report radarUnavailableTemporary + radar = AccRadarInterface(structs.CarParams()) + packer = CANPacker(RADAR_DBC) + reports = [] + for i, fault in enumerate((True, False, True, True, True, False)): + frames = [packer.make_can_msg("EVENT_STATE", 1, {"RADAR_FAULT": int(fault)})] + acc_frames(packer, i, 60000 * (i + 1)) + ret = radar.update([(1_000_000_000 + i * 60_000_000, frames)]) + reports.append((ret.errors.radarUnavailableTemporary, len(ret.points))) + assert reports == [(False, 1), (False, 1), (False, 1), (True, 0), (True, 0), (False, 1)] + + @pytest.mark.parametrize('candidate', sorted(ARS510_RADAR_CAR)) def test_pcs_alarm_sets_stock_fcw_on_ars510_cars(candidate): from opendbc.can import CANParser