Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix proposal for #733 #735

Merged
merged 24 commits into from
Jun 27, 2023
Merged
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d491b07
Refactor: Change time() to int(time()) for consistency in max_voltage…
ogurevich Jun 8, 2023
6c20cfe
The time difference ('tDiff') added to the debug output in the charge…
ogurevich Jun 8, 2023
9137fa3
Introduce PENALTY_BUFFER for Overcharge Prevention
ogurevich Jun 9, 2023
db6ed1b
Refactor battery voltage calculations for efficiency and clarity
ogurevich Jun 9, 2023
23db9e5
Refactor battery.py to use existing class variables for min/max voltage
ogurevich Jun 9, 2023
8ce3661
remove unnecessary brackets
ogurevich Jun 9, 2023
c385803
fix formatting with black formatter
ogurevich Jun 10, 2023
6cabc93
hm, fix imported but unused (flake8 action failed)
ogurevich Jun 10, 2023
f8c00c7
calc self.max_battery_voltage, self.min_battery_voltage in manage_cha…
ogurevich Jun 10, 2023
8bc2b9c
reduce PENALTY_BUFFER (do we really need it at all ?)
ogurevich Jun 10, 2023
187723f
calculate min/max battery voltage on battery class init
mr-manuel Jun 10, 2023
75a8f26
Update battery.py
mr-manuel Jun 10, 2023
c52c7d0
init max min voltage in prepare_voltage_management()
ogurevich Jun 10, 2023
43672c8
Merge branch 'ogdev' of github.com:ogurevich/dbus-serialbattery into …
ogurevich Jun 10, 2023
4449850
Merge remote-tracking branch 'origin/dev' into ogdev
ogurevich Jun 10, 2023
027e694
remove penalty_buffer
ogurevich Jun 10, 2023
6391341
removed debug output, comment on resetting of max_voltage_start_time
ogurevich Jun 11, 2023
4fc9e43
Merge branch 'dev' into ogdev
ogurevich Jun 11, 2023
54d013c
Merge branch 'dev' of github.com:ogurevich/dbus-serialbattery into dev
ogurevich Jun 16, 2023
465413e
Merge branch 'dev' into ogdev
ogurevich Jun 26, 2023
18d5333
Merge remote-tracking branch 'origin/dev' into ogdev
ogurevich Jun 26, 2023
81a2fc7
fix proposal for #733
ogurevich Jun 26, 2023
8d2440b
format with BlackFormatter
ogurevich Jun 26, 2023
712e332
use 3 digit in constant, removed unnecessary code
ogurevich Jun 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactor battery voltage calculations for efficiency and clarity
This commit introduces several changes to the battery.py script to improve the handling of battery voltage calculations. Specifically:

1. Constants  and  are introduced to replace repeated calculations of these values.
2. These constants are then used to replace the previous direct calculations in various conditions and assignments.
3. Conditions for resetting  are updated to include a check against .

These changes aim to make the code more efficient by reducing repeated calculations, and also make the code easier to understand by using clearly named constants.
ogurevich committed Jun 9, 2023
commit db6ed1b08ff0fe000f22f3ab7ad655913b3e6dc3
16 changes: 10 additions & 6 deletions etc/dbus-serialbattery/battery.py
Original file line number Diff line number Diff line change
@@ -217,6 +217,8 @@ def manage_charge_voltage_linear(self) -> None:
tDiff = 0

PENALTY_BUFFER = 0.010
MAX_BATTERY_VOLTAGE = utils.MAX_CELL_VOLTAGE * self.cell_count
MIN_BATTERY_VOLTAGE = utils.MIN_CELL_VOLTAGE * self.cell_count

try:
if utils.CVCM_ENABLE:
@@ -237,7 +239,7 @@ def manage_charge_voltage_linear(self) -> None:
if self.max_voltage_start_time is None:
# start timer, if max voltage is reached and cells are balanced
if (
(utils.MAX_CELL_VOLTAGE * self.cell_count) - utils.VOLTAGE_DROP
MAX_BATTERY_VOLTAGE - utils.VOLTAGE_DROP
<= voltageSum
and voltageDiff
<= utils.CELL_VOLTAGE_DIFF_KEEP_MAX_VOLTAGE_UNTIL
@@ -258,6 +260,8 @@ def manage_charge_voltage_linear(self) -> None:
if 300 < tDiff:
self.allow_max_voltage = False
self.max_voltage_start_time = None
if voltageSum < MAX_BATTERY_VOLTAGE - utils.VOLTAGE_DROP:
self.max_voltage_start_time = None

# INFO: battery will only switch to Absorption, if all cells are balanced.
# Reach MAX_CELL_VOLTAGE * cell count if they are all balanced.
@@ -274,9 +278,9 @@ def manage_charge_voltage_linear(self) -> None:
min(
max(
voltageSum - penaltySum,
utils.MIN_CELL_VOLTAGE * self.cell_count,
MIN_BATTERY_VOLTAGE,
),
utils.MAX_CELL_VOLTAGE * self.cell_count,
MAX_BATTERY_VOLTAGE,
),
3,
)
@@ -292,16 +296,16 @@ def manage_charge_voltage_linear(self) -> None:
else "Absorption dynamic"
# + "(vS: "
# + str(round(voltageSum, 2))
# + " - tDiff: "
# + " tDiff: "
# + str(tDiff)
# + " - pS: "
# + " pS: "
# + str(round(penaltySum, 2))
# + ")"
)

elif self.allow_max_voltage:
self.control_voltage = round(
(utils.MAX_CELL_VOLTAGE * self.cell_count), 3
(MAX_BATTERY_VOLTAGE), 3
)
self.charge_mode = (
"Bulk" if self.max_voltage_start_time is None else "Absorption"