From 49dcfe81c3e196ad060f81861ca6854549f252fe Mon Sep 17 00:00:00 2001 From: jjackbrandt Date: Sun, 30 Aug 2026 01:41:38 +0000 Subject: [PATCH] tesla_preap: restore regen prompt thresholds Keep the looping sound on the openpilot side. Fire again only when the command is deep in regen, the shortfall is larger, and evidence has 0.8s instead of 0.5s. --- opendbc/car/tesla/preap/carcontroller.py | 17 ++++++++-------- .../tesla/preap/tests/test_pedal_authority.py | 20 ++++++------------- 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/opendbc/car/tesla/preap/carcontroller.py b/opendbc/car/tesla/preap/carcontroller.py index 391cfd5c4ba..16d6978d40a 100644 --- a/opendbc/car/tesla/preap/carcontroller.py +++ b/opendbc/car/tesla/preap/carcontroller.py @@ -37,17 +37,16 @@ def init_preap_can(dbc_names, packers): # consecutive dwell can never complete. Evidence instead accumulates in a # saturating up/down counter, which also rides through single-update # shortfall noise. Trigger and clear thresholds are separated so the visible -# prompt cannot chatter. Thresholds are biased early so the driver has time -# to add friction brake. -REGEN_DECEL_PROMPT_DWELL_UPDATES = 25 # 0.5s of net evidence at 50Hz +# prompt cannot chatter. +REGEN_DECEL_PROMPT_DWELL_UPDATES = 40 # 0.8s of net evidence at 50Hz REGEN_DECEL_PROMPT_MIN_SPEED = 2.0 # m/s; do not prompt for a stopped/settling car REGEN_DECEL_PROMPT_CLEAR_SPEED = 1.0 # m/s -REGEN_DECEL_SHORTFALL_TRIGGER = 0.20 # m/s² -REGEN_DECEL_SHORTFALL_CLEAR = 0.08 # m/s² -REGEN_COMMAND_TRIGGER_DI = -1.0 # command in the regen range -REGEN_COMMAND_CLEAR_DI = -0.5 -REGEN_DECEL_REQUEST_TRIGGER = -0.35 # m/s²; a meaningful deceleration request -REGEN_DECEL_REQUEST_CLEAR = -0.15 # m/s² +REGEN_DECEL_SHORTFALL_TRIGGER = 0.35 # m/s² +REGEN_DECEL_SHORTFALL_CLEAR = 0.15 # m/s² +REGEN_COMMAND_TRIGGER_DI = -2.0 # command deep in the regen range +REGEN_COMMAND_CLEAR_DI = -1.0 +REGEN_DECEL_REQUEST_TRIGGER = -0.5 # m/s²; a meaningful deceleration request +REGEN_DECEL_REQUEST_CLEAR = -0.2 # m/s² class RegenDecelMonitor: diff --git a/opendbc/car/tesla/preap/tests/test_pedal_authority.py b/opendbc/car/tesla/preap/tests/test_pedal_authority.py index 0af3fde9073..f31c860052c 100644 --- a/opendbc/car/tesla/preap/tests/test_pedal_authority.py +++ b/opendbc/car/tesla/preap/tests/test_pedal_authority.py @@ -835,10 +835,9 @@ def test_regen_prompt_uses_hysteresis_and_clears_when_decel_recovers(): # These values have crossed back over the trigger thresholds, but remain # inside the clear thresholds so sensor noise cannot chatter the prompt. - # shortfall 0.15 m/s²: below 0.20 trigger, above 0.08 clear. - assert _update_regen_monitor(monitor, actual_accel=-1.35, v_ego=1.5, pedal_di=-4.25) + assert _update_regen_monitor(monitor, actual_accel=-1.25, v_ego=1.5, pedal_di=-4.25) - assert not _update_regen_monitor(monitor, actual_accel=-1.45) + assert not _update_regen_monitor(monitor, actual_accel=-1.35) assert not monitor.active @@ -860,26 +859,19 @@ def test_regen_prompt_survives_brief_shortfall_dropouts(): for _ in range(3 * REGEN_DECEL_PROMPT_DWELL_UPDATES): for _ in range(9): fired = _update_regen_monitor(monitor) or fired - # shortfall 0.15 m/s²: below the 0.20 trigger, above the 0.08 clear - fired = _update_regen_monitor(monitor, actual_accel=-1.35) or fired + # shortfall 0.3 m/s²: below the trigger, above the clear threshold + fired = _update_regen_monitor(monitor, actual_accel=-1.2) or fired if fired: break assert fired -def test_regen_prompt_requires_regen_command(): - # A command still on the gas/coast side has regen authority left; the +def test_regen_prompt_requires_deep_regen_command(): + # A command still in the shallow-regen range has authority left; the # driver does not need the brake yet. monitor = RegenDecelMonitor() for _ in range(3 * REGEN_DECEL_PROMPT_DWELL_UPDATES): - assert not _update_regen_monitor(monitor, pedal_di=0.0) - - -def test_regen_prompt_fires_in_shallow_regen_command(): - monitor = RegenDecelMonitor() - for _ in range(REGEN_DECEL_PROMPT_DWELL_UPDATES - 1): assert not _update_regen_monitor(monitor, pedal_di=-1.5) - assert _update_regen_monitor(monitor, pedal_di=-1.5) def _replay_fixture(name):