mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-06-24 15:32:07 +08:00
more comma two cleanup (#24300)
* more comma two cleanup * fix up power monitoring
This commit is contained in:
@@ -302,7 +302,6 @@ selfdrive/camerad/cameras/camera_common.h
|
||||
selfdrive/camerad/cameras/camera_common.cc
|
||||
selfdrive/camerad/cameras/camera_replay.cc
|
||||
selfdrive/camerad/cameras/camera_replay.h
|
||||
selfdrive/camerad/cameras/sensor_i2c.h
|
||||
selfdrive/camerad/cameras/sensor2_i2c.h
|
||||
|
||||
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:
|
||||
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
|
||||
def get_usb_present(self):
|
||||
pass
|
||||
|
||||
@@ -50,24 +50,6 @@ class Pc(HardwareBase):
|
||||
def get_network_strength(self, network_type):
|
||||
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):
|
||||
return False
|
||||
|
||||
|
||||
@@ -355,25 +355,6 @@ class Tici(HardwareBase):
|
||||
pass
|
||||
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):
|
||||
# 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)
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
import random
|
||||
import threading
|
||||
import time
|
||||
from statistics import mean
|
||||
from typing import Optional
|
||||
|
||||
from cereal import log
|
||||
@@ -82,52 +79,8 @@ class PowerMonitoring:
|
||||
self.car_battery_capacity_uWh += (CAR_CHARGING_RATE_W * 1e6 * integration_time_h)
|
||||
self.last_measurement_time = now
|
||||
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
|
||||
current_power = HARDWARE.get_current_power_draw() # pylint: disable=assignment-from-none
|
||||
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
|
||||
current_power = HARDWARE.get_current_power_draw()
|
||||
|
||||
# Do the integration
|
||||
self._perform_integration(now, current_power)
|
||||
@@ -178,11 +131,9 @@ class PowerMonitoring:
|
||||
|
||||
now = sec_since_boot()
|
||||
panda_charging = (peripheralState.usbPowerMode != log.PeripheralState.UsbPowerMode.client)
|
||||
BATT_PERC_OFF = 10
|
||||
|
||||
should_shutdown = False
|
||||
# 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 |= ((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)
|
||||
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
|
||||
|
||||
TEST_DURATION_S = 50
|
||||
ALL_PANDA_TYPES = [(hw_type,) for hw_type in [log.PandaState.PandaType.whitePanda,
|
||||
log.PandaState.PandaType.greyPanda,
|
||||
log.PandaState.PandaType.blackPanda,
|
||||
log.PandaState.PandaType.uno]]
|
||||
ALL_PANDA_TYPES = [(log.PandaState.PandaType.dos,)]
|
||||
|
||||
def pm_patch(name, value, constant=False):
|
||||
if constant:
|
||||
@@ -121,12 +118,8 @@ class TestPowerMonitoring(unittest.TestCase):
|
||||
# Test to check policy of stopping charging after MAX_TIME_OFFROAD_S
|
||||
@parameterized.expand(ALL_PANDA_TYPES)
|
||||
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
|
||||
with pm_patch("HARDWARE.get_battery_voltage", BATT_VOLTAGE * 1e6), pm_patch("HARDWARE.get_battery_current", BATT_CURRENT * 1e6), \
|
||||
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):
|
||||
with pm_patch("MAX_TIME_OFFROAD_S", MOCKED_MAX_OFFROAD_TIME, constant=True), pm_patch("HARDWARE.get_current_power_draw", None):
|
||||
pm = PowerMonitoring()
|
||||
pm.car_battery_capacity_uWh = CAR_BATTERY_CAPACITY_uWh
|
||||
start_time = ssb
|
||||
|
||||
@@ -240,8 +240,6 @@ def thermald_thread(end_event, hw_queue):
|
||||
msg.deviceState.modemTempC = last_hw_state.modem_temps
|
||||
|
||||
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()
|
||||
current_filter.update(msg.deviceState.batteryCurrent / 1e6)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user