From 61d47b5359d902fc61c809eaa18fb6291a2f9715 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20=C3=96ster?= Date: Thu, 25 Jul 2024 21:30:25 +0300 Subject: [PATCH 1/4] Only update values that are sane --- .../src/battery/IMIEV-CZERO-ION-BATTERY.cpp | 37 ++++++++++++------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp b/Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp index be45bf0a..0181385f 100644 --- a/Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp +++ b/Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp @@ -10,7 +10,7 @@ //Figure out if CAN messages need to be sent to keep the system happy? /* Do not change code below unless you are sure what you are doing */ -#define MAX_CELL_VOLTAGE 4100 +#define MAX_CELL_VOLTAGE 4150 #define MIN_CELL_VOLTAGE 2750 static uint8_t errorCode = 0; //stores if we have an error code active from battery control logic static uint8_t BMU_Detected = 0; @@ -92,13 +92,21 @@ void update_values_battery() { //This function maps all the values fetched via datalayer.battery.status.cell_voltages_mV[i] = (uint16_t)(cell_voltages[i] * 1000); } - datalayer.battery.status.cell_max_voltage_mV = (uint16_t)(max_volt_cel * 1000); + if (max_volt_cel > 2200) { // Only update cellvoltage when we have a value + datalayer.battery.status.cell_max_voltage_mV = (uint16_t)(max_volt_cel * 1000); + } - datalayer.battery.status.cell_min_voltage_mV = (uint16_t)(min_volt_cel * 1000); + if (min_volt_cel > 2200) { // Only update cellvoltage when we have a value + datalayer.battery.status.cell_min_voltage_mV = (uint16_t)(min_volt_cel * 1000); + } - datalayer.battery.status.temperature_min_dC = (int16_t)(min_temp_cel * 10); + if (min_temp_cel > -49) { // Only update temperature when we have a value + datalayer.battery.status.temperature_min_dC = (int16_t)(min_temp_cel * 10); + } - datalayer.battery.status.temperature_max_dC = (int16_t)(max_temp_cel * 10); + if (max_temp_cel > -49) { // Only update temperature when we have a value + datalayer.battery.status.temperature_max_dC = (int16_t)(max_temp_cel * 10); + } //Check safeties if (datalayer.battery.status.cell_max_voltage_mV >= MAX_CELL_VOLTAGE) { @@ -198,15 +206,18 @@ void receive_can_battery(CAN_frame_t rx_frame) { cell_voltages[voltage_index + 1] = voltage2; } - if (pid_index == 0) { - cell_temperatures[temp_index] = temp2; - cell_temperatures[temp_index + 1] = temp3; - } else { - cell_temperatures[temp_index] = temp1; - if (cmu_id != 6 && cmu_id != 12) { - cell_temperatures[temp_index + 1] = temp2; + if () + + if (temp1 == 0) { + if () + cell_temperatures[temp_index] = temp2; + cell_temperatures[temp_index + 1] = temp3; + } else { + cell_temperatures[temp_index] = temp1; + if (cmu_id != 6 && cmu_id != 12) { + cell_temperatures[temp_index + 1] = temp2; + } } - } break; default: break; From ccb099f2c07a753f6592e1c6ed7143e33a05526c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20=C3=96ster?= Date: Thu, 25 Jul 2024 21:42:30 +0300 Subject: [PATCH 2/4] Fix compilation error --- .../src/battery/IMIEV-CZERO-ION-BATTERY.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp b/Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp index 0181385f..e10b130d 100644 --- a/Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp +++ b/Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp @@ -206,18 +206,15 @@ void receive_can_battery(CAN_frame_t rx_frame) { cell_voltages[voltage_index + 1] = voltage2; } - if () - - if (temp1 == 0) { - if () - cell_temperatures[temp_index] = temp2; - cell_temperatures[temp_index + 1] = temp3; - } else { - cell_temperatures[temp_index] = temp1; - if (cmu_id != 6 && cmu_id != 12) { - cell_temperatures[temp_index + 1] = temp2; - } + if (temp1 == 0) { + cell_temperatures[temp_index] = temp2; + cell_temperatures[temp_index + 1] = temp3; + } else { + cell_temperatures[temp_index] = temp1; + if (cmu_id != 6 && cmu_id != 12) { + cell_temperatures[temp_index + 1] = temp2; } + } break; default: break; From 6c5fbd6046749c22e5e85615067bf0614d5eb5b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20=C3=96ster?= Date: Sun, 4 Aug 2024 23:35:18 +0300 Subject: [PATCH 3/4] Restore pid_index --- Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp b/Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp index e10b130d..28b2d120 100644 --- a/Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp +++ b/Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp @@ -206,7 +206,7 @@ void receive_can_battery(CAN_frame_t rx_frame) { cell_voltages[voltage_index + 1] = voltage2; } - if (temp1 == 0) { + if (pid_index == 0) { cell_temperatures[temp_index] = temp2; cell_temperatures[temp_index + 1] = temp3; } else { From 99a2dd579628bee60370ea55428d9939c3be8dce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20=C3=96ster?= Date: Sun, 4 Aug 2024 23:36:10 +0300 Subject: [PATCH 4/4] Fix sizeof --- Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp b/Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp index 28b2d120..350a560c 100644 --- a/Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp +++ b/Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp @@ -71,7 +71,7 @@ void update_values_battery() { //This function maps all the values fetched via } } - static int m = sizeof(cell_voltages) / sizeof(cell_temperatures[0]); + static int m = sizeof(cell_temperatures) / sizeof(cell_temperatures[0]); max_temp_cel = cell_temperatures[0]; // Initialize max with the first element of the array for (int i = 1; i < m; i++) { if (cell_temperatures[i] > max_temp_cel) {