From 30c41788dcaba3694945362368464d4283a288ab Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Wed, 5 Jun 2024 15:58:00 -0700 Subject: [PATCH] thermald is hardwared (#32637) * thermald is deviced * hardwared * rename old-commit-hash: 51fdf2330453fe863597db0eb8daf87c2ec4ff8d --- common/realtime.py | 2 +- pyproject.toml | 3 +-- selfdrive/test/test_onroad.py | 2 +- system/camerad/snapshot/snapshot.py | 2 +- .../{thermald => hardware}/fan_controller.py | 4 ++-- .../thermald.py => hardware/hardwared.py} | 24 +++++++++---------- .../power_monitoring.py | 0 .../{thermald => hardware/tests}/__init__.py | 0 .../tests/test_fan_controller.py | 2 +- .../tests/test_power_monitoring.py | 6 ++--- system/hardware/tici/hardware.py | 2 +- system/manager/process_config.py | 2 +- system/thermald/tests/__init__.py | 0 13 files changed, 24 insertions(+), 25 deletions(-) rename system/{thermald => hardware}/fan_controller.py (94%) rename system/{thermald/thermald.py => hardware/hardwared.py} (96%) rename system/{thermald => hardware}/power_monitoring.py (100%) rename system/{thermald => hardware/tests}/__init__.py (100%) rename system/{thermald => hardware}/tests/test_fan_controller.py (96%) rename system/{thermald => hardware}/tests/test_power_monitoring.py (97%) delete mode 100644 system/thermald/tests/__init__.py diff --git a/common/realtime.py b/common/realtime.py index 16e9a220e6..dd97ea3d78 100644 --- a/common/realtime.py +++ b/common/realtime.py @@ -12,7 +12,7 @@ from openpilot.system.hardware import PC # time step for each process DT_CTRL = 0.01 # controlsd DT_MDL = 0.05 # model -DT_TRML = 0.5 # thermald and manager +DT_HW = 0.5 # hardwared and manager DT_DMON = 0.05 # driver monitoring diff --git a/pyproject.toml b/pyproject.toml index 5f69948297..8642eff4cd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,10 +29,9 @@ testpaths = [ "selfdrive/test/longitudinal_maneuvers", "selfdrive/test/process_replay/test_fuzzy.py", "system/updated", - "system/thermald", "system/athena", "system/camerad", - "system/hardware/tici", + "system/hardware", "system/loggerd", "system/proclogd", "system/tests", diff --git a/selfdrive/test/test_onroad.py b/selfdrive/test/test_onroad.py index bcdf71f8e8..75585e2f14 100644 --- a/selfdrive/test/test_onroad.py +++ b/selfdrive/test/test_onroad.py @@ -47,7 +47,7 @@ PROCS = { "selfdrive.controls.radard": 7.0, "selfdrive.modeld.modeld": 13.0, "selfdrive.modeld.dmonitoringmodeld": 8.0, - "system.thermald.thermald": 3.87, + "system.hardware.hardwared": 3.87, "selfdrive.locationd.calibrationd": 2.0, "selfdrive.locationd.torqued": 5.0, "selfdrive.ui.soundd": 3.5, diff --git a/system/camerad/snapshot/snapshot.py b/system/camerad/snapshot/snapshot.py index d9377eebe9..381240212b 100755 --- a/system/camerad/snapshot/snapshot.py +++ b/system/camerad/snapshot/snapshot.py @@ -83,7 +83,7 @@ def snapshot(): front_camera_allowed = params.get_bool("RecordFront") params.put_bool("IsTakingSnapshot", True) set_offroad_alert("Offroad_IsTakingSnapshot", True) - time.sleep(2.0) # Give thermald time to read the param, or if just started give camerad time to start + time.sleep(2.0) # Give hardwared time to read the param, or if just started give camerad time to start # Check if camerad is already started try: diff --git a/system/thermald/fan_controller.py b/system/hardware/fan_controller.py similarity index 94% rename from system/thermald/fan_controller.py rename to system/hardware/fan_controller.py index 19c3292ce2..f32133f6bf 100755 --- a/system/thermald/fan_controller.py +++ b/system/hardware/fan_controller.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 from abc import ABC, abstractmethod -from openpilot.common.realtime import DT_TRML +from openpilot.common.realtime import DT_HW from openpilot.common.numpy_fast import interp from openpilot.common.swaglog import cloudlog from openpilot.selfdrive.controls.lib.pid import PIDController @@ -18,7 +18,7 @@ class TiciFanController(BaseFanController): cloudlog.info("Setting up TICI fan handler") self.last_ignition = False - self.controller = PIDController(k_p=0, k_i=4e-3, k_f=1, rate=(1 / DT_TRML)) + self.controller = PIDController(k_p=0, k_i=4e-3, k_f=1, rate=(1 / DT_HW)) def update(self, cur_temp: float, ignition: bool) -> int: self.controller.neg_limit = -(100 if ignition else 30) diff --git a/system/thermald/thermald.py b/system/hardware/hardwared.py similarity index 96% rename from system/thermald/thermald.py rename to system/hardware/hardwared.py index 90f6494a26..e3a4c81711 100755 --- a/system/thermald/thermald.py +++ b/system/hardware/hardwared.py @@ -15,14 +15,14 @@ from cereal.services import SERVICE_LIST from openpilot.common.dict_helpers import strip_deprecated_keys from openpilot.common.filter_simple import FirstOrderFilter from openpilot.common.params import Params -from openpilot.common.realtime import DT_TRML +from openpilot.common.realtime import DT_HW from openpilot.selfdrive.controls.lib.alertmanager import set_offroad_alert from openpilot.system.hardware import HARDWARE, TICI, AGNOS from openpilot.system.loggerd.config import get_available_percent from openpilot.system.statsd import statlog from openpilot.common.swaglog import cloudlog -from openpilot.system.thermald.power_monitoring import PowerMonitoring -from openpilot.system.thermald.fan_controller import TiciFanController +from openpilot.system.hardware.power_monitoring import PowerMonitoring +from openpilot.system.hardware.fan_controller import TiciFanController from openpilot.system.version import terms_version, training_version ThermalStatus = log.DeviceState.ThermalStatus @@ -106,7 +106,7 @@ def hw_state_thread(end_event, hw_queue): while not end_event.is_set(): # these are expensive calls. update every 10s - if (count % int(10. / DT_TRML)) == 0: + if (count % int(10. / DT_HW)) == 0: try: network_type = HARDWARE.get_network_type() modem_temps = HARDWARE.get_modem_temperatures() @@ -159,10 +159,10 @@ def hw_state_thread(end_event, hw_queue): cloudlog.exception("Error getting hardware state") count += 1 - time.sleep(DT_TRML) + time.sleep(DT_HW) -def thermald_thread(end_event, hw_queue) -> None: +def hardware_thread(end_event, hw_queue) -> None: pm = messaging.PubMaster(['deviceState']) sm = messaging.SubMaster(["peripheralState", "gpsLocationExternal", "controlsState", "pandaStates"], poll="pandaStates") @@ -190,8 +190,8 @@ def thermald_thread(end_event, hw_queue) -> None: modem_temps=[], ) - all_temp_filter = FirstOrderFilter(0., TEMP_TAU, DT_TRML, initialized=False) - offroad_temp_filter = FirstOrderFilter(0., TEMP_TAU, DT_TRML, initialized=False) + all_temp_filter = FirstOrderFilter(0., TEMP_TAU, DT_HW, initialized=False) + offroad_temp_filter = FirstOrderFilter(0., TEMP_TAU, DT_HW, initialized=False) should_start_prev = False in_car = False engaged_prev = False @@ -232,7 +232,7 @@ def thermald_thread(end_event, hw_queue) -> None: # Run at 2Hz, plus rising edge of ignition ign_edge = started_ts is None and onroad_conditions["ignition"] - if (sm.frame % round(SERVICE_LIST['pandaStates'].frequency * DT_TRML) != 0) and not ign_edge: + if (sm.frame % round(SERVICE_LIST['pandaStates'].frequency * DT_HW) != 0) and not ign_edge: continue msg = read_thermal(thermal_config) @@ -349,7 +349,7 @@ def thermald_thread(end_event, hw_queue) -> None: try: with open('/dev/kmsg', 'w') as kmsg: - kmsg.write(f"<3>[thermald] engaged: {engaged}\n") + kmsg.write(f"<3>[hardware] engaged: {engaged}\n") except Exception: pass @@ -423,7 +423,7 @@ def thermald_thread(end_event, hw_queue) -> None: # report to server once every 10 minutes rising_edge_started = should_start and not should_start_prev - if rising_edge_started or (count % int(600. / DT_TRML)) == 0: + if rising_edge_started or (count % int(600. / DT_HW)) == 0: dat = { 'count': count, 'pandaStates': [strip_deprecated_keys(p.to_dict()) for p in pandaStates], @@ -452,7 +452,7 @@ def main(): threads = [ threading.Thread(target=hw_state_thread, args=(end_event, hw_queue)), - threading.Thread(target=thermald_thread, args=(end_event, hw_queue)), + threading.Thread(target=hardware_thread, args=(end_event, hw_queue)), ] for t in threads: diff --git a/system/thermald/power_monitoring.py b/system/hardware/power_monitoring.py similarity index 100% rename from system/thermald/power_monitoring.py rename to system/hardware/power_monitoring.py diff --git a/system/thermald/__init__.py b/system/hardware/tests/__init__.py similarity index 100% rename from system/thermald/__init__.py rename to system/hardware/tests/__init__.py diff --git a/system/thermald/tests/test_fan_controller.py b/system/hardware/tests/test_fan_controller.py similarity index 96% rename from system/thermald/tests/test_fan_controller.py rename to system/hardware/tests/test_fan_controller.py index ffbf180acc..002c1edfda 100644 --- a/system/thermald/tests/test_fan_controller.py +++ b/system/hardware/tests/test_fan_controller.py @@ -1,6 +1,6 @@ import pytest -from openpilot.system.thermald.fan_controller import TiciFanController +from openpilot.system.hardware.fan_controller import TiciFanController ALL_CONTROLLERS = [TiciFanController] diff --git a/system/thermald/tests/test_power_monitoring.py b/system/hardware/tests/test_power_monitoring.py similarity index 97% rename from system/thermald/tests/test_power_monitoring.py rename to system/hardware/tests/test_power_monitoring.py index 95166094b3..1dff6c6c5f 100644 --- a/system/thermald/tests/test_power_monitoring.py +++ b/system/hardware/tests/test_power_monitoring.py @@ -1,7 +1,7 @@ import pytest from openpilot.common.params import Params -from openpilot.system.thermald.power_monitoring import PowerMonitoring, CAR_BATTERY_CAPACITY_uWh, \ +from openpilot.system.hardware.power_monitoring import PowerMonitoring, CAR_BATTERY_CAPACITY_uWh, \ CAR_CHARGING_RATE_W, VBATT_PAUSE_CHARGING, DELAY_SHUTDOWN_TIME_S # Create fake time @@ -17,9 +17,9 @@ VOLTAGE_BELOW_PAUSE_CHARGING = (VBATT_PAUSE_CHARGING - 1) * 1e3 def pm_patch(mocker, name, value, constant=False): if constant: - mocker.patch(f"openpilot.system.thermald.power_monitoring.{name}", value) + mocker.patch(f"openpilot.system.hardware.power_monitoring.{name}", value) else: - mocker.patch(f"openpilot.system.thermald.power_monitoring.{name}", return_value=value) + mocker.patch(f"openpilot.system.hardware.power_monitoring.{name}", return_value=value) @pytest.fixture(autouse=True) diff --git a/system/hardware/tici/hardware.py b/system/hardware/tici/hardware.py index b6b41c4728..a5dee88b56 100644 --- a/system/hardware/tici/hardware.py +++ b/system/hardware/tici/hardware.py @@ -412,7 +412,7 @@ class Tici(HardwareBase): if self.amplifier is not None: self.amplifier.initialize_configuration(self.get_device_type()) - # Allow thermald to write engagement status to kmsg + # Allow hardwared to write engagement status to kmsg os.system("sudo chmod a+w /dev/kmsg") # Ensure fan gpio is enabled so fan runs until shutdown, also turned on at boot by the ABL diff --git a/system/manager/process_config.py b/system/manager/process_config.py index 25c5f46497..ced31077c9 100644 --- a/system/manager/process_config.py +++ b/system/manager/process_config.py @@ -76,7 +76,7 @@ procs = [ PythonProcess("pigeond", "system.ubloxd.pigeond", ublox, enabled=TICI), PythonProcess("plannerd", "selfdrive.controls.plannerd", only_onroad), PythonProcess("radard", "selfdrive.controls.radard", only_onroad), - PythonProcess("thermald", "system.thermald.thermald", always_run), + PythonProcess("hardwared", "system.hardware.hardwared", always_run), PythonProcess("tombstoned", "system.tombstoned", always_run, enabled=not PC), PythonProcess("updated", "system.updated.updated", only_offroad, enabled=not PC), PythonProcess("uploader", "system.loggerd.uploader", always_run), diff --git a/system/thermald/tests/__init__.py b/system/thermald/tests/__init__.py deleted file mode 100644 index e69de29bb2..0000000000