diff --git a/opendbc_repo/opendbc/car/subaru/carcontroller.py b/opendbc_repo/opendbc/car/subaru/carcontroller.py index 398301ac9b..1a203bf5df 100644 --- a/opendbc_repo/opendbc/car/subaru/carcontroller.py +++ b/opendbc_repo/opendbc/car/subaru/carcontroller.py @@ -6,7 +6,7 @@ from opendbc.car.lateral import (apply_driver_steer_torque_limits, apply_std_ste apply_steer_angle_limits_vm, common_fault_avoidance) from opendbc.car.interfaces import CarControllerBase from opendbc.car.subaru import subarucan -from opendbc.car.subaru.jacobw_angle import filter_angle as jacobw_filter_angle, limit_angle as jacobw_limit_angle +from opendbc.car.subaru.jacobw_angle import MAX_ANGLE as JACOBW_MAX_ANGLE, filter_angle as jacobw_filter_angle, limit_angle as jacobw_limit_angle from opendbc.car.subaru.stock_aol import qualified as subaru_aol_qualified from opendbc.car.subaru.values import CAR, DBC, GLOBAL_ES_ADDR, CanBus, CarControllerParams, SubaruFlags from opendbc.car.vehicle_model import VehicleModel @@ -127,8 +127,11 @@ class CarController(CarControllerBase): if (self.frame % self.p.STEER_STEP) == 0: if self.CP.carFingerprint in GEN2_ANGLE_PORTS: independent_lateral = subaru_aol_qualified(self.CP, marked_only=True) - # Match Dom's independent-lateral envelope during large manual turns and parking speeds. - aol_motion_ok = CC.enabled or (CS.out.vEgoRaw > 0.44704 and abs(CS.out.steeringAngleDeg) < 120.) + # Preserve large-turn admission; active Jacobw ports retain their native angle envelope. + angle_continuation = (self.angle_was_active and self.angle_filter is not None and + abs(CS.out.steeringAngleDeg) < JACOBW_MAX_ANGLE) + aol_motion_ok = CC.enabled or (CS.out.vEgoRaw > 0.44704 and + (abs(CS.out.steeringAngleDeg) < 120. or angle_continuation)) angle_available = (CC.latActive and aol_motion_ok and CS.out.cruiseState.available and (independent_lateral or CC.enabled and CS.out.cruiseState.enabled and not CS.out.brakePressed) and CS.out.gearShifter == structs.CarState.GearShifter.drive and diff --git a/opendbc_repo/opendbc/car/subaru/tests/test_angle_handoff.py b/opendbc_repo/opendbc/car/subaru/tests/test_angle_handoff.py index a04c3752b1..603a61c71d 100644 --- a/opendbc_repo/opendbc/car/subaru/tests/test_angle_handoff.py +++ b/opendbc_repo/opendbc/car/subaru/tests/test_angle_handoff.py @@ -2,6 +2,7 @@ import unittest from opendbc.car.subaru.tests.test_ascent_angle import setup_controller, step from opendbc.car.subaru.values import CAR +from opendbc.car import structs class TestAngleHandoff(unittest.TestCase): @@ -98,3 +99,64 @@ class TestIndependentAngleEnvelope(unittest.TestCase): # Follow the small target without jumping to the measured angle. expected = -1.45 * (1. - (30. / 31.) ** 5) self.assertAlmostEqual(decoded['LKAS_Output'], round(expected, 2), places=2) + + +class TestJacobwAngleContinuation(unittest.TestCase): + def test_active_aol_crosses_admission_angle_without_losing_request(self): + for car in (CAR.SUBARU_CROSSTREK_2025, CAR.SUBARU_IMPREZA_2025): + for sign in (-1, 1): + with self.subTest(car=car, sign=sign): + cp, controller, command, state = setup_controller(car) + cp.alternativeExperience = 32 + command.enabled = state.out.cruiseState.enabled = False + command.actuators.steeringAngleDeg = 170 * sign + state.out.vEgoRaw = state.out.vEgo = 4.8 + state.out.standstill = False + state.out.steeringTorque = state.out.steeringRateDeg = 0 + for angle in (115, 119, 120, 121, 140, 170, 189): + state.out.steeringAngleDeg = angle * sign + _, decoded = step(controller, command, state) + self.assertTrue(decoded['LKAS_Request']) + self.assertLessEqual(abs(decoded['LKAS_Output']), 190) + state.out.steeringAngleDeg = 190 * sign + _, decoded = step(controller, command, state) + self.assertFalse(decoded['LKAS_Request']) + state.out.steeringAngleDeg = 140 * sign + for _ in range(3): + _, decoded = step(controller, command, state) + self.assertFalse(decoded['LKAS_Request']) + + def test_continuation_preserves_driver_override_and_all_independent_vetoes(self): + for car in (CAR.SUBARU_CROSSTREK_2025, CAR.SUBARU_IMPREZA_2025): + for veto in ('driver', 'temporary', 'permanent', 'main', 'reverse', 'standstill', 'slow', 'lateral'): + with self.subTest(car=car, veto=veto): + cp, controller, command, state = setup_controller(car) + cp.alternativeExperience = 32 + command.enabled = state.out.cruiseState.enabled = False + command.actuators.steeringAngleDeg = 160 + state.out.vEgoRaw = state.out.vEgo = 4.8 + state.out.standstill = False + state.out.steeringAngleDeg = 110 + state.out.steeringTorque = state.out.steeringRateDeg = 0 + _, decoded = step(controller, command, state) + self.assertTrue(decoded['LKAS_Request']) + state.out.steeringAngleDeg = 140 + if veto == 'driver': + state.out.steeringTorque = 151 + elif veto == 'temporary': + state.out.steerFaultTemporary = True + elif veto == 'permanent': + state.out.steerFaultPermanent = True + elif veto == 'main': + state.out.cruiseState.available = False + elif veto == 'reverse': + state.out.gearShifter = structs.CarState.GearShifter.reverse + elif veto == 'standstill': + state.out.standstill = True + elif veto == 'slow': + state.out.vEgoRaw = .4 + else: + command.latActive = False + for _ in range(2): + _, decoded = step(controller, command, state) + self.assertFalse(decoded['LKAS_Request']) diff --git a/openpilot/starpilot/car/subaru/tests/test_stock_aol_callers.py b/openpilot/starpilot/car/subaru/tests/test_stock_aol_callers.py index 1ec51f23cb..3f9f414f45 100644 --- a/openpilot/starpilot/car/subaru/tests/test_stock_aol_callers.py +++ b/openpilot/starpilot/car/subaru/tests/test_stock_aol_callers.py @@ -28,7 +28,8 @@ def test_actual_full_engage_brake_reverse_temporary_recovery_mainoff(candidate, deadline_gap=False, fixed_angle_handoff=False, host_first_stop=False, source_outage=False, vm_angle_handoff=0, crawl=False, eps_brake_join=False, high_angle_guard=False, main_on_brake=False, guard_brake_release=False, - stopped_feedback_gap=False, rearm_on_brake=0, main_during_eps=False): + stopped_feedback_gap=False, rearm_on_brake=0, main_during_eps=False, + angle_continuation=0): angle_handoff = fixed_angle_handoff or vm_angle_handoff fw = firmware_records(candidate, FW_VERSIONS, 'subaru') if firmware is None else firmware rows = [] @@ -75,7 +76,8 @@ def test_actual_full_engage_brake_reverse_temporary_recovery_mainoff(candidate, published = {} ticks = (list(range(30)) + list(range(30, 50)) * 16 + list(range(50, 460)) if main_during_eps else list(range(125)) + list(range(125, 135)) * 30 + list(range(135, 460)) - if hard_stop_native_first else range(460)) + if hard_stop_native_first else list(range(70)) + list(range(70, 90)) * 16 + list(range(90, 460)) + if angle_continuation else range(460)) gap_tick = 75 if main_only else 210 last_card_published = {} pending_host_can = [] @@ -88,6 +90,7 @@ def test_actual_full_engage_brake_reverse_temporary_recovery_mainoff(candidate, brake = (stopped_feedback_gap and 125 <= tick < 135 or 90 <= tick < 110 or eps_brake_join and 225 <= tick < 270 or main_on_brake and 30 <= tick < 55 or guard_brake_release and 225 <= tick < 245 or rearm_on_brake and 345 <= tick < 365) + brake = bool(brake or angle_continuation and 70 <= tick < 90) reverse = 150 <= tick < 185 temporary = not guard_brake_release and 225 <= tick < 260 main = not 310 <= tick < 350 and (tick >= 30 or not main_only) @@ -134,6 +137,9 @@ def test_actual_full_engage_brake_reverse_temporary_recovery_mainoff(candidate, if 225 <= tick < 260: values['Steering_Torque'].update(Steering_Angle=100, Steer_Torque_Sensor=94) values['Wheel_Speeds'] = dict.fromkeys(('FL', 'FR', 'RL', 'RR'), 8) + if angle_continuation: + values['Steering_2']['Steering_Angle'] = ci.CC.apply_angle_last if tick < 90 else 0 + values['Wheel_Speeds'] = dict.fromkeys(('FL', 'FR', 'RL', 'RR'), 17.28) incoming = stream.frames(values, tick=tick) if source_outage: pending_host_can.append((now, incoming)) @@ -233,6 +239,11 @@ def test_actual_full_engage_brake_reverse_temporary_recovery_mainoff(candidate, if aol and tick % 10 == 0: receipt, order = pandad.step(driven, published, now) feed_perception_only(controls, now, elapsed, enabled=sd.enabled, active=sd.active) + if angle_continuation and tick < 90: + import math + model = controls.sm['modelV2'].as_builder() + model.action.desiredCurvature = -controls.VM.calc_curvature(math.radians(160 * angle_continuation), 4.8, 0.) + controls.sm.data['modelV2'] = model.as_reader() plan = messaging.new_message('longitudinalPlan', valid=True, logMonoTime=now) plan.longitudinalPlan.aTarget = 0.5 control_peers = [published['carState'], published['carOutput'], plan.as_reader()] @@ -272,6 +283,9 @@ def test_actual_full_engage_brake_reverse_temporary_recovery_mainoff(candidate, request = bool(decoder.vl[steering_name]['LKAS_Request']) output = decoder.vl[steering_name]['LKAS_Output'] decoded_steering.append({'request': request, 'output': output, 'nativeAccepted': accepted}) + if angle_continuation and 65 <= tick < 90 and abs(cs.steeringAngleDeg) >= 120: + assert not command.enabled and not cs.steeringPressed and not cs.steerFaultTemporary + assert request and accepted, ('SUBARU_ACTIVE_ANGLE_ADMISSION_CLIFF', tick, cs.steeringAngleDeg, decoded_steering) if crawl and 95 <= tick < 105: assert aol and main_only and cs.brakePressed and not command.enabled assert request and accepted, ('CRAWL_AOL_BRAKE_WITHDREW', tick, decoded_steering) @@ -572,3 +586,14 @@ def test_actual_impreza2025_automatic_full_stack(subaru_native_pair, tmp_path, f test_actual_full_engage_brake_reverse_temporary_recovery_mainoff( CAR.SUBARU_IMPREZA_2025, subaru_native_pair, tmp_path, main_only=True, stop_resume=True, hard_stop_native_first=True, firmware=firmware) + + +@pytest.mark.parametrize('candidate', [CAR.SUBARU_CROSSTREK_2025, CAR.SUBARU_IMPREZA_2025]) +@pytest.mark.parametrize('direction', [-1, 1]) +def test_actual_jacobw_aol_continues_through_admission_angle(candidate, direction, subaru_native_pair, tmp_path): + test_actual_full_engage_brake_reverse_temporary_recovery_mainoff( + candidate, subaru_native_pair, tmp_path, main_only=True, angle_continuation=direction) + rows = json.loads((tmp_path / (str(candidate) + '-True-actual.json')).read_text()) + crossing = [frame for row in rows if 65 <= row['tick'] < 90 for frame in row['steering'] if abs(frame['output']) > 120] + assert len(crossing) >= 10 + assert all(frame['request'] and frame['nativeAccepted'] and abs(frame['output']) <= 190 for frame in crossing) diff --git a/prebuilt.json b/prebuilt.json index 255e71be38..262c1a0afb 100644 --- a/prebuilt.json +++ b/prebuilt.json @@ -1 +1 @@ -{"protected_inventory_sha256": "e097b25d58024918d411fa7d65a84064c5c6310e788088c11fe2e58d97b0d20c", "schema_version": 1} +{"protected_inventory_sha256": "a4f076343ab5f49bbd73eb83ae4a6508bb49a880d706a643293ae792572ed465", "schema_version": 1} diff --git a/tools/ci/run_vehicle_tests.py b/tools/ci/run_vehicle_tests.py index 50503c6b73..d559ff91e4 100644 --- a/tools/ci/run_vehicle_tests.py +++ b/tools/ci/run_vehicle_tests.py @@ -275,6 +275,7 @@ RELEASE_TARGETS = ( "openpilot/selfdrive/controls/tests/test_subaru_planner_fcw.py", "opendbc_repo/opendbc/car/subaru/tests/test_supported_firmware.py", "openpilot/starpilot/car/subaru/tests/test_stock_aol_callers.py::test_actual_impreza2025_automatic_full_stack", + "openpilot/starpilot/car/subaru/tests/test_stock_aol_callers.py::test_actual_jacobw_aol_continues_through_admission_angle", "openpilot/starpilot/car/subaru/tests/test_stock_aol_callers.py::test_actual_main_during_temporary_eps_waits_for_clear", "openpilot/starpilot/car/subaru/tests/test_stock_aol_callers.py::test_actual_stopped_feedback_gap_retains_only_armed_intent", "openpilot/starpilot/car/subaru/tests/test_stock_aol_callers.py::test_actual_repeat_main_with_brake_and_signal_pause",