Skip to content

Commit

Permalink
Merge pull request #1029 from mr-manuel/master
Browse files Browse the repository at this point in the history
Changes pre release
  • Loading branch information
Louisvdw authored Apr 8, 2024
2 parents 821e872 + da58c5c commit 59a6d00
Show file tree
Hide file tree
Showing 17 changed files with 342 additions and 133 deletions.
4 changes: 3 additions & 1 deletion .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ body:
* Please carefully read all the instructions below including the descriptions! Very often we have to request the data again, because it was not provided in the first place.
* Please try the `nightly` build from the `dev` first, if you are not already using it. It's very likely that the bug is already fixed. See [here](https://louisvdw.github.io/dbus-serialbattery/general/install#nightly-build) how to install it.
* Please try the `nightly` build first, if you are not already using it. It's very likely that the bug is already fixed. See [here](https://louisvdw.github.io/dbus-serialbattery/general/install#nightly-build) how to install it.
* Please read the complete [changelog](https://github.com/Louisvdw/dbus-serialbattery/blob/master/CHANGELOG.md).
- type: textarea
id: description
Expand Down
4 changes: 3 additions & 1 deletion .github/ISSUE_TEMPLATE/feature_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ body:
## 🚨 IMPORTANT 🚨
* Please try the `nightly` build from the `dev` first, if you are not already using it. Maybe the feature was already developed. See [here](https://louisvdw.github.io/dbus-serialbattery/general/install#nightly-build) how to install it.
* Please try the `nightly` build first, if you are not already using it. Maybe the feature was already developed. See [here](https://louisvdw.github.io/dbus-serialbattery/general/install#nightly-build) how to install it.
* Please read the complete [changelog](https://github.com/Louisvdw/dbus-serialbattery/blob/master/CHANGELOG.md).
- type: textarea
id: idea
Expand Down
4 changes: 3 additions & 1 deletion .github/ISSUE_TEMPLATE/support_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ body:
* Please carefully read all the instructions below including the descriptions! Very often we have to request the data again, because it was not provided in the first place.
* Please try the `nightly` build from the `dev` first, if you are not already using it. It's very likely that the bug is already fixed. See [here](https://louisvdw.github.io/dbus-serialbattery/general/install#nightly-build) how to install it.
* Please try the `nightly` build first, if you are not already using it. It's very likely that the bug is already fixed. See [here](https://louisvdw.github.io/dbus-serialbattery/general/install#nightly-build) how to install it.
* Please read the complete [changelog](https://github.com/Louisvdw/dbus-serialbattery/blob/master/CHANGELOG.md).
- type: textarea
id: description
Expand Down
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,30 @@
* `BULK_AFTER_DAYS` -> `SOC_RESET_AFTER_DAYS`


## v1.2.x

## v1.2.20240408

* Added: Check if the device instance is already used by @mr-manuel
* Added: Check if there is enough space on system and data partitions before installation by @mr-manuel
* 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 is now disabled by default, since in most use cases it's very inaccurate 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
* Changed: Daly BMS - Fixed some smaller errory with https://github.com/mr-manuel/venus-os_dbus-serialbattery/pull/22 and https://github.com/mr-manuel/venus-os_dbus-serialbattery/pull/23 by @transistorgit
* Changed: Fixed CAN installation with https://github.com/Louisvdw/dbus-serialbattery/pull/1007 by @p0l0us
* Changed: Fixed non-working can-bus dependency with https://github.com/Louisvdw/dbus-serialbattery/pull/1007 by @p0l0us
* Changed: Fixed showing None SoC in log in driver start by @mr-manuel
* Changed: Fixed some other errors when restoring values from dbus settings by @mr-manuel
* Changed: Fixed some SOC calculation issues by @mr-manuel
* Changed: Fixed Time-to-SoC and Time-to-Go calculation by @mr-manuel
* Changed: Set CCL/DCL to 0, if allow to charge/discharge is no, fixes https://github.com/Louisvdw/dbus-serialbattery/issues/1024 by @mr-manuel
* Changed: Install script now shows repositories and version numbers by @mr-manuel
* Changed: JKBMS BLE - Fixed driver gets unresponsive, if connection is lost https://github.com/Louisvdw/dbus-serialbattery/issues/720 with https://github.com/Louisvdw/dbus-serialbattery/pull/941 by @cupertinomiranda
* Changed: JKBMS BLE - Fixed driver not starting for some BMS models that are not sending BLE data correctly https://github.com/Louisvdw/dbus-serialbattery/issues/819 by @mr-manuel
* Changed: JKBMS BLE - Fixed temperature issue https://github.com/Louisvdw/dbus-serialbattery/issues/916 by @mr-manuel
* Changed: JKBMS CAN - Fixed different BMS versions with https://github.com/mr-manuel/venus-os_dbus-serialbattery/pull/24 by @p0l0us
* Changed: LLT/JBD BMS & BLE - If only one temperature is available use it as battery temp. Fixed https://github.com/Louisvdw/dbus-serialbattery/issues/971 by @mr-manuel
* Changed: Optimized reinstall-local.sh. Show installed version and restart GUI only on changes by @mr-manuel
* Changed: Reinstallation of the driver now checks, if packages are already installed for Bluetooth and CAN by @mr-manuel
Expand Down
138 changes: 117 additions & 21 deletions etc/dbus-serialbattery/battery.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import math
from time import time
from abc import ABC, abstractmethod
import sys


class Protection(object):
Expand Down Expand Up @@ -69,6 +70,22 @@ def __init__(self, port: str, baud: int, address: str):
self.max_battery_discharge_current: float = None
self.has_settings: bool = False

# this values should only be initialized once,
# else the BMS turns off the inverter on disconnect
self.soc_calc_capacity_remain: float = None
self.soc_calc_capacity_remain_lasttime: float = None
self.soc_calc_reset_starttime: int = None
self.soc_calc: float = None # save soc_calc to preserve on restart
self.soc: float = None
self.charge_fet: bool = None
self.discharge_fet: bool = None
self.balance_fet: bool = None
self.block_because_disconnect: bool = False
self.control_charge_current: int = None
self.control_discharge_current: int = None
self.control_allow_charge: bool = None
self.control_allow_discharge: bool = None

# fetched from the BMS from a field where the user can input a custom string
# only if available
self.custom_field: str = None
Expand All @@ -83,22 +100,15 @@ def init_values(self):
self.current: float = None
self.current_avg: float = None
self.current_avg_lst: list = []
self.current_corrected: float = None
self.capacity_remain: float = None
self.capacity: float = None
self.cycles: float = None
self.total_ah_drawn: float = None
self.production = None
self.protection = Protection()
self.version = None
self.soc_calc_capacity_remain: float = None
self.soc_calc_capacity_remain_lasttime: float = None
self.soc_calc_reset_starttime: int = None
self.soc_calc: float = None # save soc_calc to preserve on restart
self.soc: float = None
self.time_to_soc_update: int = 0
self.charge_fet: bool = None
self.discharge_fet: bool = None
self.balance_fet: bool = None
self.temp_sensors: int = None
self.temp1: float = None
self.temp2: float = None
Expand All @@ -122,10 +132,6 @@ def init_values(self):
self.linear_cvl_last_set: int = 0
self.linear_ccl_last_set: int = 0
self.linear_dcl_last_set: int = 0
self.control_discharge_current: int = None
self.control_charge_current: int = None
self.control_allow_charge: bool = None
self.control_allow_discharge: bool = None
# list of available callbacks, in order to display the buttons in the GUI
self.available_callbacks: List[str] = []

Expand Down Expand Up @@ -241,7 +247,7 @@ def manage_charge_voltage(self) -> None:
def soc_calculation(self) -> None:
current_time = time()
voltage_sum = 0
current_corrected = 0
self.current_corrected = 0
current_min_cell_voltage = self.get_min_cell_voltage()

# calculate battery voltage from cell voltages
Expand All @@ -252,15 +258,18 @@ def soc_calculation(self) -> None:

if self.soc_calc_capacity_remain is not None:
# calculate real current
current_corrected = utils.calcLinearRelationship(
self.current,
utils.SOC_CALC_CURRENT_REPORTED_BY_BMS,
utils.SOC_CALC_CURRENT_MEASURED_BY_USER,
self.current_corrected = round(
utils.calcLinearRelationship(
self.current,
utils.SOC_CALC_CURRENT_REPORTED_BY_BMS,
utils.SOC_CALC_CURRENT_MEASURED_BY_USER,
),
2,
)

self.soc_calc_capacity_remain = (
self.soc_calc_capacity_remain
+ current_corrected
+ self.current_corrected
* (current_time - self.soc_calc_capacity_remain_lasttime)
/ 3600
)
Expand Down Expand Up @@ -601,8 +610,9 @@ def manage_charge_voltage_linear(self) -> None:
)
self.charge_mode_debug += f" • Reset voltage limit SoC: {utils.SOC_LEVEL_TO_RESET_VOLTAGE_LIMIT}%"
self.charge_mode_debug += (
f"\nSoC: {self.soc}% • SoC_Calc {self.soc_calc}%"
f"\nSoC: {self.soc}% • SoC_Calc: {self.soc_calc}%"
)
self.charge_mode_debug += f"\ncurrent: {self.current}A • current_corrected: {self.current_corrected}A"
self.charge_mode_debug += (
f"\nallow_max_voltage: {self.allow_max_voltage}"
)
Expand All @@ -613,6 +623,11 @@ def manage_charge_voltage_linear(self) -> None:
self.charge_mode_debug += (
f"\nlinear_cvl_last_set: {self.linear_cvl_last_set}"
)
self.charge_mode_debug += (
f"\ncharge_fet: {self.charge_fet} • control_allow_charge: {self.control_allow_charge}"
+ f"\ndischarge_fet: {self.discharge_fet} • control_allow_discharge: {self.control_allow_discharge}"
+ f"\nblock_because_disconnect: {self.block_because_disconnect}"
)
soc_reset_days_ago = round(
(current_time - self.soc_reset_last_reached) / 60 / 60 / 24, 2
)
Expand Down Expand Up @@ -783,11 +798,18 @@ def manage_charge_current(self) -> None:
else:
charge_limits.update({tmp: "SoC"})

# set CCL to 0, if BMS does not allow to charge
if self.charge_fet is False or self.block_because_disconnect:
if 0 in charge_limits:
charge_limits.update({0: charge_limits[0] + ", BMS"})
else:
charge_limits.update({0: "BMS"})

# do not set CCL immediately, but only
# - after LINEAR_RECALCULATION_EVERY passed
# - if CCL changes to 0
# - if CCL changes more than LINEAR_RECALCULATION_ON_PERC_CHANGE
ccl = round(min(charge_limits), 3) # gets changed after finished testing
ccl = round(min(charge_limits), 3)
diff = (
abs(self.control_charge_current - ccl)
if self.control_charge_current is not None
Expand All @@ -809,6 +831,7 @@ def manage_charge_current(self) -> None:

self.charge_limitation = charge_limits[min(charge_limits)]

# set allow to charge to no, if CCL is 0
if self.control_charge_current == 0:
self.control_allow_charge = False
else:
Expand Down Expand Up @@ -869,11 +892,18 @@ def manage_charge_current(self) -> None:
else:
discharge_limits.update({tmp: "SoC"})

# set DCL to 0, if BMS does not allow to discharge
if self.discharge_fet is False or self.block_because_disconnect:
if 0 in discharge_limits:
discharge_limits.update({0: discharge_limits[0] + ", BMS"})
else:
discharge_limits.update({0: "BMS"})

# do not set DCL immediately, but only
# - after LINEAR_RECALCULATION_EVERY passed
# - if DCL changes to 0
# - if DCL changes more than LINEAR_RECALCULATION_ON_PERC_CHANGE
dcl = round(min(discharge_limits), 3) # gets changed after finished testing
dcl = round(min(discharge_limits), 3)
diff = (
abs(self.control_discharge_current - dcl)
if self.control_discharge_current is not None
Expand All @@ -895,6 +925,7 @@ def manage_charge_current(self) -> None:

self.discharge_limitation = discharge_limits[min(discharge_limits)]

# set allow to discharge to no, if DCL is 0
if self.control_discharge_current == 0:
self.control_allow_discharge = False
else:
Expand All @@ -918,6 +949,17 @@ def calcMaxChargeCurrentReferringToCellVoltage(self) -> float:
logger.warning(
"Error while executing calcMaxChargeCurrentReferringToCellVoltage(). Using default value instead."
)
logger.warning(
f"CELL_VOLTAGES_WHILE_CHARGING: {utils.CELL_VOLTAGES_WHILE_CHARGING}"
+ f" • MAX_CHARGE_CURRENT_CV: {utils.MAX_CHARGE_CURRENT_CV}"
)

exception_type, exception_object, exception_traceback = sys.exc_info()
file = exception_traceback.tb_frame.f_code.co_filename
line = exception_traceback.tb_lineno
logger.error(
f"Exception occurred: {repr(exception_object)} of type {exception_type} in {file} line #{line}"
)
return self.max_battery_charge_current

def calcMaxDischargeCurrentReferringToCellVoltage(self) -> float:
Expand All @@ -938,6 +980,17 @@ def calcMaxDischargeCurrentReferringToCellVoltage(self) -> float:
logger.warning(
"Error while executing calcMaxDischargeCurrentReferringToCellVoltage(). Using default value instead."
)
logger.warning(
f"CELL_VOLTAGES_WHILE_DISCHARGING: {utils.CELL_VOLTAGES_WHILE_DISCHARGING}"
+ f" • MAX_DISCHARGE_CURRENT_CV: {utils.MAX_DISCHARGE_CURRENT_CV}"
)

exception_type, exception_object, exception_traceback = sys.exc_info()
file = exception_traceback.tb_frame.f_code.co_filename
line = exception_traceback.tb_lineno
logger.error(
f"Exception occurred: {repr(exception_object)} of type {exception_type} in {file} line #{line}"
)
return self.max_battery_charge_current

def calcMaxChargeCurrentReferringToTemperature(self) -> float:
Expand Down Expand Up @@ -1004,6 +1057,17 @@ def calcMaxChargeCurrentReferringToSoc(self) -> float:
logger.warning(
"Error while executing calcMaxChargeCurrentReferringToSoc(). Using default value instead."
)
logger.warning(
f"SOC_WHILE_CHARGING: {utils.SOC_WHILE_CHARGING}"
+ f" • MAX_CHARGE_CURRENT_SOC: {utils.MAX_CHARGE_CURRENT_SOC}"
)

exception_type, exception_object, exception_traceback = sys.exc_info()
file = exception_traceback.tb_frame.f_code.co_filename
line = exception_traceback.tb_lineno
logger.error(
f"Exception occurred: {repr(exception_object)} of type {exception_type} in {file} line #{line}"
)
return self.max_battery_charge_current

def calcMaxDischargeCurrentReferringToSoc(self) -> float:
Expand All @@ -1024,6 +1088,17 @@ def calcMaxDischargeCurrentReferringToSoc(self) -> float:
logger.warning(
"Error while executing calcMaxDischargeCurrentReferringToSoc(). Using default value instead."
)
logger.warning(
f"SOC_WHILE_DISCHARGING: {utils.SOC_WHILE_DISCHARGING}"
+ f" • MAX_DISCHARGE_CURRENT_SOC: {utils.MAX_DISCHARGE_CURRENT_SOC}"
)

exception_type, exception_object, exception_traceback = sys.exc_info()
file = exception_traceback.tb_frame.f_code.co_filename
line = exception_traceback.tb_lineno
logger.error(
f"Exception occurred: {repr(exception_object)} of type {exception_type} in {file} line #{line}"
)
return self.max_battery_discharge_current

def get_min_cell(self) -> int:
Expand Down Expand Up @@ -1333,6 +1408,27 @@ def get_mos_temp(self) -> Union[float, None]:
else:
return None

def get_allow_to_charge(self) -> bool:
return (
True
if self.charge_fet
and self.control_allow_charge
and self.block_because_disconnect is False
else False
)

def get_allow_to_discharge(self) -> bool:
return (
True
if self.discharge_fet
and self.control_allow_discharge
and self.block_because_disconnect is False
else False
)

def get_allow_to_balance(self) -> bool:
return True if self.balance_fet else False

def validate_data(self) -> bool:
"""
Used to validate the data received from the BMS.
Expand Down
Loading

0 comments on commit 59a6d00

Please sign in to comment.