From 4fb2c5c16c8b65206fed2ff4a1c2e960c83d4c0e Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Wed, 20 Nov 2024 11:22:58 -0500 Subject: [PATCH] in lists --- selfdrive/selfdrived/events.py | 3 +++ sunnypilot/mads/mads.py | 6 ++---- sunnypilot/mads/state.py | 7 ++++++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/selfdrive/selfdrived/events.py b/selfdrive/selfdrived/events.py index 700e2701c3..db1e54d0e6 100755 --- a/selfdrive/selfdrived/events.py +++ b/selfdrive/selfdrived/events.py @@ -108,6 +108,9 @@ class Events: def has(self, event_name: int) -> bool: return event_name in self.events + def has_list(self, events_list: list[int]) -> bool: + return all(event_name in self.events for event_name in events_list) + def remove(self, event_name: int, static: bool = False) -> None: if static and event_name in self.static_events: self.static_events.remove(event_name) diff --git a/sunnypilot/mads/mads.py b/sunnypilot/mads/mads.py index 824da8eb9e..34994c8777 100644 --- a/sunnypilot/mads/mads.py +++ b/sunnypilot/mads/mads.py @@ -4,7 +4,7 @@ from opendbc.car.hyundai.values import HyundaiFlags from opendbc.sunnypilot.car.hyundai.values import HyundaiFlagsSP from openpilot.sunnypilot.mads.helpers import MadsParams -from openpilot.sunnypilot.mads.state import StateMachine +from openpilot.sunnypilot.mads.state import StateMachine, GEARS_ALLOW_PAUSED_SILENT State = custom.SelfdriveStateSP.ModularAssistiveDrivingSystem.ModularAssistiveDrivingSystemState ButtonType = car.CarState.ButtonEvent.Type @@ -58,9 +58,7 @@ class ModularAssistiveDrivingSystem: self.selfdrive.events.replace(EventName.brakeHold, EventName.silentBrakeHold) transition_paused_state() - if not self.selfdrive.events.has(EventName.silentWrongGear) and \ - not self.selfdrive.events.has(EventName.silentReverseGear) and \ - not self.selfdrive.events.has(EventName.silentBrakeHold): + if self.selfdrive.events.has_list(GEARS_ALLOW_PAUSED_SILENT): update_silent_lkas_enable() if self.disengage_lateral_on_brake_toggle: diff --git a/sunnypilot/mads/state.py b/sunnypilot/mads/state.py index 0896532157..161d25ec90 100644 --- a/sunnypilot/mads/state.py +++ b/sunnypilot/mads/state.py @@ -9,6 +9,10 @@ EventName = log.OnroadEvent.EventName ACTIVE_STATES = (State.enabled, State.softDisabling, State.overriding) ENABLED_STATES = (State.paused, *ACTIVE_STATES) +GEARS_ALLOW_PAUSED_SILENT = [EventName.silentWrongGear, EventName.silentReverseGear, EventName.silentBrakeHold] +GEARS_ALLOW_PAUSED = [EventName.wrongGear, EventName.reverseGear, EventName.brakeHold, *GEARS_ALLOW_PAUSED_SILENT] +ALLOW_PAUSED = [EventName.silentPedalPressed, *GEARS_ALLOW_PAUSED] + class StateMachine: def __init__(self, mads): @@ -96,7 +100,8 @@ class StateMachine: elif self.state == State.disabled: if events.contains(ET.ENABLE): if events.contains(ET.NO_ENTRY): - self.state = State.paused + if events.has_list(ALLOW_PAUSED): + self.state = State.paused self.add_current_alert_types(ET.NO_ENTRY) else: