Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP - Dynamically adjust the charge current to avoid over-voltage
Browse files Browse the repository at this point in the history
bjpirt committed Dec 2, 2023
1 parent 763c272 commit cc55d95
Showing 2 changed files with 10 additions and 14 deletions.
7 changes: 0 additions & 7 deletions battery/battery_pack.py
Original file line number Diff line number Diff line change
@@ -122,13 +122,6 @@ def cell_voltage_difference(self) -> float:
return max((module.cell_voltage_difference for module in self.modules))
return 0.0

def should_charge(self, current_state: bool) -> bool:
if current_state is True:
return self.high_cell_voltage < self._config.cell_high_voltage_setpoint
else:
return self.high_cell_voltage < (
self._config.cell_high_voltage_setpoint - self._config.charge_hysteresis_voltage)

def should_discharge(self, current_state: bool) -> bool:
if current_state is True:
return self.low_cell_voltage > self._config.cell_low_voltage_setpoint
17 changes: 10 additions & 7 deletions bms/bms.py
Original file line number Diff line number Diff line change
@@ -30,6 +30,7 @@ def __init__(self, battery_pack: BatteryPack, config: Config, current_sensor: Op
self.__discharging_enabled = True
self.__charging_timer = get_interval()
self.__charging_timer.set(self.__config.charge_hysteresis_time)
self.__charge_current = self.__config.max_charge_current
self.__discharging_timer = get_interval()
self.__discharging_timer.set(self.__config.charge_hysteresis_time)
self.__wdt: Optional[WDT] = None
@@ -73,17 +74,19 @@ def current(self) -> float:

@property
def charge_current_setpoint(self) -> float:
self.__charging_enabled = self.battery_pack.should_charge(self.__charging_enabled)
if self.__charging_enabled is True:
if self.__charging_timer.ready:
return self.__config.max_charge_current
voltage_difference = self.battery_pack.high_cell_voltage - \
self.__config.cell_high_voltage_setpoint
if voltage_difference > 0:
self.__charge_current = self.current * 0.9
else:
self.__charging_timer.reset()
return 0
self.__charge_current = min(
self.__charge_current * 1.1, self.__config.max_charge_current)
return self.__charge_current

@property
def discharge_current_setpoint(self) -> float:
self.__discharging_enabled = self.battery_pack.should_discharge(self.__discharging_enabled)
self.__discharging_enabled = self.battery_pack.should_discharge(
self.__discharging_enabled)
if self.__discharging_enabled is True:
if self.__discharging_timer.ready:
return self.__config.max_discharge_current

0 comments on commit cc55d95

Please sign in to comment.