damping instead of 24h average

This commit is contained in:
2025-10-18 20:39:36 +02:00
parent 9ff3b38f70
commit b3a571da3f
3 changed files with 40 additions and 49 deletions

View File

@ -88,26 +88,20 @@ void initMeasurement(sMeasurement *pMeasurement)
return;
pMeasurement->state = MEASUREMENT_FAULT;
pMeasurement->fCurrentValue = 0.0f;
pMeasurement->fCurrentValue = INITIALISATION_VALUE;
pMeasurement->fDampedValue = INITIALISATION_VALUE;
pMeasurement->average10s.fValue = 0.0f;
pMeasurement->average10s.fValue = INITIALISATION_VALUE;
pMeasurement->average10s.bufferCount = 0U;
pMeasurement->average10s.bufferIndex = 0U;
memset(pMeasurement->average10s.samples, 0U, AVG10S_SAMPLE_SIZE);
pMeasurement->average60s.fValue = 0.0f;
pMeasurement->average60s.fValue = INITIALISATION_VALUE;
pMeasurement->average60s.bufferCount = 0U;
pMeasurement->average60s.bufferIndex = 0U;
memset(pMeasurement->average60s.samples, 0U, AVG60S_SAMPLE_SIZE);
/*
pMeasurement->average24h.fValue = 0.0f;
pMeasurement->average24h.bufferCount = 0U;
pMeasurement->average24h.bufferIndex = 0U;
memset(pMeasurement->average24h.samples, 0U, AVG24H_SAMPLE_SIZE);
*/
pMeasurement->predict60s.fValue = 0.0f;
pMeasurement->predict60s.fValue = INITIALISATION_VALUE;
pMeasurement->predict60s.bufferCount = 0U;
pMeasurement->predict60s.bufferIndex = 0U;
memset(pMeasurement->predict60s.samples, 0U, PRED60S_SAMPLE_SIZE);
@ -152,24 +146,22 @@ void updateAverage(sMeasurement *pMeasurement)
pMeasurement->average60s.fValue = sum / pMeasurement->average60s.bufferCount;
// Average form the last 24h
/*
pMeasurement->average24h.samples[pMeasurement->average24h.bufferIndex] = pMeasurement->fCurrentValue;
pMeasurement->average24h.bufferIndex = (pMeasurement->average24h.bufferIndex + 1) % AVG24H_SAMPLE_SIZE;
if (pMeasurement->average24h.bufferCount < AVG24H_SAMPLE_SIZE)
// Damped current value
if (pMeasurement->fDampedValue == INITIALISATION_VALUE)
{
pMeasurement->average24h.bufferCount++;
pMeasurement->fDampedValue = pMeasurement->fCurrentValue;
}
sum = 0.0;
for (int i = 0; i <= pMeasurement->average24h.bufferCount; i++)
else
{
sum += pMeasurement->average24h.samples[i];
if (pMeasurement->fCurrentValue > pMeasurement->fDampedValue)
{
pMeasurement->fDampedValue = pMeasurement->fDampedValue + (DAMPING_FACTOR * (pMeasurement->fCurrentValue - pMeasurement->fDampedValue));
}
else
{
pMeasurement->fDampedValue = pMeasurement->fDampedValue - (DAMPING_FACTOR * (pMeasurement->fDampedValue - pMeasurement->fCurrentValue));
}
}
pMeasurement->average24h.fValue = sum / pMeasurement->average24h.bufferCount;
*/
}
void updatePrediction(sMeasurement *pMeasurement)
@ -297,9 +289,9 @@ void taskInput(void *pvParameters)
float linearRegressionPredict(const float *samples, size_t count, size_t bufferIndex, float futureIndex)
{
if (count == 0)
return 0.0f; // No prediction possible with no data
return INITIALISATION_VALUE; // No prediction possible with no data
float sumX = 0.0f, sumY = 0.0f, sumXY = 0.0f, sumX2 = 0.0f;
float sumX = INITIALISATION_VALUE, sumY = INITIALISATION_VALUE, sumXY = INITIALISATION_VALUE, sumX2 = INITIALISATION_VALUE;
for (size_t i = 0; i < count; i++)
{

View File

@ -1,10 +1,12 @@
#pragma once
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define INITIALISATION_VALUE 0.0f
#define AVG10S_SAMPLE_SIZE 10U
#define AVG60S_SAMPLE_SIZE 60U
#define AVG24H_SAMPLE_SIZE 60U // * 60U * 24U
#define AVG24H_SAMPLE_SIZE 24U
#define PRED60S_SAMPLE_SIZE 60U
#define DAMPING_FACTOR 0.01f
typedef enum _BurnerErrorState
{
@ -37,9 +39,9 @@ typedef struct _Predict
typedef struct _Measurement
{
float fCurrentValue;
float fDampedValue;
sAverage average10s;
sAverage average60s;
// sAverage average24h;
sPredict predict60s;
eMeasurementErrorState state;
} sMeasurement;

View File

@ -128,12 +128,11 @@ void taskMetrics(void *pvParameters)
aMetrics[u16MetricCounter].fMetricValue = getChamberTemperature().average60s.fValue;
u16MetricCounter++;
// Chamber Temperature Average 24h
/*
strcpy(aMetrics[u16MetricCounter].caMetricName, "chamber_temperature_avg24h");
// Chamber Temperature Damped
strcpy(aMetrics[u16MetricCounter].caMetricName, "chamber_temperature_damped");
aMetrics[u16MetricCounter].type = FLOAT;
aMetrics[u16MetricCounter].fMetricValue = getChamberTemperature().average24h.fValue;
u16MetricCounter++;*/
aMetrics[u16MetricCounter].fMetricValue = getChamberTemperature().fDampedValue;
u16MetricCounter++;
// Chamber Temperature Predict 60s
strcpy(aMetrics[u16MetricCounter].caMetricName, "chamber_temperature_pred60");
@ -159,12 +158,11 @@ void taskMetrics(void *pvParameters)
aMetrics[u16MetricCounter].fMetricValue = getInletFlowTemperature().average60s.fValue;
u16MetricCounter++;
// Inlet Flow Temperature Average 24h
/*
strcpy(aMetrics[u16MetricCounter].caMetricName, "inlet_flow_temperature_avg24h");
// Inlet Flow Temperature Damped
strcpy(aMetrics[u16MetricCounter].caMetricName, "inlet_flow_temperature_damped");
aMetrics[u16MetricCounter].type = FLOAT;
aMetrics[u16MetricCounter].fMetricValue = getInletFlowTemperature().average24h.fValue;
u16MetricCounter++;*/
aMetrics[u16MetricCounter].fMetricValue = getInletFlowTemperature().fDampedValue;
u16MetricCounter++;
// Inlet Flow Temperature Predict 60s
strcpy(aMetrics[u16MetricCounter].caMetricName, "inlet_flow_temperature_pred60");
@ -190,13 +188,12 @@ void taskMetrics(void *pvParameters)
aMetrics[u16MetricCounter].fMetricValue = getOutdoorTemperature().average60s.fValue;
u16MetricCounter++;
// Outdoor Temperature Average 24h
/*
strcpy(aMetrics[u16MetricCounter].caMetricName, "outdoor_temperature_avg24h");
// Outdoor Temperature Average Damped
strcpy(aMetrics[u16MetricCounter].caMetricName, "outdoor_temperature_damped");
aMetrics[u16MetricCounter].type = FLOAT;
aMetrics[u16MetricCounter].fMetricValue = getOutdoorTemperature().average24h.fValue;
aMetrics[u16MetricCounter].fMetricValue = getOutdoorTemperature().fDampedValue;
u16MetricCounter++;
*/
// Outdoor Temperature Predict 60s
strcpy(aMetrics[u16MetricCounter].caMetricName, "outdoor_temperature_pred60");
aMetrics[u16MetricCounter].type = FLOAT;
@ -221,12 +218,11 @@ void taskMetrics(void *pvParameters)
aMetrics[u16MetricCounter].fMetricValue = getReturnFlowTemperature().average60s.fValue;
u16MetricCounter++;
// Return Flow Temperature Average 24h
/*
strcpy(aMetrics[u16MetricCounter].caMetricName, "return_flow_temperature_avg24h");
// Return Flow Temperature Damped
strcpy(aMetrics[u16MetricCounter].caMetricName, "return_flow_temperature_damped");
aMetrics[u16MetricCounter].type = FLOAT;
aMetrics[u16MetricCounter].fMetricValue = getReturnFlowTemperature().average24h.fValue;
u16MetricCounter++;*/
aMetrics[u16MetricCounter].fMetricValue = getReturnFlowTemperature().fDampedValue;
u16MetricCounter++;
// Return Flow Temperature Predict 60s
strcpy(aMetrics[u16MetricCounter].caMetricName, "return_flow_temperature_pred60");
@ -286,6 +282,7 @@ void taskMetrics(void *pvParameters)
aMetrics[u16MetricCounter].i64MetricValue = ap.rssi;
u16MetricCounter++;
ESP_ERROR_CHECK(u16MetricCounter > METRIC_MAX_COUNT);
vSetMetrics(aMetrics, u16MetricCounter);
}
}