add prediction for 10s
This commit is contained in:
parent
307278e679
commit
ff16e601fb
@ -32,6 +32,7 @@ static sMeasurement sReturnFlowTemperature;
|
||||
|
||||
void taskInput(void *pvParameters);
|
||||
void updateAverage(sMeasurement *pMeasurement);
|
||||
void updatePrediction(sMeasurement *pMeasurement);
|
||||
|
||||
void initInputs(void)
|
||||
{
|
||||
@ -82,20 +83,15 @@ void updateAverage(sMeasurement *pMeasurement)
|
||||
pMeasurement->average10s.bufferCount++;
|
||||
}
|
||||
|
||||
if (pMeasurement->average10s.bufferCount == 0U)
|
||||
{
|
||||
pMeasurement->average10s.fValue = pMeasurement->fCurrentValue;
|
||||
}
|
||||
|
||||
float sum = 0.0;
|
||||
for (int i = 0; i < pMeasurement->average10s.bufferCount; i++)
|
||||
for (int i = 0; i <= pMeasurement->average10s.bufferCount; i++)
|
||||
{
|
||||
sum += pMeasurement->average10s.samples[i];
|
||||
}
|
||||
|
||||
pMeasurement->average10s.fValue = sum / pMeasurement->average10s.bufferCount;
|
||||
|
||||
/* Average form the last 60sec */
|
||||
/* Average form the last 60sec
|
||||
pMeasurement->average60s.samples[pMeasurement->average60s.bufferIndex] = pMeasurement->fCurrentValue;
|
||||
pMeasurement->average60s.bufferIndex = (pMeasurement->average60s.bufferIndex + 1) % AVG60_SAMPLE_SIZE;
|
||||
|
||||
@ -116,6 +112,31 @@ void updateAverage(sMeasurement *pMeasurement)
|
||||
}
|
||||
|
||||
pMeasurement->average60s.fValue = sum / pMeasurement->average60s.bufferCount;
|
||||
*/
|
||||
}
|
||||
|
||||
void updatePrediction(sMeasurement *pMeasurement)
|
||||
{ /* Prediction of the value in 10sec */
|
||||
pMeasurement->predict10s.samples[pMeasurement->predict10s.bufferIndex] = pMeasurement->fCurrentValue;
|
||||
pMeasurement->predict10s.bufferIndex = (pMeasurement->predict10s.bufferIndex + 1) % PRED10_SAMPLE_SIZE;
|
||||
|
||||
if (pMeasurement->predict10s.bufferCount < PRED10_SAMPLE_SIZE)
|
||||
{
|
||||
pMeasurement->predict10s.bufferCount++;
|
||||
}
|
||||
|
||||
if (pMeasurement->predict10s.bufferCount == 0U)
|
||||
{
|
||||
pMeasurement->predict10s.fValue = pMeasurement->fCurrentValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
float delta = pMeasurement->predict10s.samples[(pMeasurement->predict10s.bufferIndex - 1) % PRED10_SAMPLE_SIZE] - pMeasurement->predict10s.samples[pMeasurement->predict10s.bufferIndex];
|
||||
if (delta != 0.0)
|
||||
{
|
||||
// pMeasurement->predict10s.fValue = pMeasurement->fCurrentValue + (delta * pMeasurement->predict10s.bufferCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void taskInput(void *pvParameters)
|
||||
@ -178,6 +199,7 @@ void taskInput(void *pvParameters)
|
||||
sChamperTemperature.fCurrentValue = temp_c;
|
||||
sChamperTemperature.state = MEASUREMENT_NO_ERROR;
|
||||
updateAverage(&sChamperTemperature);
|
||||
// updatePrediction(&sChamperTemperature);
|
||||
|
||||
sOutdoorTemperature.fCurrentValue = temp_c;
|
||||
sOutdoorTemperature.state = MEASUREMENT_NO_ERROR;
|
||||
|
@ -3,6 +3,8 @@
|
||||
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
||||
#define AVG10_SAMPLE_SIZE 10U
|
||||
#define AVG60_SAMPLE_SIZE 60U
|
||||
#define PRED10_SAMPLE_SIZE 10U
|
||||
#define PRED60_SAMPLE_SIZE 60U
|
||||
|
||||
typedef enum _BurnerErrorState
|
||||
{
|
||||
@ -24,11 +26,21 @@ typedef struct _Average
|
||||
size_t bufferCount;
|
||||
} sAverage;
|
||||
|
||||
typedef struct _Predict
|
||||
{
|
||||
float fValue;
|
||||
float samples[MAX(PRED10_SAMPLE_SIZE, PRED60_SAMPLE_SIZE)];
|
||||
size_t bufferIndex;
|
||||
size_t bufferCount;
|
||||
} sPredict;
|
||||
|
||||
typedef struct _Measurement
|
||||
{
|
||||
float fCurrentValue;
|
||||
sAverage average10s;
|
||||
sAverage average60s;
|
||||
sPredict predict10s;
|
||||
sPredict predict60s;
|
||||
eMeasurementErrorState state;
|
||||
} sMeasurement;
|
||||
|
||||
|
@ -128,6 +128,12 @@ void taskMetrics(void *pvParameters)
|
||||
aMetrics[u16MetricCounter].fMetricValue = getChamberTemperature().average60s.fValue;
|
||||
u16MetricCounter++;
|
||||
|
||||
/*Chamber Temperature Predict 10s*/
|
||||
strcpy(aMetrics[u16MetricCounter].caMetricName, "chamber_temperature_pred10");
|
||||
aMetrics[u16MetricCounter].type = FLOAT;
|
||||
aMetrics[u16MetricCounter].fMetricValue = getChamberTemperature().predict10s.fValue;
|
||||
u16MetricCounter++;
|
||||
|
||||
/*Inlet Flow Temperature*/
|
||||
strcpy(aMetrics[u16MetricCounter].caMetricName, "inlet_flow_temperature");
|
||||
aMetrics[u16MetricCounter].type = FLOAT;
|
||||
|
Loading…
Reference in New Issue
Block a user