thermald: track engaged state in param and kmsg (#23478)

* thermald: track engaged state in param

* write in kmsg

* format string

* move to python
old-commit-hash: 3ce4976db7
commatwo_master
Willem Melching 3 years ago committed by GitHub
parent 020d7d8b57
commit efc06c6290
  1. 2
      selfdrive/common/params.cc
  2. 3
      selfdrive/hardware/tici/hardware.py
  3. 22
      selfdrive/thermald/thermald.py

@ -86,7 +86,6 @@ std::unordered_map<std::string, uint32_t> keys = {
{"AccessToken", CLEAR_ON_MANAGER_START | DONT_LOG},
{"AthenadPid", PERSISTENT},
{"AthenadUploadQueue", PERSISTENT},
{"BootedOnroad", CLEAR_ON_MANAGER_START | CLEAR_ON_IGNITION_OFF},
{"CalibrationParams", PERSISTENT},
{"CarBatteryCapacity", PERSISTENT},
{"CarParams", CLEAR_ON_MANAGER_START | CLEAR_ON_PANDA_DISCONNECT | CLEAR_ON_IGNITION_ON},
@ -121,6 +120,7 @@ std::unordered_map<std::string, uint32_t> keys = {
{"IMEI", PERSISTENT},
{"InstallDate", PERSISTENT},
{"IsDriverViewEnabled", CLEAR_ON_MANAGER_START},
{"IsEngaged", PERSISTENT},
{"IsLdwEnabled", PERSISTENT},
{"IsMetric", PERSISTENT},
{"IsOffroad", CLEAR_ON_MANAGER_START},

@ -320,6 +320,9 @@ class Tici(HardwareBase):
def initialize_hardware(self):
self.amplifier.initialize_configuration()
# Allow thermald to write engagement status to kmsg
os.system("sudo chmod a+w /dev/kmsg")
def get_networks(self):
r = {}

@ -159,7 +159,7 @@ def thermald_thread() -> NoReturn:
pandaState_timeout = int(1000 * 2.5 * DT_TRML) # 2.5x the expected pandaState frequency
pandaState_sock = messaging.sub_sock('pandaStates', timeout=pandaState_timeout)
sm = messaging.SubMaster(["peripheralState", "gpsLocationExternal", "managerState"])
sm = messaging.SubMaster(["peripheralState", "gpsLocationExternal", "managerState", "controlsState"])
fan_speed = 0
count = 0
@ -192,6 +192,7 @@ def thermald_thread() -> NoReturn:
handle_fan = None
is_uno = False
ui_running_prev = False
engaged_prev = False
params = Params()
power_monitor = PowerMonitoring()
@ -203,10 +204,6 @@ def thermald_thread() -> NoReturn:
# TODO: use PI controller for UNO
controller = PIController(k_p=0, k_i=2e-3, neg_limit=-80, pos_limit=0, rate=(1 / DT_TRML))
# Leave flag for loggerd to indicate device was left onroad
if params.get_bool("IsOnroad"):
params.put_bool("BootedOnroad", True)
while True:
pandaStates = messaging.recv_sock(pandaState_sock, wait=True)
@ -359,8 +356,23 @@ def thermald_thread() -> NoReturn:
if should_start != should_start_prev or (count == 0):
params.put_bool("IsOnroad", should_start)
params.put_bool("IsOffroad", not should_start)
params.put_bool("IsEngaged", False)
engaged_prev = False
HARDWARE.set_power_save(not should_start)
if sm.updated['controlsState']:
engaged = sm['controlsState'].enabled
if engaged != engaged_prev:
params.put_bool("IsEngaged", engaged)
engaged_prev = engaged
try:
with open('/dev/kmsg', 'w') as kmsg:
kmsg.write(f"[thermald] engaged: {engaged}")
except Exception:
pass
if should_start:
off_ts = None
if started_ts is None:

Loading…
Cancel
Save