mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-07-03 04:22:09 +08:00
add lower limit to prevent triggering on power loss (#20720)
Co-authored-by: Comma Device <device@comma.ai> old-commit-hash: 13a6e3c68f94d39890602acd6955ac9025e34498
This commit is contained in:
@@ -16,7 +16,8 @@ CAR_VOLTAGE_LOW_PASS_K = 0.091 # LPF gain for 5s tau (dt/tau / (dt/tau + 1))
|
||||
CAR_BATTERY_CAPACITY_uWh = 30e6
|
||||
CAR_CHARGING_RATE_W = 45
|
||||
|
||||
VBATT_PAUSE_CHARGING = 11.0
|
||||
VBATT_PAUSE_CHARGING = 11.0 # Lower limit on the LPF car battery voltage
|
||||
VBATT_INSTANT_PAUSE_CHARGING = 7.0 # Lower limit on the instant car battery voltage measurements to avoid triggering on instant power loss
|
||||
MAX_TIME_OFFROAD_S = 30*3600
|
||||
|
||||
class PowerMonitoring:
|
||||
@@ -27,6 +28,7 @@ class PowerMonitoring:
|
||||
self.power_used_uWh = 0 # Integrated power usage in uWh since going into offroad
|
||||
self.next_pulsed_measurement_time = None
|
||||
self.car_voltage_mV = 12e3 # Low-passed version of pandaState voltage
|
||||
self.car_voltage_instant_mV = 12e3 # Last value of pandaState voltage
|
||||
self.integration_lock = threading.Lock()
|
||||
|
||||
car_battery_capacity_uWh = self.params.get("CarBatteryCapacity")
|
||||
@@ -51,6 +53,7 @@ class PowerMonitoring:
|
||||
return
|
||||
|
||||
# Low-pass battery voltage
|
||||
self.car_voltage_instant_mV = pandaState.pandaState.voltage
|
||||
self.car_voltage_mV = ((pandaState.pandaState.voltage * CAR_VOLTAGE_LOW_PASS_K) + (self.car_voltage_mV * (1 - CAR_VOLTAGE_LOW_PASS_K)))
|
||||
|
||||
# Cap the car battery power and save it in a param every 10-ish seconds
|
||||
@@ -161,7 +164,7 @@ class PowerMonitoring:
|
||||
now = sec_since_boot()
|
||||
disable_charging = False
|
||||
disable_charging |= (now - offroad_timestamp) > MAX_TIME_OFFROAD_S
|
||||
disable_charging |= (self.car_voltage_mV < (VBATT_PAUSE_CHARGING * 1e3))
|
||||
disable_charging |= (self.car_voltage_mV < (VBATT_PAUSE_CHARGING * 1e3)) and (self.car_voltage_instant_mV > (VBATT_INSTANT_PAUSE_CHARGING * 1e3))
|
||||
disable_charging |= (self.car_battery_capacity_uWh <= 0)
|
||||
disable_charging &= (not pandaState.pandaState.ignitionLine and not pandaState.pandaState.ignitionCan)
|
||||
disable_charging &= (not self.params.get_bool("DisablePowerDown"))
|
||||
|
||||
Reference in New Issue
Block a user