chamber temp prediction metrics
This commit is contained in:
parent
59eb361431
commit
655d890a0f
@ -1,6 +1,7 @@
|
|||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "freertos/task.h"
|
#include "freertos/task.h"
|
||||||
#include "driver/gpio.h"
|
#include "driver/gpio.h"
|
||||||
|
#include <string.h>
|
||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
#include <ds18x20.h>
|
#include <ds18x20.h>
|
||||||
|
|
||||||
@ -31,6 +32,7 @@ static sMeasurement sInletFlowTemperature;
|
|||||||
static sMeasurement sReturnFlowTemperature;
|
static sMeasurement sReturnFlowTemperature;
|
||||||
|
|
||||||
void taskInput(void *pvParameters);
|
void taskInput(void *pvParameters);
|
||||||
|
void initMeasurement(sMeasurement *pMeasurement);
|
||||||
void updateAverage(sMeasurement *pMeasurement);
|
void updateAverage(sMeasurement *pMeasurement);
|
||||||
void updatePrediction(sMeasurement *pMeasurement);
|
void updatePrediction(sMeasurement *pMeasurement);
|
||||||
|
|
||||||
@ -54,6 +56,11 @@ void initInputs(void)
|
|||||||
}
|
}
|
||||||
xSemaphoreGiveRecursive(xMutexAccessInputs);
|
xSemaphoreGiveRecursive(xMutexAccessInputs);
|
||||||
|
|
||||||
|
initMeasurement(&sChamperTemperature);
|
||||||
|
initMeasurement(&sOutdoorTemperature);
|
||||||
|
initMeasurement(&sInletFlowTemperature);
|
||||||
|
initMeasurement(&sReturnFlowTemperature);
|
||||||
|
|
||||||
BaseType_t taskCreated = xTaskCreate(
|
BaseType_t taskCreated = xTaskCreate(
|
||||||
taskInput, // Function to implement the task
|
taskInput, // Function to implement the task
|
||||||
"taskInput", // Task name
|
"taskInput", // Task name
|
||||||
@ -73,6 +80,32 @@ void initInputs(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void initMeasurement(sMeasurement *pMeasurement)
|
||||||
|
{
|
||||||
|
pMeasurement->state = MEASUREMENT_FAULT;
|
||||||
|
pMeasurement->fCurrentValue = 0.0f;
|
||||||
|
|
||||||
|
pMeasurement->average10s.fValue = 0.0f;
|
||||||
|
pMeasurement->average10s.bufferCount = 0U;
|
||||||
|
pMeasurement->average10s.bufferIndex = 0U;
|
||||||
|
memset(pMeasurement->average10s.samples, 0U, AVG10_SAMPLE_SIZE);
|
||||||
|
|
||||||
|
pMeasurement->average60s.fValue = 0.0f;
|
||||||
|
pMeasurement->average60s.bufferCount = 0U;
|
||||||
|
pMeasurement->average60s.bufferIndex = 0U;
|
||||||
|
memset(pMeasurement->average60s.samples, 0U, AVG60_SAMPLE_SIZE);
|
||||||
|
|
||||||
|
pMeasurement->predict10s.fValue = 0.0f;
|
||||||
|
pMeasurement->predict10s.bufferCount = 0U;
|
||||||
|
pMeasurement->predict10s.bufferIndex = 0U;
|
||||||
|
memset(pMeasurement->predict10s.samples, 0U, PRED10_SAMPLE_SIZE);
|
||||||
|
|
||||||
|
pMeasurement->predict60s.fValue = 0.0f;
|
||||||
|
pMeasurement->predict60s.bufferCount = 0U;
|
||||||
|
pMeasurement->predict60s.bufferIndex = 0U;
|
||||||
|
memset(pMeasurement->predict60s.samples, 0U, PRED60_SAMPLE_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
void updateAverage(sMeasurement *pMeasurement)
|
void updateAverage(sMeasurement *pMeasurement)
|
||||||
{ /* Average form the last 10sec */
|
{ /* Average form the last 10sec */
|
||||||
pMeasurement->average10s.samples[pMeasurement->average10s.bufferIndex] = pMeasurement->fCurrentValue;
|
pMeasurement->average10s.samples[pMeasurement->average10s.bufferIndex] = pMeasurement->fCurrentValue;
|
||||||
@ -124,10 +157,25 @@ void updatePrediction(sMeasurement *pMeasurement)
|
|||||||
pMeasurement->predict10s.bufferCount++;
|
pMeasurement->predict10s.bufferCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
float delta = pMeasurement->predict10s.samples[(pMeasurement->predict10s.bufferIndex - 1) % PRED10_SAMPLE_SIZE] - pMeasurement->predict10s.samples[pMeasurement->predict10s.bufferIndex];
|
float delta10s = pMeasurement->predict10s.samples[(pMeasurement->predict10s.bufferIndex - 1) % PRED10_SAMPLE_SIZE] - pMeasurement->predict10s.samples[pMeasurement->predict10s.bufferIndex];
|
||||||
if (delta != 0.0)
|
if (delta10s != 0.0)
|
||||||
{
|
{
|
||||||
pMeasurement->predict10s.fValue = pMeasurement->fCurrentValue + (delta * pMeasurement->predict10s.bufferCount);
|
pMeasurement->predict10s.fValue = pMeasurement->fCurrentValue + (delta10s * pMeasurement->predict10s.bufferCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Prediction of the value in 60sec */
|
||||||
|
pMeasurement->predict60s.samples[pMeasurement->predict60s.bufferIndex] = pMeasurement->fCurrentValue;
|
||||||
|
pMeasurement->predict60s.bufferIndex = (pMeasurement->predict60s.bufferIndex + 1) % PRED60_SAMPLE_SIZE;
|
||||||
|
|
||||||
|
if (pMeasurement->predict60s.bufferCount < PRED60_SAMPLE_SIZE)
|
||||||
|
{
|
||||||
|
pMeasurement->predict60s.bufferCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
float delta60s = pMeasurement->predict60s.samples[(pMeasurement->predict60s.bufferIndex - 1) % PRED60_SAMPLE_SIZE] - pMeasurement->predict60s.samples[pMeasurement->predict60s.bufferIndex];
|
||||||
|
if (delta60s != 0.0)
|
||||||
|
{
|
||||||
|
pMeasurement->predict60s.fValue = pMeasurement->fCurrentValue + (delta60s * pMeasurement->predict60s.bufferCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user