From cc0d4ea4bf86db2a4f616fb033e6c090ef9a6d77 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 12 Feb 2024 23:18:06 +0200 Subject: [PATCH] Event clearning added, LEAF safety improved --- .../src/battery/KIA-HYUNDAI-64-BATTERY.cpp | 2 ++ Software/src/battery/NISSAN-LEAF-BATTERY.cpp | 22 ++++++++++++++----- .../src/battery/TESLA-MODEL-3-BATTERY.cpp | 18 ++++++++++----- Software/src/devboard/utils/events.cpp | 4 ++-- 4 files changed, 33 insertions(+), 13 deletions(-) diff --git a/Software/src/battery/KIA-HYUNDAI-64-BATTERY.cpp b/Software/src/battery/KIA-HYUNDAI-64-BATTERY.cpp index a32b8129..d2011e36 100644 --- a/Software/src/battery/KIA-HYUNDAI-64-BATTERY.cpp +++ b/Software/src/battery/KIA-HYUNDAI-64-BATTERY.cpp @@ -222,6 +222,8 @@ void update_values_kiaHyundai_64_battery() { //This function maps all the value } if (cell_deviation_mV > MAX_CELL_DEVIATION) { set_event(EVENT_CELL_DEVIATION_HIGH, 0); + } else { + clear_event(EVENT_CELL_DEVIATION_HIGH); } if (bms_status == FAULT) { //Incase we enter a critical fault state, zero out the allowed limits diff --git a/Software/src/battery/NISSAN-LEAF-BATTERY.cpp b/Software/src/battery/NISSAN-LEAF-BATTERY.cpp index c302f75b..aecf242d 100644 --- a/Software/src/battery/NISSAN-LEAF-BATTERY.cpp +++ b/Software/src/battery/NISSAN-LEAF-BATTERY.cpp @@ -267,11 +267,15 @@ void update_values_leaf_battery() { /* This function maps all the values fetched if (LB_Full_CHARGE_flag) { //Battery reports that it is fully charged stop all further charging incase it hasn't already set_event(EVENT_BATTERY_FULL, 0); max_target_charge_power = 0; + } else { + clear_event(EVENT_BATTERY_FULL); } if (LB_Capacity_Empty) { //Battery reports that it is fully discharged. Stop all further discharging incase it hasn't already set_event(EVENT_BATTERY_EMPTY, 0); max_target_discharge_power = 0; + } else { + clear_event(EVENT_BATTERY_EMPTY); } if (LB_Relay_Cut_Request) { //LB_FAIL, BMS requesting shutdown and contactors to be opened @@ -323,14 +327,18 @@ void update_values_leaf_battery() { /* This function maps all the values fetched default: break; } + } else { //LB_Failsafe_Status == 0 + clear_event(EVENT_BATTERY_DISCHG_STOP_REQ); + clear_event(EVENT_BATTERY_CHG_STOP_REQ); + clear_event(EVENT_BATTERY_CHG_DISCHG_STOP_REQ); } if (LB_StateOfHealth < 25) { //Battery is extremely degraded, not fit for secondlifestorage. Zero it all out. if (LB_StateOfHealth != 0) { //Extra check to see that we actually have a SOH Value available errorCode = 5; set_event(EVENT_LOW_SOH, LB_StateOfHealth); - max_target_discharge_power = 0; - max_target_charge_power = 0; + } else { + clear_event(EVENT_LOW_SOH); } } @@ -338,9 +346,8 @@ void update_values_leaf_battery() { /* This function maps all the values fetched if (!LB_Interlock) { set_event(EVENT_HVIL_FAILURE, 0); errorCode = 6; - SOC = 0; - max_target_discharge_power = 0; - max_target_charge_power = 0; + } else { + clear_event(EVENT_HVIL_FAILURE); } #endif @@ -359,6 +366,11 @@ void update_values_leaf_battery() { /* This function maps all the values fetched set_event(EVENT_CAN_RX_WARNING, 0); } + if (bms_status == FAULT) { //Incase we enter a critical fault state, zero out the allowed limits + max_target_charge_power = 0; + max_target_discharge_power = 0; + } + /*Finally print out values to serial if configured to do so*/ #ifdef DEBUG_VIA_USB if (errorCode > 0) { diff --git a/Software/src/battery/TESLA-MODEL-3-BATTERY.cpp b/Software/src/battery/TESLA-MODEL-3-BATTERY.cpp index 036c8926..58b08a79 100644 --- a/Software/src/battery/TESLA-MODEL-3-BATTERY.cpp +++ b/Software/src/battery/TESLA-MODEL-3-BATTERY.cpp @@ -236,6 +236,8 @@ void update_values_tesla_model_3_battery() { //This function maps all the value if (hvil_status == 3) { //INTERNAL_OPEN_FAULT - Someone disconnected a high voltage cable while battery was in use set_event(EVENT_INTERNAL_OPEN_FAULT, 0); + } else { + clear_event(EVENT_INTERNAL_OPEN_FAULT); } cell_deviation_mV = (cell_max_v - cell_min_v); @@ -270,23 +272,27 @@ void update_values_tesla_model_3_battery() { //This function maps all the value if (LFP_Chemistry) { //LFP limits used for voltage safeties if (cell_max_v >= MAX_CELL_VOLTAGE_LFP) { - set_event(EVENT_CELL_OVER_VOLTAGE, 0); + set_event(EVENT_CELL_OVER_VOLTAGE, cell_max_v); } if (cell_min_v <= MIN_CELL_VOLTAGE_LFP) { - set_event(EVENT_CELL_UNDER_VOLTAGE, 0); + set_event(EVENT_CELL_UNDER_VOLTAGE, cell_min_v); } if (cell_deviation_mV > MAX_CELL_DEVIATION_LFP) { - set_event(EVENT_CELL_DEVIATION_HIGH, 0); + set_event(EVENT_CELL_DEVIATION_HIGH, cell_deviation_mV); + } else { + clear_event(EVENT_CELL_DEVIATION_HIGH); } } else { //NCA/NCM limits used if (cell_max_v >= MAX_CELL_VOLTAGE_NCA_NCM) { - set_event(EVENT_CELL_OVER_VOLTAGE, 0); + set_event(EVENT_CELL_OVER_VOLTAGE, cell_max_v); } if (cell_min_v <= MIN_CELL_VOLTAGE_NCA_NCM) { - set_event(EVENT_CELL_UNDER_VOLTAGE, 0); + set_event(EVENT_CELL_UNDER_VOLTAGE, cell_min_v); } if (cell_deviation_mV > MAX_CELL_DEVIATION_NCA_NCM) { - set_event(EVENT_CELL_DEVIATION_HIGH, 0); + set_event(EVENT_CELL_DEVIATION_HIGH, cell_deviation_mV); + } else { + clear_event(EVENT_CELL_DEVIATION_HIGH); } } diff --git a/Software/src/devboard/utils/events.cpp b/Software/src/devboard/utils/events.cpp index 9f89c36b..64f3c59a 100644 --- a/Software/src/devboard/utils/events.cpp +++ b/Software/src/devboard/utils/events.cpp @@ -111,7 +111,7 @@ void init_events(void) { events.entries[EVENT_WATER_INGRESS].level = EVENT_LEVEL_ERROR; events.entries[EVENT_12V_LOW].level = EVENT_LEVEL_WARNING; events.entries[EVENT_SOC_PLAUSIBILITY_ERROR].level = EVENT_LEVEL_ERROR; - events.entries[EVENT_KWH_PLAUSIBILITY_ERROR].level = EVENT_LEVEL_WARNING; + events.entries[EVENT_KWH_PLAUSIBILITY_ERROR].level = EVENT_LEVEL_INFO; events.entries[EVENT_BATTERY_EMPTY].level = EVENT_LEVEL_INFO; events.entries[EVENT_BATTERY_FULL].level = EVENT_LEVEL_INFO; events.entries[EVENT_BATTERY_CHG_STOP_REQ].level = EVENT_LEVEL_ERROR; @@ -174,7 +174,7 @@ const char* get_event_message_string(EVENTS_ENUM_TYPE event) { case EVENT_SOC_PLAUSIBILITY_ERROR: return "ERROR: SOC% reported by battery not plausible. Restart battery!"; case EVENT_KWH_PLAUSIBILITY_ERROR: - return "Warning: kWh remaining reported by battery not plausible. Battery needs cycling."; + return "Info: kWh remaining reported by battery not plausible. Battery needs cycling."; case EVENT_BATTERY_EMPTY: return "Info: Battery is completely discharged"; case EVENT_BATTERY_FULL: