Skip to content

Commit

Permalink
Event setting
Browse files Browse the repository at this point in the history
  • Loading branch information
Cabooman committed Feb 5, 2024
1 parent 5edfd6c commit 1d09dac
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Software/src/battery/BMW-I3-BATTERY.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "BMW-I3-BATTERY.h"
#include "../devboard/utils/events.h"
#include "../lib/miwagner-ESP32-Arduino-CAN/CAN_config.h"
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"

Expand Down Expand Up @@ -103,6 +104,7 @@ void update_values_i3_battery() { //This function maps all the values fetched v
if (!CANstillAlive) {
bms_status = FAULT;
Serial.println("No CAN communication detected for 60s. Shutting down battery control.");
set_event(EVENT_CAN_FAILURE, 0);
} else {
CANstillAlive--;
}
Expand Down
2 changes: 2 additions & 0 deletions Software/src/battery/CHADEMO-BATTERY.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "CHADEMO-BATTERY.h"
#include "../devboard/utils/events.h"
#include "../lib/miwagner-ESP32-Arduino-CAN/CAN_config.h"
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"

Expand Down Expand Up @@ -107,6 +108,7 @@ void update_values_chademo_battery() { //This function maps all the values fetc
bms_status = FAULT;
errorCode = 7;
Serial.println("No CAN communication detected for 60s. Shutting down battery control.");
set_event(EVENT_CAN_FAILURE, 0);
} else {
CANstillAlive--;
}
Expand Down
2 changes: 2 additions & 0 deletions Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "IMIEV-CZERO-ION-BATTERY.h"
#include "../devboard/utils/events.h"
#include "../lib/miwagner-ESP32-Arduino-CAN/CAN_config.h"
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"

Expand Down Expand Up @@ -109,6 +110,7 @@ void update_values_imiev_battery() { //This function maps all the values fetche
if (!CANstillAlive) {
bms_status = FAULT;
Serial.println("No CAN communication detected for 60s. Shutting down battery control.");
set_event(EVENT_CAN_FAILURE, 0);
} else {
CANstillAlive--;
}
Expand Down
7 changes: 7 additions & 0 deletions Software/src/battery/KIA-HYUNDAI-64-BATTERY.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "KIA-HYUNDAI-64-BATTERY.h"
#include "../devboard/utils/events.h"
#include "../lib/miwagner-ESP32-Arduino-CAN/CAN_config.h"
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"

Expand Down Expand Up @@ -200,18 +201,21 @@ void update_values_kiaHyundai_64_battery() { //This function maps all the value
if (!CANstillAlive) {
bms_status = FAULT;
Serial.println("No CAN communication detected for 60s. Shutting down battery control.");
set_event(EVENT_CAN_FAILURE, 0);
} else {
CANstillAlive--;
}

if (waterleakageSensor == 0) {
Serial.println("Water leakage inside battery detected. Operation halted. Inspect battery!");
bms_status = FAULT;
set_event(EVENT_WATER_INGRESS, 0);
}

if (leadAcidBatteryVoltage < 110) {
Serial.println("12V battery source below required voltage to safely close contactors. Inspect the supply/battery!");
LEDcolor = YELLOW;
set_event(EVENT_12V_LOW, leadAcidBatteryVoltage);
}

// Check if cell voltages are within allowed range
Expand All @@ -220,14 +224,17 @@ void update_values_kiaHyundai_64_battery() { //This function maps all the value
if (cell_max_voltage >= MAX_CELL_VOLTAGE) {
bms_status = FAULT;
Serial.println("ERROR: CELL OVERVOLTAGE!!! Stopping battery charging and discharging. Inspect battery!");
set_event(EVENT_CELL_OVER_VOLTAGE, 0);
}
if (cell_min_voltage <= MIN_CELL_VOLTAGE) {
bms_status = FAULT;
Serial.println("ERROR: CELL UNDERVOLTAGE!!! Stopping battery charging and discharging. Inspect battery!");
set_event(EVENT_CELL_UNDER_VOLTAGE, 0);
}
if (cell_deviation_mV > MAX_CELL_DEVIATION) {
LEDcolor = YELLOW;
Serial.println("ERROR: HIGH CELL DEVIATION!!! Inspect battery!");
set_event(EVENT_CELL_DEVIATION_HIGH, 0);
}

if (bms_status == FAULT) { //Incase we enter a critical fault state, zero out the allowed limits
Expand Down
12 changes: 12 additions & 0 deletions Software/src/battery/NISSAN-LEAF-BATTERY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#ifdef MQTT
#include "../devboard/mqtt/mqtt.h"
#endif
#include "../devboard/utils/events.h"
#include "../lib/miwagner-ESP32-Arduino-CAN/CAN_config.h"
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"

Expand Down Expand Up @@ -262,6 +263,7 @@ void update_values_leaf_battery() { /* This function maps all the values fetched
#ifdef DEBUG_VIA_USB
Serial.println("ERROR: SOC% reported by battery not plausible. Restart battery!");
#endif
set_event(EVENT_SOC_PLAUSIBILITY_ERROR, LB_SOC / 10);
}
}

Expand Down Expand Up @@ -311,6 +313,7 @@ void update_values_leaf_battery() { /* This function maps all the values fetched
#ifdef DEBUG_VIA_USB
Serial.println("ERROR: Battery raised caution indicator AND requested discharge stop. Inspect battery status!");
#endif
set_event(EVENT_BATTERY_DISCHG_STOP_REQ, 0);
break;
case (6):
//Caution Lamp Request & Charging Mode Stop Request
Expand All @@ -319,6 +322,7 @@ void update_values_leaf_battery() { /* This function maps all the values fetched
#ifdef DEBUG_VIA_USB
Serial.println("ERROR: Battery raised caution indicator AND requested charge stop. Inspect battery status!");
#endif
set_event(EVENT_BATTERY_CHG_STOP_REQ, 0);
break;
case (7):
//Caution Lamp Request & Charging Mode Stop Request & Normal Stop Request
Expand All @@ -328,6 +332,7 @@ void update_values_leaf_battery() { /* This function maps all the values fetched
Serial.println(
"ERROR: Battery raised caution indicator AND requested charge/discharge stop. Inspect battery status!");
#endif
set_event(EVENT_BATTERY_CHG_DISCHG_STOP_REQ, 0);
break;
default:
break;
Expand All @@ -342,6 +347,7 @@ void update_values_leaf_battery() { /* This function maps all the values fetched
#endif
bms_status = FAULT;
errorCode = 5;
set_event(EVENT_LOW_SOH, LB_StateOfHealth);
max_target_discharge_power = 0;
max_target_charge_power = 0;
}
Expand All @@ -355,6 +361,7 @@ void update_values_leaf_battery() { /* This function maps all the values fetched
"disabled!");
#endif
bms_status = FAULT;
set_event(EVENT_HVIL_FAILURE, 0);
errorCode = 6;
SOC = 0;
max_target_discharge_power = 0;
Expand All @@ -369,6 +376,7 @@ void update_values_leaf_battery() { /* This function maps all the values fetched
#ifdef DEBUG_VIA_USB
Serial.println("ERROR: No CAN communication detected for 60s. Shutting down battery control.");
#endif
set_event(EVENT_CAN_FAILURE, 0);
} else {
CANstillAlive--;
}
Expand All @@ -380,6 +388,7 @@ void update_values_leaf_battery() { /* This function maps all the values fetched
#ifdef DEBUG_VIA_USB
Serial.println("ERROR: High amount of corrupted CAN messages detected. Check CAN wire shielding!");
#endif
set_event(EVENT_CAN_WARNING, 0);
}

/*Finally print out values to serial if configured to do so*/
Expand Down Expand Up @@ -615,6 +624,7 @@ void receive_can_leaf_battery(CAN_frame_t rx_frame) {
#ifdef DEBUG_VIA_USB
Serial.println("HIGH CELL DEVIATION!!! Inspect battery!");
#endif
set_event(EVENT_CELL_DEVIATION_HIGH, 0);
}

if (min_max_voltage[1] >= MAX_CELL_VOLTAGE) {
Expand All @@ -623,13 +633,15 @@ void receive_can_leaf_battery(CAN_frame_t rx_frame) {
#ifdef DEBUG_VIA_USB
Serial.println("CELL OVERVOLTAGE!!! Stopping battery charging and discharging. Inspect battery!");
#endif
set_event(EVENT_CELL_OVER_VOLTAGE, 0);
}
if (min_max_voltage[0] <= MIN_CELL_VOLTAGE) {
bms_status = FAULT;
errorCode = 9;
#ifdef DEBUG_VIA_USB
Serial.println("CELL UNDERVOLTAGE!!! Stopping battery charging and discharging. Inspect battery!");
#endif
set_event(EVENT_CELL_UNDER_VOLTAGE, 0);
}
break;
}
Expand Down
5 changes: 5 additions & 0 deletions Software/src/battery/RENAULT-KANGOO-BATTERY.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "RENAULT-KANGOO-BATTERY.h"
#include "../devboard/utils/events.h"
#include "../lib/miwagner-ESP32-Arduino-CAN/CAN_config.h"
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"

Expand Down Expand Up @@ -126,21 +127,25 @@ void update_values_kangoo_battery() { //This function maps all the values fetch
if (!CANstillAlive) {
bms_status = FAULT;
Serial.println("No CAN communication detected for 60s. Shutting down battery control.");
set_event(EVENT_CAN_FAILURE, 0);
} else {
CANstillAlive--;
}

if (LB_Cell_Max_Voltage >= ABSOLUTE_CELL_MAX_VOLTAGE) {
bms_status = FAULT;
Serial.println("ERROR: CELL OVERVOLTAGE!!! Stopping battery charging and discharging. Inspect battery!");
set_event(EVENT_CELL_OVER_VOLTAGE, 0);
}
if (LB_Cell_Min_Voltage <= ABSOLUTE_CELL_MIN_VOLTAGE) {
bms_status = FAULT;
Serial.println("ERROR: CELL UNDERVOLTAGE!!! Stopping battery charging and discharging. Inspect battery!");
set_event(EVENT_CELL_UNDER_VOLTAGE, 0);
}
if (cell_deviation_mV > MAX_CELL_DEVIATION_MV) {
LEDcolor = YELLOW;
Serial.println("ERROR: HIGH CELL mV DEVIATION!!! Inspect battery!");
set_event(EVENT_CELL_DEVIATION_HIGH, 0);
}

#ifdef DEBUG_VIA_USB
Expand Down
5 changes: 5 additions & 0 deletions Software/src/battery/RENAULT-ZOE-BATTERY.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "RENAULT-ZOE-BATTERY.h"
#include "../devboard/utils/events.h"
#include "../lib/miwagner-ESP32-Arduino-CAN/CAN_config.h"
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"

Expand Down Expand Up @@ -87,21 +88,25 @@ void update_values_zoe_battery() { //This function maps all the values fetched
if (!CANstillAlive) {
bms_status = FAULT;
Serial.println("No CAN communication detected for 60s. Shutting down battery control.");
set_event(EVENT_CAN_FAILURE, 0);
} else {
CANstillAlive--;
}

if (LB_Cell_Max_Voltage >= ABSOLUTE_CELL_MAX_VOLTAGE) {
bms_status = FAULT;
Serial.println("ERROR: CELL OVERVOLTAGE!!! Stopping battery charging and discharging. Inspect battery!");
set_event(EVENT_CELL_OVER_VOLTAGE, 0);
}
if (LB_Cell_Min_Voltage <= ABSOLUTE_CELL_MIN_VOLTAGE) {
bms_status = FAULT;
Serial.println("ERROR: CELL UNDERVOLTAGE!!! Stopping battery charging and discharging. Inspect battery!");
set_event(EVENT_CELL_UNDER_VOLTAGE, 0);
}
if (cell_deviation_mV > MAX_CELL_DEVIATION_MV) {
LEDcolor = YELLOW;
Serial.println("ERROR: HIGH CELL mV DEVIATION!!! Inspect battery!");
set_event(EVENT_CELL_DEVIATION_HIGH, 0);
}

#ifdef DEBUG_VIA_USB
Expand Down
2 changes: 2 additions & 0 deletions Software/src/battery/SANTA-FE-PHEV-BATTERY.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "SANTA-FE-PHEV-BATTERY.h"
#include "../devboard/utils/events.h"
#include "../lib/miwagner-ESP32-Arduino-CAN/CAN_config.h"
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"

Expand Down Expand Up @@ -84,6 +85,7 @@ void update_values_santafe_phev_battery() { //This function maps all the values
if (!CANstillAlive) {
bms_status = FAULT;
Serial.println("No CAN communication detected for 60s. Shutting down battery control.");
set_event(EVENT_CAN_FAILURE, 0);
} else {
CANstillAlive--;
}
Expand Down
11 changes: 11 additions & 0 deletions Software/src/battery/TESLA-MODEL-3-BATTERY.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "TESLA-MODEL-3-BATTERY.h"
#include "../devboard/utils/events.h"
#include "../lib/miwagner-ESP32-Arduino-CAN/CAN_config.h"
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"

Expand Down Expand Up @@ -231,13 +232,15 @@ void update_values_tesla_model_3_battery() { //This function maps all the value
if (!stillAliveCAN) {
bms_status = FAULT;
Serial.println("ERROR: No CAN communication detected for 60s. Shutting down battery control.");
set_event(EVENT_CAN_FAILURE, 0);
} else {
stillAliveCAN--;
}

if (hvil_status == 3) { //INTERNAL_OPEN_FAULT - Someone disconnected a high voltage cable while battery was in use
bms_status = FAULT;
Serial.println("ERROR: High voltage cable removed while battery running. Opening contactors!");
set_event(EVENT_INTERNAL_OPEN_FAULT, 0);
}

cell_deviation_mV = (cell_max_v - cell_min_v);
Expand All @@ -258,40 +261,48 @@ void update_values_tesla_model_3_battery() { //This function maps all the value
if (SOC < 6500) { //When SOC is less than 65.00% when approaching max voltage
bms_status = FAULT;
Serial.println("ERROR: SOC% reported by battery not plausible. Restart battery!");
set_event(EVENT_SOC_PLAUSIBILITY_ERROR, SOC / 100);
}
}

//Check if BMS is in need of recalibration
if (nominal_full_pack_energy < REASONABLE_ENERGYAMOUNT) {
Serial.println("Warning: kWh remaining reported by battery not plausible. Battery needs cycling.");
set_event(EVENT_KWH_PLAUSIBILITY_ERROR, nominal_full_pack_energy);
LEDcolor = YELLOW;
}

if (LFP_Chemistry) { //LFP limits used for voltage safeties
if (cell_max_v >= MAX_CELL_VOLTAGE_LFP) {
bms_status = FAULT;
Serial.println("ERROR: CELL OVERVOLTAGE!!! Stopping battery charging and discharging. Inspect battery!");
set_event(EVENT_CELL_OVER_VOLTAGE, 0);
}
if (cell_min_v <= MIN_CELL_VOLTAGE_LFP) {
bms_status = FAULT;
Serial.println("ERROR: CELL UNDERVOLTAGE!!! Stopping battery charging and discharging. Inspect battery!");
set_event(EVENT_CELL_UNDER_VOLTAGE, 0);
}
if (cell_deviation_mV > MAX_CELL_DEVIATION_LFP) {
LEDcolor = YELLOW;
Serial.println("ERROR: HIGH CELL DEVIATION!!! Inspect battery!");
set_event(EVENT_CELL_DEVIATION_HIGH, 0);
}
} else { //NCA/NCM limits used
if (cell_max_v >= MAX_CELL_VOLTAGE_NCA_NCM) {
bms_status = FAULT;
Serial.println("ERROR: CELL OVERVOLTAGE!!! Stopping battery charging and discharging. Inspect battery!");
set_event(EVENT_CELL_OVER_VOLTAGE, 0);
}
if (cell_min_v <= MIN_CELL_VOLTAGE_NCA_NCM) {
bms_status = FAULT;
Serial.println("ERROR: CELL UNDERVOLTAGE!!! Stopping battery charging and discharging. Inspect battery!");
set_event(EVENT_CELL_UNDER_VOLTAGE, 0);
}
if (cell_deviation_mV > MAX_CELL_DEVIATION_NCA_NCM) {
LEDcolor = YELLOW;
Serial.println("ERROR: HIGH CELL DEVIATION!!! Inspect battery!");
set_event(EVENT_CELL_DEVIATION_HIGH, 0);
}
}

Expand Down

0 comments on commit 1d09dac

Please sign in to comment.