Skip to content

Commit

Permalink
Merge pull request #719 from ogurevich/voltagedroppersecond
Browse files Browse the repository at this point in the history
Gradual lowering of the voltage in float transition mode. considering utils.LINEAR_RECALCULATION_EVERY parameter
  • Loading branch information
mr-manuel authored Jun 17, 2023
2 parents 4af10dd + f45fb41 commit 2a3a1c2
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 26 deletions.
60 changes: 34 additions & 26 deletions etc/dbus-serialbattery/battery.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,24 +296,18 @@ def manage_charge_voltage_linear(self) -> None:
# INFO: battery will only switch to Absorption, if all cells are balanced.
# Reach MAX_CELL_VOLTAGE * cell count if they are all balanced.
if foundHighCellVoltage and self.allow_max_voltage:
# set CVL only once every LINEAR_RECALCULATION_EVERY seconds
if (
int(time()) - self.linear_cvl_last_set
>= utils.LINEAR_RECALCULATION_EVERY
):
self.linear_cvl_last_set = int(time())

# Keep penalty above min battery voltage and below max battery voltage
self.control_voltage = round(
min(
max(
voltageSum - penaltySum,
self.min_battery_voltage,
),
self.max_battery_voltage,
# Keep penalty above min battery voltage and below max battery voltage
control_voltage = round(
min(
max(
voltageSum - penaltySum,
self.min_battery_voltage,
),
3,
)
self.max_battery_voltage,
),
3,
)
self.set_cvl_linear(control_voltage)

self.charge_mode = (
"Bulk dynamic"
Expand Down Expand Up @@ -351,15 +345,17 @@ def manage_charge_voltage_linear(self) -> None:
self.initial_control_voltage = self.control_voltage
chargeMode = "Float Transition"
elif self.charge_mode.startswith("Float Transition"):
elapsed_time = int(time()) - self.transition_start_time
# Duration in seconds for smooth voltage drop from absorption to float
# depending on the number of cells
FLOAT_MODE_TRANSITION_DURATION = self.cell_count * 12
t = min(1, elapsed_time / FLOAT_MODE_TRANSITION_DURATION)
self.control_voltage = (
1 - t
) * self.initial_control_voltage + t * floatVoltage
if t == 1:
current_time = int(time())
elapsed_time = current_time - self.transition_start_time
# Voltage drop per second
VOLTAGE_DROP_PER_SECOND = 0.01 / 10
voltage_drop = min(
VOLTAGE_DROP_PER_SECOND * elapsed_time,
self.initial_control_voltage - floatVoltage,
)
self.set_cvl_linear(self.initial_control_voltage - voltage_drop)
if self.control_voltage <= floatVoltage:
self.control_voltage = floatVoltage
chargeMode = "Float"
else:
chargeMode = "Float Transition"
Expand All @@ -380,6 +376,18 @@ def manage_charge_voltage_linear(self) -> None:
self.control_voltage = None
self.charge_mode = "--"

def set_cvl_linear(self, control_voltage) -> bool:
"""
set CVL only once every LINEAR_RECALCULATION_EVERY seconds
:return: bool
"""
current_time = int(time())
if utils.LINEAR_RECALCULATION_EVERY <= current_time - self.linear_cvl_last_set:
self.control_voltage = control_voltage
self.linear_cvl_last_set = current_time
return True
return False

def manage_charge_voltage_step(self) -> None:
"""
manages the charge voltage using a step function by setting self.control_voltage
Expand Down
10 changes: 10 additions & 0 deletions etc/dbus-serialbattery/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ def _get_list_from_config(
MAX_CELL_VOLTAGE = float(config["DEFAULT"]["MAX_CELL_VOLTAGE"])
# Max voltage can seen as absorption voltage
FLOAT_CELL_VOLTAGE = float(config["DEFAULT"]["FLOAT_CELL_VOLTAGE"])
if FLOAT_CELL_VOLTAGE > MAX_CELL_VOLTAGE:
FLOAT_CELL_VOLTAGE = MAX_CELL_VOLTAGE
logger.error(
">>> ERROR: FLOAT_CELL_VOLTAGE is set to a value greater than MAX_CELL_VOLTAGE. Please check the configuration."
)
if FLOAT_CELL_VOLTAGE < MIN_CELL_VOLTAGE:
FLOAT_CELL_VOLTAGE = MIN_CELL_VOLTAGE
logger.error(
">>> ERROR: FLOAT_CELL_VOLTAGE is set to a value less than MAX_CELL_VOLTAGE. Please check the configuration."
)

# --------- BMS disconnect behaviour ---------
# Description: Block charge and discharge when the communication to the BMS is lost. If you are removing the
Expand Down

0 comments on commit 2a3a1c2

Please sign in to comment.