add check for implausible temperatures
This commit is contained in:
parent
37cec353ec
commit
96b8e12f9a
@ -6,6 +6,10 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#define MAX_PLAUSIBLE_TEMP 15000 // 150.0°C
|
||||||
|
#define MIN_PLAUSIBLE_TEMP -4000 // -40.0°C
|
||||||
|
#define MAX_ERRORED_TEMP 3 // number of implausible temperatures before panic (per BMS module)
|
||||||
|
|
||||||
#define ADBMS_NO_LOGGING_DEFS
|
#define ADBMS_NO_LOGGING_DEFS
|
||||||
#include "ADBMS_Driver.h"
|
#include "ADBMS_Driver.h"
|
||||||
|
|
||||||
|
@ -135,9 +135,22 @@ HAL_StatusTypeDef battery_update() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Process temperature values
|
// Process temperature values
|
||||||
|
int failed_sensors = 0;
|
||||||
|
|
||||||
for (size_t j = 0; j < 10; j++) { // 10 GPIOs
|
for (size_t j = 0; j < 10; j++) { // 10 GPIOs
|
||||||
battery.module[i].cellTemps[j] = ntc_mv_to_celsius(bms_data[i].auxVoltages[j]);
|
battery.module[i].cellTemps[j] = ntc_mv_to_celsius(bms_data[i].auxVoltages[j]);
|
||||||
|
|
||||||
|
if (battery.module[i].cellTemps[j] > MAX_PLAUSIBLE_TEMP || battery.module[i].cellTemps[j] < MIN_PLAUSIBLE_TEMP) {
|
||||||
|
debug_log(LOG_LEVEL_ERROR, "Sensor %u on BMS %u has implausible temperature: %d0 mC", j, i,
|
||||||
|
battery.module[i].cellTemps[j]);
|
||||||
|
if (++failed_sensors >= MAX_ERRORED_TEMP) {
|
||||||
|
// If too many implausible temperatures, panic
|
||||||
|
debug_log(LOG_LEVEL_ERROR, "Too many implausible temperatures on BMS %u, erroring...", i);
|
||||||
|
update_error_window(true, i);
|
||||||
|
return HAL_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// For new battery struct
|
// For new battery struct
|
||||||
if (battery.module[i].cellTemps[j] > battery.pack.max_temp) {
|
if (battery.module[i].cellTemps[j] > battery.pack.max_temp) {
|
||||||
battery.pack.max_temp = battery.module[i].cellTemps[j];
|
battery.pack.max_temp = battery.module[i].cellTemps[j];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user