From 3a6491e23a8390371b29547f86d01fd15c463102 Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Wed, 14 May 2025 17:46:55 -0400 Subject: [PATCH] MADS: allow transition from Paused to Enabled at all times (#910) * MADS: silentBrakeHold should not exit control * no longer * allow transition from paused to enabled when long is allowed --- sunnypilot/mads/mads.py | 10 +++++----- sunnypilot/mads/state.py | 2 +- sunnypilot/mads/tests/test_mads_state_machine.py | 2 +- sunnypilot/selfdrive/selfdrived/events.py | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/sunnypilot/mads/mads.py b/sunnypilot/mads/mads.py index d27e2f1fc..9aeb67972 100644 --- a/sunnypilot/mads/mads.py +++ b/sunnypilot/mads/mads.py @@ -89,11 +89,6 @@ class ModularAssistiveDrivingSystem: if CS.brakePressed: transition_paused_state() - if not (self.pause_lateral_on_brake_toggle and CS.brakePressed) and \ - not self.events_sp.contains_in_list(GEARS_ALLOW_PAUSED_SILENT): - if self.state_machine.state == State.paused: - self.events_sp.add(EventNameSP.silentLkasEnable) - self.events.remove(EventName.preEnableStandstill) self.events.remove(EventName.belowEngageSpeed) self.events.remove(EventName.speedTooLow) @@ -125,6 +120,11 @@ class ModularAssistiveDrivingSystem: if self.selfdrive.CS_prev.cruiseState.available: self.events_sp.add(EventNameSP.lkasDisable) + if not (self.pause_lateral_on_brake_toggle and CS.brakePressed) and \ + not self.events_sp.contains_in_list(GEARS_ALLOW_PAUSED_SILENT): + if self.state_machine.state == State.paused: + self.events_sp.add(EventNameSP.silentLkasEnable) + self.events.remove(EventName.pcmDisable) self.events.remove(EventName.buttonCancel) self.events.remove(EventName.pedalPressed) diff --git a/sunnypilot/mads/state.py b/sunnypilot/mads/state.py index 89ae506ac..73240c790 100644 --- a/sunnypilot/mads/state.py +++ b/sunnypilot/mads/state.py @@ -51,7 +51,7 @@ class StateMachine: if self.state != State.disabled: # user and immediate disable always have priority in a non-disabled state if self.check_contains(ET.USER_DISABLE): - if self._events_sp.has(EventNameSP.silentLkasDisable) or self._events_sp.has(EventNameSP.silentBrakeHold): + if self._events_sp.has(EventNameSP.silentLkasDisable): self.state = State.paused else: self.state = State.disabled diff --git a/sunnypilot/mads/tests/test_mads_state_machine.py b/sunnypilot/mads/tests/test_mads_state_machine.py index 51013b0ba..7bc556a0f 100644 --- a/sunnypilot/mads/tests/test_mads_state_machine.py +++ b/sunnypilot/mads/tests/test_mads_state_machine.py @@ -73,7 +73,7 @@ class TestMADSStateMachine: self.clear_events() def test_user_disable_to_paused(self): - paused_events = (EventNameSP.silentLkasDisable, EventNameSP.silentBrakeHold) + paused_events = (EventNameSP.silentLkasDisable, ) for state in ALL_STATES: for et in MAINTAIN_STATES[state]: self.events_sp.add(make_event([et, ET.USER_DISABLE])) diff --git a/sunnypilot/selfdrive/selfdrived/events.py b/sunnypilot/selfdrive/selfdrived/events.py index 6813542c0..979de0a80 100644 --- a/sunnypilot/selfdrive/selfdrived/events.py +++ b/sunnypilot/selfdrive/selfdrived/events.py @@ -64,7 +64,7 @@ EVENTS_SP: dict[int, dict[str, Alert | AlertCallbackType]] = { }, EventNameSP.silentBrakeHold: { - ET.USER_DISABLE: EngagementAlert(AudibleAlert.none), + ET.WARNING: EngagementAlert(AudibleAlert.none), ET.NO_ENTRY: NoEntryAlert("Brake Hold Active"), },