Skip to content

Commit

Permalink
Reset SoC to 0% if empty
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-manuel committed Feb 19, 2024
1 parent 93f12f4 commit cdc9b98
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
## v1.2.x

* Added: LLT/JBD BLE BMS - Added MAC address as unique identifier. Fixed https://github.com/Louisvdw/dbus-serialbattery/issues/970 by @mr-manuel
* Added: Reset calculated SoC to 0%, if battery is empty by @mr-manuel
* Added: Venus OS version to logfile by @mr-manuel
* Changed: Config: SoC limitation variables where changed to match other setting variables by @mr-manuel
* Changed: Config: Temperature limitation variables where changed to match other setting variables by @mr-manuel
Expand Down
49 changes: 37 additions & 12 deletions etc/dbus-serialbattery/battery.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ def soc_calculation(self) -> None:
current_time = time()
voltage_sum = 0
current_corrected = 0
current_min_cell_voltage = self.get_min_cell_voltage()

# calculate battery voltage from cell voltages
for i in range(self.cell_count):
Expand All @@ -263,19 +264,43 @@ def soc_calculation(self) -> None:
)
self.soc_calc_capacity_remain_lasttime = current_time

# check if battery is fully charged
if (
self.current < utils.SOC_RESET_CURRENT
and (self.max_battery_voltage - utils.VOLTAGE_DROP <= voltage_sum)
and self.soc_calc_reset_starttime
):
# set soc to 100%
# execute checks only if battery is nearly fully charged
# use lowest cell voltage, since it reaches as last the max voltage
if current_min_cell_voltage > utils.MAX_CELL_VOLTAGE * 0.99:
# check if battery is fully charged
if (
int(current_time) - self.soc_calc_reset_starttime
) > utils.SOC_RESET_TIME:
self.soc_calc_capacity_remain = self.capacity
else:
self.soc_calc_reset_starttime = int(current_time)
self.current < utils.SOC_RESET_CURRENT
and (self.max_battery_voltage - utils.VOLTAGE_DROP <= voltage_sum)
and self.soc_calc_reset_starttime
):
# set soc to 100%
if (
int(current_time) - self.soc_calc_reset_starttime
) > utils.SOC_RESET_TIME:
self.soc_calc_capacity_remain = self.capacity
else:
self.soc_calc_reset_starttime = int(current_time)

# execute checks only if battery is nearly fully discharged
# use lowest cell voltage, since the battery should not go undervoltage
if current_min_cell_voltage < utils.MIN_CELL_VOLTAGE * 1.01:
# check if battery is fully discharged
if (
self.current < utils.SOC_RESET_CURRENT
and (
current_min_cell_voltage
- (utils.VOLTAGE_DROP / self.cell_count)
<= utils.MIN_CELL_VOLTAGE
)
and self.soc_calc_reset_starttime
):
# set soc to 0%
if (
int(current_time) - self.soc_calc_reset_starttime
) > utils.SOC_RESET_TIME:
self.soc_calc_capacity_remain = 0
else:
self.soc_calc_reset_starttime = int(current_time)

else:
# if soc_calc is not available from dbus then initialize it
Expand Down

0 comments on commit cdc9b98

Please sign in to comment.