mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-07-23 14:22:06 +08:00
14318d2f09
# Conflicts: # .github/labeler.yaml # .github/workflows/auto_pr_review.yaml # .github/workflows/docs.yaml # .github/workflows/release.yaml # .github/workflows/repo-maintenance.yaml # .github/workflows/tests.yaml # .github/workflows/ui_preview.yaml # README.md # SConstruct # conftest.py # docs/CARS.md # msgq_repo # opendbc_repo # openpilot/cereal/messaging/tests/validate_sp_cereal_upstream.py # openpilot/common/api.py # openpilot/common/hardware/hw.py # openpilot/common/version.py # openpilot/selfdrive/assets/fonts/Audiowide-Regular.ttf # openpilot/selfdrive/assets/sounds/prompt_single_high.wav # openpilot/selfdrive/assets/sounds/prompt_single_low.wav # openpilot/selfdrive/car/card.py # openpilot/selfdrive/car/helpers.py # openpilot/selfdrive/car/tests/test_car_interfaces.py # openpilot/selfdrive/car/tests/test_cruise_speed.py # openpilot/selfdrive/controls/lib/desire_helper.py # openpilot/selfdrive/controls/lib/longcontrol.py # openpilot/selfdrive/controls/plannerd.py # openpilot/selfdrive/controls/radard.py # openpilot/selfdrive/controls/tests/test_longcontrol.py # openpilot/selfdrive/modeld/compile_warp.py # openpilot/selfdrive/modeld/modeld.py # openpilot/selfdrive/monitoring/policy.py # openpilot/selfdrive/monitoring/test_monitoring.py # openpilot/selfdrive/selfdrived/events.py # openpilot/selfdrive/selfdrived/selfdrived.py # openpilot/selfdrive/ui/layouts/onboarding.py # openpilot/selfdrive/ui/mici/layouts/onboarding.py # openpilot/selfdrive/ui/soundd.py # openpilot/selfdrive/ui/tests/diff/replay.py # openpilot/selfdrive/ui/translations/app.pot # openpilot/system/athena/athenad.py # openpilot/system/athena/manage_athenad.py # openpilot/system/hardware/hardwared.py # openpilot/system/loggerd/config.py # openpilot/system/manager/github_runner.sh # openpilot/system/manager/manager.py # openpilot/system/updated/updated.py # panda # pyproject.toml # scripts/lint/lint.sh # system/manager/process_config.py # system/statsd.py # tinygrad_repo # tools/release/build_release.sh # tools/release/build_stripped.sh # uv.lock
53 lines
1.7 KiB
Python
Executable File
53 lines
1.7 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
import openpilot.cereal.messaging as messaging
|
|
from openpilot.common.params import Params
|
|
from openpilot.common.realtime import config_realtime_process
|
|
from openpilot.selfdrive.monitoring.policy import DriverMonitoring
|
|
|
|
|
|
def dmonitoringd_thread():
|
|
config_realtime_process([0, 1, 2, 3], 5)
|
|
|
|
params = Params()
|
|
pm = messaging.PubMaster(['driverMonitoringState'])
|
|
sm = messaging.SubMaster(['driverStateV2', 'liveCalibration', 'carState', 'selfdriveState', 'modelV2',
|
|
'carControl'], poll='driverStateV2')
|
|
|
|
DM = DriverMonitoring(rhd_saved=params.get_bool("IsRhdDetected"), always_on=params.get_bool("AlwaysOnDM"))
|
|
demo_mode=False
|
|
|
|
# 20Hz <- dmonitoringmodeld
|
|
while True:
|
|
sm.update()
|
|
if not sm.updated['driverStateV2']:
|
|
# iterate when model has new output
|
|
continue
|
|
|
|
valid = sm.all_checks()
|
|
if demo_mode and sm.valid['driverStateV2']:
|
|
DM.run_step(sm, demo=True)
|
|
elif valid:
|
|
DM.run_step(sm, demo=demo_mode)
|
|
|
|
# publish
|
|
dat = DM.get_state_packet(valid=valid)
|
|
pm.send('driverMonitoringState', dat)
|
|
|
|
# load live always-on toggle
|
|
if sm['driverStateV2'].frameId % 40 == 1:
|
|
DM.always_on = params.get_bool("AlwaysOnDM")
|
|
demo_mode = params.get_bool("IsDriverViewEnabled")
|
|
|
|
# save rhd virtual toggle every 5 mins
|
|
if (sm['driverStateV2'].frameId % 6000 == 0 and not demo_mode and
|
|
DM.wheelpos_offsetter.filtered_stat.n > DM.settings._WHEELPOS_FILTER_MIN_COUNT and
|
|
DM.wheel_on_right == (DM.wheelpos_offsetter.filtered_stat.M > DM.settings._WHEELPOS_THRESHOLD)):
|
|
params.put_bool("IsRhdDetected", DM.wheel_on_right)
|
|
|
|
def main():
|
|
dmonitoringd_thread()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|