This commit is contained in:
Jason Wen
2024-11-20 11:22:58 -05:00
parent 692055df39
commit 4fb2c5c16c
3 changed files with 11 additions and 5 deletions
+3
View File
@@ -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)
+2 -4
View File
@@ -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:
+6 -1
View File
@@ -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: