From ea9d14acae97146524a0d30620f79fa809290710 Mon Sep 17 00:00:00 2001 From: Robbe Derks Date: Mon, 27 Jun 2022 15:33:46 +0200 Subject: [PATCH] Log SOM power draw (#24975) * log SOM power draw * bump cereal Co-authored-by: Comma Device Co-authored-by: Willem Melching --- selfdrive/hardware/base.py | 4 ++++ selfdrive/hardware/pc/hardware.py | 3 +++ selfdrive/hardware/tici/hardware.py | 3 +++ selfdrive/thermald/thermald.py | 13 +++++++------ 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/selfdrive/hardware/base.py b/selfdrive/hardware/base.py index 7e580b1027e903c..76c313de815d21b 100644 --- a/selfdrive/hardware/base.py +++ b/selfdrive/hardware/base.py @@ -110,6 +110,10 @@ def get_usb_present(self): def get_current_power_draw(self): pass + @abstractmethod + def get_som_power_draw(self): + pass + @abstractmethod def shutdown(self): pass diff --git a/selfdrive/hardware/pc/hardware.py b/selfdrive/hardware/pc/hardware.py index 0d85f28bed06b1e..84425d3d14a3757 100644 --- a/selfdrive/hardware/pc/hardware.py +++ b/selfdrive/hardware/pc/hardware.py @@ -73,6 +73,9 @@ def get_usb_present(self): def get_current_power_draw(self): return 0 + + def get_som_power_draw(self): + return 0 def shutdown(self): print("SHUTDOWN!") diff --git a/selfdrive/hardware/tici/hardware.py b/selfdrive/hardware/tici/hardware.py index ea512fa12ba55f1..d3a7de21b6a18cf 100644 --- a/selfdrive/hardware/tici/hardware.py +++ b/selfdrive/hardware/tici/hardware.py @@ -381,6 +381,9 @@ def get_usb_present(self): def get_current_power_draw(self): return (self.read_param_file("/sys/class/hwmon/hwmon1/power1_input", int) / 1e6) + def get_som_power_draw(self): + return (self.read_param_file("/sys/class/power_supply/bms/voltage_now", int) * self.read_param_file("/sys/class/power_supply/bms/current_now", int) / 1e12) + def shutdown(self): # Note that for this to work and have the device stay powered off, the panda needs to be in UsbPowerMode::CLIENT! os.system("sudo poweroff") diff --git a/selfdrive/thermald/thermald.py b/selfdrive/thermald/thermald.py index be3ae771298955d..69f05ebf03e1229 100755 --- a/selfdrive/thermald/thermald.py +++ b/selfdrive/thermald/thermald.py @@ -359,12 +359,13 @@ def thermald_thread(end_event, hw_queue): power_monitor.calculate(peripheralState, onroad_conditions["ignition"]) msg.deviceState.offroadPowerUsageUwh = power_monitor.get_power_used() msg.deviceState.carBatteryCapacityUwh = max(0, power_monitor.get_car_battery_capacity()) - current_power_draw = HARDWARE.get_current_power_draw() # pylint: disable=assignment-from-none - if current_power_draw is not None: - statlog.sample("power_draw", current_power_draw) - msg.deviceState.powerDrawW = current_power_draw - else: - msg.deviceState.powerDrawW = 0 + current_power_draw = HARDWARE.get_current_power_draw() + statlog.sample("power_draw", current_power_draw) + msg.deviceState.powerDrawW = current_power_draw + + som_power_draw = HARDWARE.get_som_power_draw() + statlog.sample("som_power_draw", som_power_draw) + msg.deviceState.somPowerDrawW = som_power_draw # Check if we need to disable charging (handled by boardd) msg.deviceState.chargingDisabled = power_monitor.should_disable_charging(onroad_conditions["ignition"], in_car, off_ts)