diff --git a/selfdrive/controls/lib/events.py b/selfdrive/controls/lib/events.py index df22d97d6b4ed4..19620cbf4b989d 100644 --- a/selfdrive/controls/lib/events.py +++ b/selfdrive/controls/lib/events.py @@ -251,6 +251,32 @@ def no_gps_alert(CP: car.CarParams, sm: messaging.SubMaster, metric: bool, soft_ AlertStatus.normal, AlertSize.mid, Priority.LOWER, VisualAlert.none, AudibleAlert.none, .2, creation_delay=300.) +# *** debug alerts *** + +def out_of_space_alert(CP: car.CarParams, sm: messaging.SubMaster, metric: bool, soft_disable_time: int) -> Alert: + full_perc = round(100. - sm['deviceState'].freeSpacePercent) + return NormalPermanentAlert("Out of Storage", f"{full_perc}% full") + + +def overheat_alert(CP: car.CarParams, sm: messaging.SubMaster, metric: bool, soft_disable_time: int) -> Alert: + cpu = max(sm['deviceState'].cpuTempC, default=0.) + gpu = max(sm['deviceState'].gpuTempC, default=0.) + temp = max((cpu, gpu, sm['deviceState'].memoryTempC)) + return NormalPermanentAlert("System Overheated", f"{temp} °C") + + +def low_memory_alert(CP: car.CarParams, sm: messaging.SubMaster, metric: bool, soft_disable_time: int) -> Alert: + return NormalPermanentAlert("Low Memory", f"{sm['deviceState'].memoryUsagePercent}% used") + + +def high_cpu_usage_alert(CP: car.CarParams, sm: messaging.SubMaster, metric: bool, soft_disable_time: int) -> Alert: + x = max(sm['deviceState'].cpuUsagePercent, default=0.) + return NormalPermanentAlert("High CPU Usage", f"{x}% used") + + +def modeld_lagging_alert(CP: car.CarParams, sm: messaging.SubMaster, metric: bool, soft_disable_time: int) -> Alert: + return NormalPermanentAlert("Driving model lagging", f"{sm['modelV2'].frameDropPerc}% frames dropped") + def wrong_car_mode_alert(CP: car.CarParams, sm: messaging.SubMaster, metric: bool, soft_disable_time: int) -> Alert: text = "Cruise Mode Disabled" @@ -578,7 +604,7 @@ def joystick_alert(CP: car.CarParams, sm: messaging.SubMaster, metric: bool, sof }, EventName.outOfSpace: { - ET.PERMANENT: NormalPermanentAlert("Out of Storage"), + ET.PERMANENT: out_of_space_alert, ET.NO_ENTRY: NoEntryAlert("Out of Storage"), }, @@ -609,7 +635,7 @@ def joystick_alert(CP: car.CarParams, sm: messaging.SubMaster, metric: bool, sof }, EventName.overheat: { - ET.PERMANENT: NormalPermanentAlert("System Overheated"), + ET.PERMANENT: overheat_alert, ET.SOFT_DISABLE: soft_disable_alert("System Overheated"), ET.NO_ENTRY: NoEntryAlert("System Overheated"), }, @@ -685,6 +711,7 @@ def joystick_alert(CP: car.CarParams, sm: messaging.SubMaster, metric: bool, sof EventName.modeldLagging: { ET.SOFT_DISABLE: soft_disable_alert("Driving model lagging"), ET.NO_ENTRY: NoEntryAlert("Driving model lagging"), + ET.PERMANENT: modeld_lagging_alert, }, # Besides predicting the path, lane lines and lead car data the model also @@ -706,14 +733,14 @@ def joystick_alert(CP: car.CarParams, sm: messaging.SubMaster, metric: bool, sof EventName.lowMemory: { ET.SOFT_DISABLE: soft_disable_alert("Low Memory: Reboot Your Device"), - ET.PERMANENT: NormalPermanentAlert("Low Memory", "Reboot your Device"), + ET.PERMANENT: low_memory_alert, ET.NO_ENTRY: NoEntryAlert("Low Memory: Reboot Your Device"), }, EventName.highCpuUsage: { #ET.SOFT_DISABLE: soft_disable_alert("System Malfunction: Reboot Your Device"), #ET.PERMANENT: NormalPermanentAlert("System Malfunction", "Reboot your Device"), - ET.NO_ENTRY: NoEntryAlert("System Malfunction: Reboot Your Device"), + ET.NO_ENTRY: high_cpu_usage_alert, }, EventName.accFaulted: { diff --git a/selfdrive/debug/cycle_alerts.py b/selfdrive/debug/cycle_alerts.py index f28d5373f44c7f..d097367474d29f 100755 --- a/selfdrive/debug/cycle_alerts.py +++ b/selfdrive/debug/cycle_alerts.py @@ -1,15 +1,11 @@ #!/usr/bin/env python3 -# flake8: noqa -# pylint: skip-file -# type: ignore - import time from cereal import car, log import cereal.messaging as messaging from common.realtime import DT_CTRL from selfdrive.car.honda.interface import CarInterface -from selfdrive.controls.lib.events import ET, EVENTS, Events +from selfdrive.controls.lib.events import ET, Events from selfdrive.controls.lib.alertmanager import AlertManager EventName = car.CarEvent.EventName @@ -33,10 +29,26 @@ def cycle_alerts(duration=200, is_metric=False): (EventName.driverDistracted, ET.WARNING), ] + # debug alerts + alerts = [ + (EventName.highCpuUsage, ET.NO_ENTRY), + (EventName.lowMemory, ET.PERMANENT), + (EventName.overheat, ET.PERMANENT), + (EventName.outOfSpace, ET.PERMANENT), + (EventName.modeldLagging, ET.PERMANENT), + ] + CP = CarInterface.get_params("HONDA CIVIC 2016") sm = messaging.SubMaster(['deviceState', 'pandaStates', 'roadCameraState', 'modelV2', 'liveCalibration', 'driverMonitoringState', 'longitudinalPlan', 'lateralPlan', 'liveLocationKalman']) + sm['deviceState'].freeSpacePercent = 55 + sm['deviceState'].memoryUsagePercent = 55 + sm['deviceState'].cpuTempC = [1, 2, 100] + sm['deviceState'].gpuTempC = [211, 2, 100] + sm['deviceState'].cpuUsagePercent = [23, 54] + sm['modelV2'].frameDropPerc = 20 + pm = messaging.PubMaster(['controlsState', 'pandaStates', 'deviceState']) events = Events() @@ -44,30 +56,27 @@ def cycle_alerts(duration=200, is_metric=False): frame = 0 while True: - current_alert_types = [ET.PERMANENT, ET.USER_DISABLE, ET.IMMEDIATE_DISABLE, - ET.SOFT_DISABLE, ET.PRE_ENABLE, ET.NO_ENTRY, - ET.ENABLE, ET.WARNING] - for alert, et in alerts: events.clear() events.add(alert) a = events.create_alerts([et, ], [CP, sm, is_metric, 0]) AM.add_many(frame, a) - AM.process_alerts(frame) - print(AM.alert) + alert = AM.process_alerts(frame, []) + print(alert) for _ in range(duration): dat = messaging.new_message() dat.init('controlsState') - dat.controlsState.enabled = True - - dat.controlsState.alertText1 = AM.alert_text_1 - dat.controlsState.alertText2 = AM.alert_text_2 - dat.controlsState.alertSize = AM.alert_size - dat.controlsState.alertStatus = AM.alert_status - dat.controlsState.alertBlinkingRate = AM.alert_rate - dat.controlsState.alertType = AM.alert_type - dat.controlsState.alertSound = AM.audible_alert + dat.controlsState.enabled = False + + if alert: + dat.controlsState.alertText1 = alert.alert_text_1 + dat.controlsState.alertText2 = alert.alert_text_2 + dat.controlsState.alertSize = alert.alert_size + dat.controlsState.alertStatus = alert.alert_status + dat.controlsState.alertBlinkingRate = alert.alert_rate + dat.controlsState.alertType = alert.alert_type + dat.controlsState.alertSound = alert.audible_alert pm.send('controlsState', dat) dat = messaging.new_message()