Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions opendbc/car/tesla/preap/carcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
20 changes: 6 additions & 14 deletions opendbc/car/tesla/preap/tests/test_pedal_authority.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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):
Expand Down
Loading