Skip to content
Draft
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
1 change: 1 addition & 0 deletions openpilot/common/params_keys.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ inline static std::unordered_map<std::string, ParamKeyAttributes> 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}},
Expand Down
10 changes: 10 additions & 0 deletions openpilot/selfdrive/selfdrived/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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),
},
Expand Down
9 changes: 6 additions & 3 deletions openpilot/selfdrive/selfdrived/selfdrived.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions openpilot/selfdrive/selfdrived/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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

3 changes: 3 additions & 0 deletions openpilot/selfdrive/ui/mici/layouts/settings/toggles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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,
Expand All @@ -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),
Expand Down
Loading