Skip to content

Commit

Permalink
Event clearning added, LEAF safety improved
Browse files Browse the repository at this point in the history
  • Loading branch information
dalathegreat committed Feb 12, 2024
1 parent 362824f commit cc0d4ea
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 13 deletions.
2 changes: 2 additions & 0 deletions Software/src/battery/KIA-HYUNDAI-64-BATTERY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 17 additions & 5 deletions Software/src/battery/NISSAN-LEAF-BATTERY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -323,24 +327,27 @@ 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);
}
}

#ifdef INTERLOCK_REQUIRED
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

Expand All @@ -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) {
Expand Down
18 changes: 12 additions & 6 deletions Software/src/battery/TESLA-MODEL-3-BATTERY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}

Expand Down
4 changes: 2 additions & 2 deletions Software/src/devboard/utils/events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit cc0d4ea

Please sign in to comment.