From 7c4d701e3369fd42f288514199393736f16bf215 Mon Sep 17 00:00:00 2001 From: Tobias Diedrich Date: Sat, 28 Sep 2024 16:40:34 +0200 Subject: [PATCH] Add SoC threshold for battery current limit. --- include/Configuration.h | 1 + include/defaults.h | 1 + src/Battery.cpp | 7 +++++++ src/Configuration.cpp | 2 ++ webapp/src/locales/de.json | 1 + webapp/src/locales/en.json | 1 + webapp/src/types/BatteryConfig.ts | 1 + webapp/src/views/BatteryAdminView.vue | 10 ++++++++++ 8 files changed, 24 insertions(+) diff --git a/include/Configuration.h b/include/Configuration.h index d77e0459a..571c31b53 100644 --- a/include/Configuration.h +++ b/include/Configuration.h @@ -147,6 +147,7 @@ struct BATTERY_CONFIG_T { BatteryVoltageUnit MqttVoltageUnit; bool EnableDischargeCurrentLimit; float DischargeCurrentLimit; + float DischargeCurrentLimitBelowSoc; bool UseBatteryReportedDischargeCurrentLimit; char MqttDischargeCurrentTopic[MQTT_MAX_TOPIC_STRLEN + 1]; char MqttDischargeCurrentJsonPath[BATTERY_JSON_MAX_PATH_STRLEN + 1]; diff --git a/include/defaults.h b/include/defaults.h index 257ddae0b..922a4fa29 100644 --- a/include/defaults.h +++ b/include/defaults.h @@ -156,6 +156,7 @@ #define BATTERY_JKBMS_POLLING_INTERVAL 5 #define BATTERY_ENABLE_DISCHARGE_CURRENT_LIMIT false #define BATTERY_DISCHARGE_CURRENT_LIMIT 0.0 +#define BATTERY_DISCHARGE_CURRENT_LIMIT_BELOW_SOC 100.0 #define BATTERY_USE_BATTERY_REPORTED_DISCHARGE_CURRENT_LIMIT false #define BATTERY_CAN_INTERFACE 0 #define BATTERY_CAN_TOPIC "debug/battery/can/message" diff --git a/src/Battery.cpp b/src/Battery.cpp index e10abb1fa..842603fdf 100644 --- a/src/Battery.cpp +++ b/src/Battery.cpp @@ -91,8 +91,15 @@ float BatteryClass::getDischargeCurrentLimit() if (!config.Battery.EnableDischargeCurrentLimit) { return FLT_MAX; } auto dischargeCurrentLimit = config.Battery.DischargeCurrentLimit; + auto dischargeCurrentLimitBelowSoc = config.Battery.DischargeCurrentLimitBelowSoc; auto dischargeCurrentValid = dischargeCurrentLimit > 0.0f; + auto statsSoC = getStats()->getSoC(); + auto statsSoCValid = getStats()->getSoCAgeSeconds() <= 60; + if (statsSoCValid && statsSoC > dischargeCurrentLimitBelowSoc) { + dischargeCurrentValid = false; + } + auto statsCurrentLimit = getStats()->getDischargeCurrentLimit(); auto statsLimitValid = config.Battery.UseBatteryReportedDischargeCurrentLimit && statsCurrentLimit >= 0.0f diff --git a/src/Configuration.cpp b/src/Configuration.cpp index 3f09b5711..b1706ddfe 100644 --- a/src/Configuration.cpp +++ b/src/Configuration.cpp @@ -88,6 +88,7 @@ void ConfigurationClass::serializeBatteryConfig(BatteryConfig const& source, Jso target["mqtt_voltage_unit"] = config.Battery.MqttVoltageUnit; target["enable_discharge_current_limit"] = config.Battery.EnableDischargeCurrentLimit; target["discharge_current_limit"] = config.Battery.DischargeCurrentLimit; + target["discharge_current_limit_below_soc"] = config.Battery.DischargeCurrentLimitBelowSoc; target["use_battery_reported_discharge_current_limit"] = config.Battery.UseBatteryReportedDischargeCurrentLimit; target["mqtt_discharge_current_topic"] = config.Battery.MqttDischargeCurrentTopic; target["mqtt_discharge_current_json_path"] = config.Battery.MqttDischargeCurrentJsonPath; @@ -387,6 +388,7 @@ void ConfigurationClass::deserializeBatteryConfig(JsonObject const& source, Batt target.MqttVoltageUnit = source["mqtt_voltage_unit"] | BatteryVoltageUnit::Volts; target.EnableDischargeCurrentLimit = source["enable_discharge_current_limit"] | BATTERY_ENABLE_DISCHARGE_CURRENT_LIMIT; target.DischargeCurrentLimit = source["discharge_current_limit"] | BATTERY_DISCHARGE_CURRENT_LIMIT; + target.DischargeCurrentLimitBelowSoc = source["discharge_current_limit_below_soc"] | BATTERY_DISCHARGE_CURRENT_LIMIT_BELOW_SOC; target.UseBatteryReportedDischargeCurrentLimit = source["use_battery_reported_discharge_current_limit"] | BATTERY_USE_BATTERY_REPORTED_DISCHARGE_CURRENT_LIMIT; strlcpy(target.MqttDischargeCurrentTopic, source["mqtt_discharge_current_topic"] | "", sizeof(config.Battery.MqttDischargeCurrentTopic)); strlcpy(target.MqttDischargeCurrentJsonPath, source["mqtt_discharge_current_json_path"] | "", sizeof(config.Battery.MqttDischargeCurrentJsonPath)); diff --git a/webapp/src/locales/de.json b/webapp/src/locales/de.json index 6aa824e06..921fd60dc 100644 --- a/webapp/src/locales/de.json +++ b/webapp/src/locales/de.json @@ -707,6 +707,7 @@ "DischargeCurrentLimitConfiguration": "Einstellungen Entladestromlimit", "LimitDischargeCurrent": "Entladestrom limitieren", "DischargeCurrentLimit": "max. Entladestrom", + "DischargeCurrentLimitBelowSoc": "Limitieren unter SoC", "UseBatteryReportedDischargeCurrentLimit": "Von der Batterie übermitteltes Limit verwenden", "BatteryReportedDischargeCurrentLimitInfo": "Hinweis: Das niedrigste Limit wird angewendet, wobei das von der Batterie übermittelte Entladestromlimit nur verwendet wird, wenn in der letzten Minute ein Update eingegangen ist; andernfalls dient das zuvor festgelegte Limit als Fallback.", "MqttDischargeCurrentTopic": "Topic für Entladestromlimit", diff --git a/webapp/src/locales/en.json b/webapp/src/locales/en.json index 69deee402..ee191089b 100644 --- a/webapp/src/locales/en.json +++ b/webapp/src/locales/en.json @@ -710,6 +710,7 @@ "DischargeCurrentLimitConfiguration": "Discharge Current Limit Settings", "LimitDischargeCurrent": "Limit Discharge Current", "DischargeCurrentLimit": "max. Discharge Current", + "DischargeCurrentLimitBelowSoc": "Apply limit below SoC", "UseBatteryReportedDischargeCurrentLimit": "Use Battery-Reported limit", "BatteryReportedDischargeCurrentLimitInfo": "Hint: The lowest limit will be applied, with the battery-reported discharge current limit used only if an update was received in the last minute; otherwise, the previously specified limit will act as a fallback.", "MqttDischargeCurrentTopic": "Discharge Current Limit Value Topic", diff --git a/webapp/src/types/BatteryConfig.ts b/webapp/src/types/BatteryConfig.ts index 4134b83d7..88f5dae17 100644 --- a/webapp/src/types/BatteryConfig.ts +++ b/webapp/src/types/BatteryConfig.ts @@ -13,6 +13,7 @@ export interface BatteryConfig { mqtt_voltage_unit: number; enable_discharge_current_limit: boolean; discharge_current_limit: number; + discharge_current_limit_below_soc: number; use_battery_reported_discharge_current_limit: boolean; mqtt_discharge_current_topic: string; mqtt_discharge_current_json_path: string; diff --git a/webapp/src/views/BatteryAdminView.vue b/webapp/src/views/BatteryAdminView.vue index c231b5b46..5c5171f52 100644 --- a/webapp/src/views/BatteryAdminView.vue +++ b/webapp/src/views/BatteryAdminView.vue @@ -175,6 +175,16 @@ postfix="A" /> + +