diff --git a/openpilot/common/params_keys.h b/openpilot/common/params_keys.h index 5bdfdf86362e40..052b2a90f8765f 100644 --- a/openpilot/common/params_keys.h +++ b/openpilot/common/params_keys.h @@ -56,6 +56,7 @@ inline static std::unordered_map keys = { {"HardwareSerial", {PERSISTENT, STRING}}, {"HasAcceptedTerms", {PERSISTENT, STRING, "0"}}, {"InstallDate", {PERSISTENT, TIME}}, + {"IsAosEnabled", {PERSISTENT, BOOL}}, {"IsDriverViewEnabled", {CLEAR_ON_MANAGER_START, BOOL}}, {"IsEngaged", {PERSISTENT, BOOL}}, {"IsLdwEnabled", {PERSISTENT, BOOL}}, diff --git a/openpilot/selfdrive/selfdrived/events.py b/openpilot/selfdrive/selfdrived/events.py index c9bae1f1d33e87..58d9c5b0b018b7 100755 --- a/openpilot/selfdrive/selfdrived/events.py +++ b/openpilot/selfdrive/selfdrived/events.py @@ -33,7 +33,12 @@ class Priority(IntEnum): # Event types class ET: + # on main, LAT_ENABLE? on set, ENABLE? on brake, USER_DISABLE_LONG? + # or simpler, USER_DISABLE just relates to long, but how should other DISABLEs affect it? + # should NO_ENTRY conditions be different for each mode? should it even play a tone if you turn on main in park after you start the car? + # or should it "enable" and wait until drive? ENABLE = 'enable' + LAT_ENABLE = 'latEnable' PRE_ENABLE = 'preEnable' OVERRIDE_LATERAL = 'overrideLateral' OVERRIDE_LONGITUDINAL = 'overrideLongitudinal' @@ -688,6 +693,11 @@ def invalid_lkas_setting_alert(CP: car.CarParams, CS: car.CarState, sm: messagin ET.ENABLE: EngagementAlert(AudibleAlert.engage), }, + EventName.latEnable: { + # TODO: two different tones? + ET.LAT_ENABLE: EngagementAlert(AudibleAlert.engage), + }, + EventName.pcmDisable: { ET.USER_DISABLE: EngagementAlert(AudibleAlert.disengage), }, diff --git a/openpilot/selfdrive/selfdrived/selfdrived.py b/openpilot/selfdrive/selfdrived/selfdrived.py index f76c161acda597..6ff19fae9eff18 100755 --- a/openpilot/selfdrive/selfdrived/selfdrived.py +++ b/openpilot/selfdrive/selfdrived/selfdrived.py @@ -115,7 +115,9 @@ def __init__(self, CP=None): self.initialized = False self.enabled = False - self.active = False + # i don't think we can keep selfdrived lat/long agnostic since it handles event state machine + self.lat_active = False + self.long_active = False self.mismatch_counter = 0 self.cruise_mismatch_counter = 0 self.last_steering_pressed_frame = 0 @@ -524,7 +526,8 @@ def publish_selfdriveState(self, CS): ss_msg.valid = True ss = ss_msg.selfdriveState ss.enabled = self.enabled - ss.active = self.active + ss.latActive = self.lat_active + ss.longActive = self.long_active ss.state = self.state_machine.state ss.engageable = not self.events.contains(ET.NO_ENTRY) ss.experimentalMode = self.experimental_mode @@ -552,7 +555,7 @@ def step(self): CS = self.data_sample() self.update_events(CS) if not self.CP.passive and self.initialized: - self.enabled, self.active = self.state_machine.update(self.events) + self.enabled, self.long_active = self.state_machine.update(self.events) self.update_alerts(CS) self.publish_selfdriveState(CS) diff --git a/openpilot/selfdrive/selfdrived/state.py b/openpilot/selfdrive/selfdrived/state.py index eca001950371a3..e4dd97e745850f 100644 --- a/openpilot/selfdrive/selfdrived/state.py +++ b/openpilot/selfdrive/selfdrived/state.py @@ -8,6 +8,7 @@ ACTIVE_STATES = (State.enabled, State.softDisabling, State.overriding) ENABLED_STATES = (State.preEnabled, *ACTIVE_STATES) + class StateMachine: def __init__(self): self.current_alert_types = [ET.PERMANENT] @@ -91,8 +92,8 @@ def update(self, events: Events): # Check if openpilot is engaged and actuators are enabled enabled = self.state in ENABLED_STATES - active = self.state in ACTIVE_STATES - if active: + long_active = self.state in ACTIVE_STATES + if long_active: self.current_alert_types.append(ET.WARNING) - return enabled, active + return enabled, long_active diff --git a/openpilot/selfdrive/ui/mici/layouts/settings/toggles.py b/openpilot/selfdrive/ui/mici/layouts/settings/toggles.py index 57cbf9410ba457..382353efad0261 100644 --- a/openpilot/selfdrive/ui/mici/layouts/settings/toggles.py +++ b/openpilot/selfdrive/ui/mici/layouts/settings/toggles.py @@ -44,6 +44,7 @@ def __init__(self): self._personality_toggle = BigMultiParamToggle("driving personality", "LongitudinalPersonality", ["aggressive", "standard", "relaxed"]) self._experimental_btn = BigToggle("experimental mode", initial_state=ui_state.params.get_bool("ExperimentalMode"), toggle_callback=self._on_experimental_mode) + aos_toggle = BigParamControl("always on steering", "IsAosEnabled") is_metric_toggle = BigParamControl("use metric units", "IsMetric") ldw_toggle = BigParamControl("lane departure warnings", "IsLdwEnabled") always_on_dm_toggle = BigParamControl("always-on driver monitor", "AlwaysOnDM") @@ -54,6 +55,7 @@ def __init__(self): self._scroller.add_widgets([ self._personality_toggle, self._experimental_btn, + aos_toggle, is_metric_toggle, ldw_toggle, always_on_dm_toggle, @@ -65,6 +67,7 @@ def __init__(self): # Toggle lists self._refresh_toggles = ( ("ExperimentalMode", self._experimental_btn), + ("IsAosEnabled", aos_toggle), ("IsMetric", is_metric_toggle), ("IsLdwEnabled", ldw_toggle), ("AlwaysOnDM", always_on_dm_toggle),