rework sanity checks for temperature sensors
This commit is contained in:
parent
97956882dd
commit
6e6d2965f7
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@ -11,7 +11,8 @@
|
||||
"compare": "c",
|
||||
"inputs.h": "c",
|
||||
"cstdlib": "c",
|
||||
"typeinfo": "c"
|
||||
"typeinfo": "c",
|
||||
"limits": "c"
|
||||
},
|
||||
"idf.openOcdConfigs": [
|
||||
"board/esp32-wrover-kit-3.3v.cfg"
|
||||
|
@ -2,26 +2,16 @@
|
||||
#include "freertos/task.h"
|
||||
#include "esp_log.h"
|
||||
#include "safety.h"
|
||||
#include "outputs.h"
|
||||
#include "inputs.h"
|
||||
|
||||
#define PERIODIC_INTERVAL 1U // run safety checks every 1sec
|
||||
|
||||
typedef struct _TemperatureSensorLimit
|
||||
{
|
||||
float max; // Maximum temperature limit
|
||||
float min; // Minimum temperature limit
|
||||
} sTemperatureSensorLimit;
|
||||
|
||||
static const char *TAG = "smart-oil-heater-control-system-safety";
|
||||
static SemaphoreHandle_t xMutexAccessSafety = NULL;
|
||||
sSafetyStateElement safetyStates[NUMBER_OF_ERROR_STATES] = {
|
||||
{0, "Emergency Stop"},
|
||||
{0, "Safety Door Open"},
|
||||
{0, "Overheating"},
|
||||
{0, "Low Battery"}};
|
||||
|
||||
static const sTemperatureSensorLimit sChamperTemperatureLimit = {75.0f, 15.0f};
|
||||
sSensorSanityCheck sanityChecks[NUMBER_OF_SENSOR_SANITY_CHECKS] = {
|
||||
{0, "chamber_temperature", {95.0f, -10.0f}, 0.0f, getChamberTemperature},
|
||||
{0, "outdoor_temperature", {45.0f, -20.0f}, 0.0f, getOutdoorTemperature},
|
||||
{0, "inlet_flow_temperature", {95.0f, -10.0f}, 0.0f, getInletFlowTemperature},
|
||||
{0, "return_flow_temperature", {95.0f, -10.0f}, 0.0f, getReturnFlowTemperature}};
|
||||
|
||||
void taskSafety(void *pvParameters);
|
||||
void checkSensorSanity(void);
|
||||
@ -67,33 +57,41 @@ void taskSafety(void *pvParameters)
|
||||
|
||||
void checkSensorSanity(void)
|
||||
{
|
||||
static float fChamperTemperatureLast;
|
||||
static float fOutdoorTemperatureLast;
|
||||
static float fInletFlowTemperatureLast;
|
||||
static float fReturnFlowTemperatureLast;
|
||||
|
||||
const float fChamperTemperatureCurrent = getChamberTemperature(CURRENT);
|
||||
if (fChamperTemperatureCurrent == fChamperTemperatureLast)
|
||||
for (int i = 0; i < NUMBER_OF_SENSOR_SANITY_CHECKS; i++)
|
||||
{
|
||||
ESP_LOGE(TAG, "Champer Temperature Sensor reported unchanged value!");
|
||||
//printf("Check sanity of sensor %s:\n", sanityChecks[i].name);
|
||||
//printf(" Status: %u\n", sanityChecks[i].status);
|
||||
//printf(" Sensor Limits: Max = %.2f, Min = %.2f\n", sanityChecks[i].sSensorLimit.max, sanityChecks[i].sSensorLimit.min);
|
||||
//printf(" Last Sensor Temperature: %.2f\n", sanityChecks[i].fSensorTemperatureLast);
|
||||
|
||||
const float fSensorTemperatureCurrent = sanityChecks[i].getSensor(CURRENT);
|
||||
if (fSensorTemperatureCurrent == sanityChecks[i].fSensorTemperatureLast)
|
||||
{
|
||||
ESP_LOGE(TAG, "%s Sensor reported unchanged value! %lf == %lf",sanityChecks[i].name, fSensorTemperatureCurrent, sanityChecks[i].fSensorTemperatureLast);
|
||||
sanityChecks[i].status = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
fChamperTemperatureLast = fChamperTemperatureCurrent;
|
||||
sanityChecks[i].fSensorTemperatureLast = fSensorTemperatureCurrent;
|
||||
|
||||
if (fChamperTemperatureCurrent > sChamperTemperatureLimit.max)
|
||||
if (fSensorTemperatureCurrent > sanityChecks[i].sSensorLimit.max)
|
||||
{
|
||||
ESP_LOGE(TAG, "Champer Temperature Sensor reported too high value!");
|
||||
ESP_LOGE(TAG, "%s Sensor reported too high value! %lf > %lf", sanityChecks[i].name, fSensorTemperatureCurrent, sanityChecks[i].sSensorLimit.max);
|
||||
sanityChecks[i].status = 1;
|
||||
}
|
||||
else if (fChamperTemperatureCurrent < sChamperTemperatureLimit.min)
|
||||
else if (fSensorTemperatureCurrent < sanityChecks[i].sSensorLimit.min)
|
||||
{
|
||||
ESP_LOGE(TAG, "Champer Temperature Sensor reported too low value!");
|
||||
ESP_LOGE(TAG, "%s Sensor reported too low value! %lf < %lf", sanityChecks[i].name, fSensorTemperatureCurrent, sanityChecks[i].sSensorLimit.min);
|
||||
sanityChecks[i].status = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// everything ok
|
||||
sanityChecks[i].status = 0;
|
||||
}
|
||||
}
|
||||
//printf(" Status: %u\n", sanityChecks[i].status);
|
||||
}
|
||||
}
|
||||
|
||||
void setSafeState(void)
|
||||
@ -102,7 +100,9 @@ void setSafeState(void)
|
||||
setBurnerState(DISABLED);
|
||||
}
|
||||
|
||||
/*
|
||||
sSafetyStateElement *getSafetyStates(void)
|
||||
{
|
||||
return safetyStates;
|
||||
}
|
||||
*/
|
@ -1,14 +1,26 @@
|
||||
#pragma once
|
||||
|
||||
#include "outputs.h"
|
||||
#include "inputs.h"
|
||||
|
||||
#define MAX_ERROR_STRING_SIZE 64U
|
||||
#define NUMBER_OF_ERROR_STATES 4U
|
||||
#define NUMBER_OF_SENSOR_SANITY_CHECKS 4U
|
||||
|
||||
typedef struct _SafetyStateElement{
|
||||
typedef float (*GetSensorValue)(eMeasurementMode);
|
||||
typedef struct _TemperatureSensorLimit
|
||||
{
|
||||
float max; // Maximum temperature limit
|
||||
float min; // Minimum temperature limit
|
||||
} sTemperatureSensorLimit;
|
||||
typedef struct _SensorSanityCheck
|
||||
{
|
||||
unsigned int status;
|
||||
char name[MAX_ERROR_STRING_SIZE];
|
||||
} sSafetyStateElement;
|
||||
sTemperatureSensorLimit sSensorLimit;
|
||||
float fSensorTemperatureLast;
|
||||
GetSensorValue getSensor;
|
||||
} sSensorSanityCheck;
|
||||
|
||||
void initSafety(void);
|
||||
|
||||
sSafetyStateElement* getSafetyStates(void);
|
||||
//sSensorSanityCheck *getSafetyStates(void);
|
Loading…
Reference in New Issue
Block a user