Skip to content

Commit

Permalink
Merge pull request #177 from dalathegreat/feature/leaf-events
Browse files Browse the repository at this point in the history
Bugfix: Clear battery events properly
  • Loading branch information
dalathegreat authored Feb 13, 2024
2 parents 9d803c1 + bc9a879 commit a238c8b
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 16 deletions.
1 change: 1 addition & 0 deletions Software/src/battery/BMW-I3-BATTERY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ void update_values_i3_battery() { //This function maps all the values fetched v
set_event(EVENT_CAN_RX_FAILURE, 0);
} else {
CANstillAlive--;
clear_event(EVENT_CAN_RX_FAILURE);
}

#ifdef DEBUG_VIA_USB
Expand Down
1 change: 1 addition & 0 deletions Software/src/battery/CHADEMO-BATTERY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ void update_values_chademo_battery() { //This function maps all the values fetc
set_event(EVENT_CAN_RX_FAILURE, 0);
} else {
CANstillAlive--;
clear_event(EVENT_CAN_RX_FAILURE);
}

#ifdef DEBUG_VIA_USB
Expand Down
1 change: 1 addition & 0 deletions Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ void update_values_imiev_battery() { //This function maps all the values fetche
set_event(EVENT_CAN_RX_FAILURE, 0);
} else {
CANstillAlive--;
clear_event(EVENT_CAN_RX_FAILURE);
}

if (!BMU_Detected) {
Expand Down
3 changes: 3 additions & 0 deletions Software/src/battery/KIA-HYUNDAI-64-BATTERY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ void update_values_kiaHyundai_64_battery() { //This function maps all the value
set_event(EVENT_CAN_RX_FAILURE, 0);
} else {
CANstillAlive--;
clear_event(EVENT_CAN_RX_FAILURE);
}

if (waterleakageSensor == 0) {
Expand All @@ -221,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
32 changes: 24 additions & 8 deletions Software/src/battery/NISSAN-LEAF-BATTERY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ static int16_t LB_SOC = 500; //0 - 100.0 % (0-1000) The real S
static int16_t CalculatedSOC = 0; // Temporary value used for calculating SOC
static uint16_t LB_TEMP = 0; //Temporary value used in status checks
static uint16_t LB_Wh_Remaining = 0; //Amount of energy in battery, in Wh
static uint16_t LB_GIDS = 0;
static uint16_t LB_GIDS = 273; //Startup in 24kWh mode
static uint16_t LB_MAX = 0;
static uint16_t LB_Max_GIDS = 273; //Startup in 24kWh mode
static uint16_t LB_StateOfHealth = 99; //State of health %
Expand Down Expand Up @@ -247,8 +247,9 @@ void update_values_leaf_battery() { /* This function maps all the values fetched
}

/*Extra safety functions below*/
if (LB_GIDS < 10) //800Wh left in battery
{ //Battery is running abnormally low, some discharge logic might have failed. Zero it all out.
if (LB_GIDS < 6) //500Wh left in battery
{ //Battery is running abnormally low, some discharge logic might have failed. Zero it all out.
set_event(EVENT_BATTERY_EMPTY, 0);
SOC = 0;
max_target_discharge_power = 0;
}
Expand All @@ -264,11 +265,17 @@ 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 @@ -320,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 @@ -347,6 +357,7 @@ void update_values_leaf_battery() { /* This function maps all the values fetched
set_event(EVENT_CAN_RX_FAILURE, 0);
} else {
CANstillAlive--;
clear_event(EVENT_CAN_RX_FAILURE);
}
if (CANerror >
MAX_CAN_FAILURES) //Also check if we have recieved too many malformed CAN messages. If so, signal via LED
Expand All @@ -355,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
3 changes: 3 additions & 0 deletions Software/src/battery/RENAULT-KANGOO-BATTERY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ void update_values_kangoo_battery() { //This function maps all the values fetch
set_event(EVENT_CAN_RX_FAILURE, 0);
} else {
CANstillAlive--;
clear_event(EVENT_CAN_RX_FAILURE);
}

if (LB_Cell_Max_Voltage >= ABSOLUTE_CELL_MAX_VOLTAGE) {
Expand All @@ -136,6 +137,8 @@ void update_values_kangoo_battery() { //This function maps all the values fetch
}
if (cell_deviation_mV > MAX_CELL_DEVIATION_MV) {
set_event(EVENT_CELL_DEVIATION_HIGH, 0);
} else {
clear_event(EVENT_CELL_DEVIATION_HIGH);
}

#ifdef DEBUG_VIA_USB
Expand Down
3 changes: 3 additions & 0 deletions Software/src/battery/RENAULT-ZOE-BATTERY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ void update_values_zoe_battery() { //This function maps all the values fetched
set_event(EVENT_CAN_RX_FAILURE, 0);
} else {
CANstillAlive--;
clear_event(EVENT_CAN_RX_FAILURE);
}

if (LB_Cell_Max_Voltage >= ABSOLUTE_CELL_MAX_VOLTAGE) {
Expand All @@ -97,6 +98,8 @@ void update_values_zoe_battery() { //This function maps all the values fetched
}
if (cell_deviation_mV > MAX_CELL_DEVIATION_MV) {
set_event(EVENT_CELL_DEVIATION_HIGH, 0);
} else {
clear_event(EVENT_CELL_DEVIATION_HIGH);
}

#ifdef DEBUG_VIA_USB
Expand Down
1 change: 1 addition & 0 deletions Software/src/battery/SANTA-FE-PHEV-BATTERY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ void update_values_santafe_phev_battery() { //This function maps all the values
set_event(EVENT_CAN_RX_FAILURE, 0);
} else {
CANstillAlive--;
clear_event(EVENT_CAN_RX_FAILURE);
}

#ifdef DEBUG_VIA_USB
Expand Down
19 changes: 13 additions & 6 deletions Software/src/battery/TESLA-MODEL-3-BATTERY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,13 @@ void update_values_tesla_model_3_battery() { //This function maps all the value
set_event(EVENT_CAN_RX_FAILURE, 0);
} else {
stillAliveCAN--;
clear_event(EVENT_CAN_RX_FAILURE);
}

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 @@ -269,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 - MAX_CELL_VOLTAGE_LFP));
}
if (cell_min_v <= MIN_CELL_VOLTAGE_LFP) {
set_event(EVENT_CELL_UNDER_VOLTAGE, 0);
set_event(EVENT_CELL_UNDER_VOLTAGE, (MIN_CELL_VOLTAGE_LFP - 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 - MAX_CELL_VOLTAGE_NCA_NCM));
}
if (cell_min_v <= MIN_CELL_VOLTAGE_NCA_NCM) {
set_event(EVENT_CELL_UNDER_VOLTAGE, 0);
set_event(EVENT_CELL_UNDER_VOLTAGE, (MIN_CELL_VOLTAGE_NCA_NCM - 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
10 changes: 8 additions & 2 deletions Software/src/devboard/utils/events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ 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;
events.entries[EVENT_BATTERY_DISCHG_STOP_REQ].level = EVENT_LEVEL_ERROR;
events.entries[EVENT_BATTERY_CHG_DISCHG_STOP_REQ].level = EVENT_LEVEL_ERROR;
Expand Down Expand Up @@ -188,7 +190,11 @@ 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:
return "Info: Battery is fully charged";
case EVENT_BATTERY_CHG_STOP_REQ:
return "ERROR: Battery raised caution indicator AND requested charge stop. Inspect battery status!";
case EVENT_BATTERY_DISCHG_STOP_REQ:
Expand Down
2 changes: 2 additions & 0 deletions Software/src/devboard/utils/events.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
XX(EVENT_12V_LOW) \
XX(EVENT_SOC_PLAUSIBILITY_ERROR) \
XX(EVENT_KWH_PLAUSIBILITY_ERROR) \
XX(EVENT_BATTERY_EMPTY) \
XX(EVENT_BATTERY_FULL) \
XX(EVENT_BATTERY_CHG_STOP_REQ) \
XX(EVENT_BATTERY_DISCHG_STOP_REQ) \
XX(EVENT_BATTERY_CHG_DISCHG_STOP_REQ) \
Expand Down

0 comments on commit a238c8b

Please sign in to comment.