more comma two cleanup (#24300)

* more comma two cleanup

* fix up power monitoring
old-commit-hash: 6a48a7acef
taco
Adeeb Shihadeh 3 years ago committed by GitHub
parent 39de4d80b4
commit 5659b6e6ce
  1. 1
      release/files_common
  2. 651
      selfdrive/camerad/cameras/sensor_i2c.h
  3. 24
      selfdrive/hardware/base.py
  4. 18
      selfdrive/hardware/pc/hardware.py
  5. 19
      selfdrive/hardware/tici/hardware.py
  6. 51
      selfdrive/thermald/power_monitoring.py
  7. 11
      selfdrive/thermald/tests/test_power_monitoring.py
  8. 2
      selfdrive/thermald/thermald.py

@ -302,7 +302,6 @@ selfdrive/camerad/cameras/camera_common.h
selfdrive/camerad/cameras/camera_common.cc selfdrive/camerad/cameras/camera_common.cc
selfdrive/camerad/cameras/camera_replay.cc selfdrive/camerad/cameras/camera_replay.cc
selfdrive/camerad/cameras/camera_replay.h selfdrive/camerad/cameras/camera_replay.h
selfdrive/camerad/cameras/sensor_i2c.h
selfdrive/camerad/cameras/sensor2_i2c.h selfdrive/camerad/cameras/sensor2_i2c.h
selfdrive/camerad/transforms/rgb_to_yuv.cc selfdrive/camerad/transforms/rgb_to_yuv.cc

File diff suppressed because one or more lines are too long

@ -78,30 +78,6 @@ class HardwareBase(ABC):
def set_bandwidth_limit(upload_speed_kbps: int, download_speed_kbps: int) -> None: def set_bandwidth_limit(upload_speed_kbps: int, download_speed_kbps: int) -> None:
pass pass
@abstractmethod
def get_battery_capacity(self):
pass
@abstractmethod
def get_battery_status(self):
pass
@abstractmethod
def get_battery_current(self):
pass
@abstractmethod
def get_battery_voltage(self):
pass
@abstractmethod
def get_battery_charging(self):
pass
@abstractmethod
def set_battery_charging(self, on):
pass
@abstractmethod @abstractmethod
def get_usb_present(self): def get_usb_present(self):
pass pass

@ -50,24 +50,6 @@ class Pc(HardwareBase):
def get_network_strength(self, network_type): def get_network_strength(self, network_type):
return NetworkStrength.unknown return NetworkStrength.unknown
def get_battery_capacity(self):
return 100
def get_battery_status(self):
return ""
def get_battery_current(self):
return 0
def get_battery_voltage(self):
return 0
def get_battery_charging(self):
return True
def set_battery_charging(self, on):
pass
def get_usb_present(self): def get_usb_present(self):
return False return False

@ -355,25 +355,6 @@ class Tici(HardwareBase):
pass pass
return ret return ret
# We don't have a battery, so let's use some sane constants
def get_battery_capacity(self):
return 100
def get_battery_status(self):
return ""
def get_battery_current(self):
return 0
def get_battery_voltage(self):
return 0
def get_battery_charging(self):
return True
def set_battery_charging(self, on):
pass
def get_usb_present(self): def get_usb_present(self):
# Not sure if relevant on tici, but the file exists # Not sure if relevant on tici, but the file exists
return self.read_param_file("/sys/class/power_supply/usb/present", lambda x: bool(int(x)), False) return self.read_param_file("/sys/class/power_supply/usb/present", lambda x: bool(int(x)), False)

@ -1,7 +1,4 @@
import random
import threading import threading
import time
from statistics import mean
from typing import Optional from typing import Optional
from cereal import log from cereal import log
@ -82,52 +79,8 @@ class PowerMonitoring:
self.car_battery_capacity_uWh += (CAR_CHARGING_RATE_W * 1e6 * integration_time_h) self.car_battery_capacity_uWh += (CAR_CHARGING_RATE_W * 1e6 * integration_time_h)
self.last_measurement_time = now self.last_measurement_time = now
else: else:
# No ignition, we integrate the offroad power used by the device
is_uno = peripheralState.pandaType == log.PandaState.PandaType.uno
# Get current power draw somehow # Get current power draw somehow
current_power = HARDWARE.get_current_power_draw() # pylint: disable=assignment-from-none current_power = HARDWARE.get_current_power_draw()
if current_power is not None:
pass
elif (self.next_pulsed_measurement_time is not None) and (self.next_pulsed_measurement_time <= now):
# TODO: Figure out why this is off by a factor of 3/4???
FUDGE_FACTOR = 1.33
# Turn off charging for about 10 sec in a thread that does not get killed on SIGINT, and perform measurement here to avoid blocking thermal
def perform_pulse_measurement(now):
try:
HARDWARE.set_battery_charging(False)
time.sleep(5)
# Measure for a few sec to get a good average
voltages = []
currents = []
for _ in range(6):
voltages.append(HARDWARE.get_battery_voltage())
currents.append(HARDWARE.get_battery_current())
time.sleep(1)
current_power = ((mean(voltages) / 1000000) * (mean(currents) / 1000000))
self._perform_integration(now, current_power * FUDGE_FACTOR)
# Enable charging again
HARDWARE.set_battery_charging(True)
except Exception:
cloudlog.exception("Pulsed power measurement failed")
# Start pulsed measurement and return
threading.Thread(target=perform_pulse_measurement, args=(now,)).start()
self.next_pulsed_measurement_time = None
return
elif self.next_pulsed_measurement_time is None and not is_uno:
# On a charging EON with black panda, or drawing more than 400mA out of a white/grey one
# Only way to get the power draw is to turn off charging for a few sec and check what the discharging rate is
# We shouldn't do this very often, so make sure it has been some long-ish random time interval
self.next_pulsed_measurement_time = now + random.randint(120, 180)
return
else:
# Do nothing
return
# Do the integration # Do the integration
self._perform_integration(now, current_power) self._perform_integration(now, current_power)
@ -178,11 +131,9 @@ class PowerMonitoring:
now = sec_since_boot() now = sec_since_boot()
panda_charging = (peripheralState.usbPowerMode != log.PeripheralState.UsbPowerMode.client) panda_charging = (peripheralState.usbPowerMode != log.PeripheralState.UsbPowerMode.client)
BATT_PERC_OFF = 10
should_shutdown = False should_shutdown = False
# Wait until we have shut down charging before powering down # Wait until we have shut down charging before powering down
should_shutdown |= (not panda_charging and self.should_disable_charging(ignition, in_car, offroad_timestamp)) should_shutdown |= (not panda_charging and self.should_disable_charging(ignition, in_car, offroad_timestamp))
should_shutdown |= ((HARDWARE.get_battery_capacity() < BATT_PERC_OFF) and (not HARDWARE.get_battery_charging()) and ((now - offroad_timestamp) > 60))
should_shutdown &= started_seen or (now > MIN_ON_TIME_S) should_shutdown &= started_seen or (now > MIN_ON_TIME_S)
return should_shutdown return should_shutdown

@ -21,10 +21,7 @@ with patch("common.realtime.sec_since_boot", new=mock_sec_since_boot):
CAR_CHARGING_RATE_W, VBATT_PAUSE_CHARGING CAR_CHARGING_RATE_W, VBATT_PAUSE_CHARGING
TEST_DURATION_S = 50 TEST_DURATION_S = 50
ALL_PANDA_TYPES = [(hw_type,) for hw_type in [log.PandaState.PandaType.whitePanda, ALL_PANDA_TYPES = [(log.PandaState.PandaType.dos,)]
log.PandaState.PandaType.greyPanda,
log.PandaState.PandaType.blackPanda,
log.PandaState.PandaType.uno]]
def pm_patch(name, value, constant=False): def pm_patch(name, value, constant=False):
if constant: if constant:
@ -121,12 +118,8 @@ class TestPowerMonitoring(unittest.TestCase):
# Test to check policy of stopping charging after MAX_TIME_OFFROAD_S # Test to check policy of stopping charging after MAX_TIME_OFFROAD_S
@parameterized.expand(ALL_PANDA_TYPES) @parameterized.expand(ALL_PANDA_TYPES)
def test_max_time_offroad(self, hw_type): def test_max_time_offroad(self, hw_type):
BATT_VOLTAGE = 4
BATT_CURRENT = 0 # To stop shutting down for other reasons
MOCKED_MAX_OFFROAD_TIME = 3600 MOCKED_MAX_OFFROAD_TIME = 3600
with pm_patch("HARDWARE.get_battery_voltage", BATT_VOLTAGE * 1e6), pm_patch("HARDWARE.get_battery_current", BATT_CURRENT * 1e6), \ with pm_patch("MAX_TIME_OFFROAD_S", MOCKED_MAX_OFFROAD_TIME, constant=True), pm_patch("HARDWARE.get_current_power_draw", None):
pm_patch("HARDWARE.get_battery_status", "Discharging"), pm_patch("MAX_TIME_OFFROAD_S", MOCKED_MAX_OFFROAD_TIME, constant=True), \
pm_patch("HARDWARE.get_current_power_draw", None):
pm = PowerMonitoring() pm = PowerMonitoring()
pm.car_battery_capacity_uWh = CAR_BATTERY_CAPACITY_uWh pm.car_battery_capacity_uWh = CAR_BATTERY_CAPACITY_uWh
start_time = ssb start_time = ssb

@ -240,8 +240,6 @@ def thermald_thread(end_event, hw_queue):
msg.deviceState.modemTempC = last_hw_state.modem_temps msg.deviceState.modemTempC = last_hw_state.modem_temps
msg.deviceState.screenBrightnessPercent = HARDWARE.get_screen_brightness() msg.deviceState.screenBrightnessPercent = HARDWARE.get_screen_brightness()
msg.deviceState.batteryPercent = HARDWARE.get_battery_capacity()
msg.deviceState.batteryCurrent = HARDWARE.get_battery_current()
msg.deviceState.usbOnline = HARDWARE.get_usb_present() msg.deviceState.usbOnline = HARDWARE.get_usb_present()
current_filter.update(msg.deviceState.batteryCurrent / 1e6) current_filter.update(msg.deviceState.batteryCurrent / 1e6)

Loading…
Cancel
Save