Compare commits
No commits in common. "main" and "testing/lab-temperature-sensor" have entirely different histories.
main
...
testing/la
@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
#define RETURN_FLOW_TEMPERATURE_LOWER_LIMIT_DAY 30.0
|
#define RETURN_FLOW_TEMPERATURE_LOWER_LIMIT_DAY 30.0
|
||||||
#define RETURN_FLOW_TEMPERATURE_LOWER_LIMIT_NIGHT 25.0
|
#define RETURN_FLOW_TEMPERATURE_LOWER_LIMIT_NIGHT 25.0
|
||||||
#define CHAMPER_TEMPERATURE_TARGET 80.0
|
#define CHAMPER_TEMPERATURE_TARGET 70.0
|
||||||
#define BURNER_FAULT_DETECTION_THRESHOLD (60U * 3U) // Detect burner fault if after 3 minutes no burner start detected
|
#define BURNER_FAULT_DETECTION_THRESHOLD (60U * 3U) // Detect burner fault if after 3 minutes no burner start detected
|
||||||
|
|
||||||
static const char *TAG = "smart-oil-heater-control-system-control";
|
static const char *TAG = "smart-oil-heater-control-system-control";
|
||||||
@ -98,7 +98,7 @@ void taskControl(void *pvParameters)
|
|||||||
|
|
||||||
if (bHeatingInAction == true)
|
if (bHeatingInAction == true)
|
||||||
{
|
{
|
||||||
if ((getChamberTemperature().fCurrentValue >= currentControlEntry.fChamberTemperature) || (getChamberTemperature().predict60s.fValue >= currentControlEntry.fChamberTemperature))
|
if (getChamberTemperature().fCurrentValue >= currentControlEntry.fChamberTemperature)
|
||||||
{
|
{
|
||||||
ESP_LOGI(TAG, "Chamber Target Temperature reached: Disable burner");
|
ESP_LOGI(TAG, "Chamber Target Temperature reached: Disable burner");
|
||||||
bHeatingInAction = false;
|
bHeatingInAction = false;
|
||||||
|
@ -16,10 +16,10 @@ static const char *TAG = "smart-oil-heater-control-system-inputs";
|
|||||||
const uint8_t uBurnerFaultPin = 19U;
|
const uint8_t uBurnerFaultPin = 19U;
|
||||||
const uint8_t uDS18B20Pin = 4U;
|
const uint8_t uDS18B20Pin = 4U;
|
||||||
|
|
||||||
const onewire_addr_t uChamperTempSensorAddr = 0xd00000108cd01d28;
|
const onewire_addr_t uChamperTempSensorAddr = 0x78000000c6c2f728;
|
||||||
const onewire_addr_t uOutdoorTempSensorAddr = 0x78000000c6c2f728;
|
const onewire_addr_t uOutdoorTempSensorAddr = 0x78000000c6c2f728;
|
||||||
const onewire_addr_t uInletFlowTempSensorAddr = 0x410000108b8c0628;
|
const onewire_addr_t uInletFlowTempSensorAddr = 0x78000000c6c2f728;
|
||||||
const onewire_addr_t uReturnFlowTempSensorAddr = 0x90000108cc77c28;
|
const onewire_addr_t uReturnFlowTempSensorAddr = 0x78000000c6c2f728;
|
||||||
|
|
||||||
onewire_addr_t uOneWireAddresses[MAX_DN18B20_SENSORS];
|
onewire_addr_t uOneWireAddresses[MAX_DN18B20_SENSORS];
|
||||||
float fDS18B20Temps[MAX_DN18B20_SENSORS];
|
float fDS18B20Temps[MAX_DN18B20_SENSORS];
|
||||||
@ -36,7 +36,7 @@ void taskInput(void *pvParameters);
|
|||||||
void initMeasurement(sMeasurement *pMeasurement);
|
void initMeasurement(sMeasurement *pMeasurement);
|
||||||
void updateAverage(sMeasurement *pMeasurement);
|
void updateAverage(sMeasurement *pMeasurement);
|
||||||
void updatePrediction(sMeasurement *pMeasurement);
|
void updatePrediction(sMeasurement *pMeasurement);
|
||||||
float linearRegressionPredict(const float *samples, size_t count, size_t bufferIndex, float futureIndex);
|
float linearRegressionPredict(const float *samples, size_t count, float futureIndex);
|
||||||
|
|
||||||
void initInputs(void)
|
void initInputs(void)
|
||||||
{
|
{
|
||||||
@ -162,7 +162,6 @@ void updatePrediction(sMeasurement *pMeasurement)
|
|||||||
predict60s->fValue = linearRegressionPredict(
|
predict60s->fValue = linearRegressionPredict(
|
||||||
predict60s->samples,
|
predict60s->samples,
|
||||||
predict60s->bufferCount,
|
predict60s->bufferCount,
|
||||||
predict60s->bufferIndex,
|
|
||||||
predict60s->bufferCount + 60.0f);
|
predict60s->bufferCount + 60.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,7 +217,7 @@ void taskInput(void *pvParameters)
|
|||||||
for (int j = 0; j < sSensorCount; j++)
|
for (int j = 0; j < sSensorCount; j++)
|
||||||
{
|
{
|
||||||
float temp_c = fDS18B20Temps[j];
|
float temp_c = fDS18B20Temps[j];
|
||||||
// ESP_LOGI(TAG, "Sensor: %08" PRIx64 " reports %lf°C", (uint64_t)uOneWireAddresses[j], temp_c);
|
ESP_LOGI(TAG, "Sensor: %08" PRIx64 " reports %lf°C", (uint64_t)uOneWireAddresses[j], temp_c);
|
||||||
|
|
||||||
switch ((uint64_t)uOneWireAddresses[j])
|
switch ((uint64_t)uOneWireAddresses[j])
|
||||||
{
|
{
|
||||||
@ -227,20 +226,17 @@ void taskInput(void *pvParameters)
|
|||||||
sChamperTemperature.state = MEASUREMENT_NO_ERROR;
|
sChamperTemperature.state = MEASUREMENT_NO_ERROR;
|
||||||
updateAverage(&sChamperTemperature);
|
updateAverage(&sChamperTemperature);
|
||||||
updatePrediction(&sChamperTemperature);
|
updatePrediction(&sChamperTemperature);
|
||||||
break;
|
|
||||||
case ((uint64_t)uOutdoorTempSensorAddr):
|
|
||||||
sOutdoorTemperature.fCurrentValue = temp_c;
|
sOutdoorTemperature.fCurrentValue = temp_c;
|
||||||
sOutdoorTemperature.state = MEASUREMENT_NO_ERROR;
|
sOutdoorTemperature.state = MEASUREMENT_NO_ERROR;
|
||||||
updateAverage(&sOutdoorTemperature);
|
updateAverage(&sOutdoorTemperature);
|
||||||
updatePrediction(&sOutdoorTemperature);
|
updatePrediction(&sOutdoorTemperature);
|
||||||
break;
|
|
||||||
case ((uint64_t)uInletFlowTempSensorAddr):
|
|
||||||
sInletFlowTemperature.fCurrentValue = temp_c;
|
sInletFlowTemperature.fCurrentValue = temp_c;
|
||||||
sInletFlowTemperature.state = MEASUREMENT_NO_ERROR;
|
sInletFlowTemperature.state = MEASUREMENT_NO_ERROR;
|
||||||
updateAverage(&sInletFlowTemperature);
|
updateAverage(&sInletFlowTemperature);
|
||||||
updatePrediction(&sInletFlowTemperature);
|
updatePrediction(&sInletFlowTemperature);
|
||||||
break;
|
|
||||||
case ((uint64_t)uReturnFlowTempSensorAddr):
|
|
||||||
sReturnFlowTemperature.fCurrentValue = temp_c;
|
sReturnFlowTemperature.fCurrentValue = temp_c;
|
||||||
sReturnFlowTemperature.state = MEASUREMENT_NO_ERROR;
|
sReturnFlowTemperature.state = MEASUREMENT_NO_ERROR;
|
||||||
updateAverage(&sReturnFlowTemperature);
|
updateAverage(&sReturnFlowTemperature);
|
||||||
@ -268,7 +264,7 @@ void taskInput(void *pvParameters)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float linearRegressionPredict(const float *samples, size_t count, size_t bufferIndex, float futureIndex)
|
float linearRegressionPredict(const float *samples, size_t count, float futureIndex)
|
||||||
{
|
{
|
||||||
if (count == 0)
|
if (count == 0)
|
||||||
return 0.0f; // No prediction possible with no data
|
return 0.0f; // No prediction possible with no data
|
||||||
@ -277,11 +273,8 @@ float linearRegressionPredict(const float *samples, size_t count, size_t bufferI
|
|||||||
|
|
||||||
for (size_t i = 0; i < count; i++)
|
for (size_t i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
// Calculate the circular buffer index for the current sample
|
|
||||||
size_t circularIndex = (bufferIndex + i + 1) % count;
|
|
||||||
|
|
||||||
float x = (float)i; // Time index
|
float x = (float)i; // Time index
|
||||||
float y = samples[circularIndex]; // Sample value
|
float y = samples[i]; // Sample value
|
||||||
|
|
||||||
sumX += x;
|
sumX += x;
|
||||||
sumY += y;
|
sumY += y;
|
||||||
@ -292,7 +285,7 @@ float linearRegressionPredict(const float *samples, size_t count, size_t bufferI
|
|||||||
// Calculate slope (m) and intercept (b) of the line: y = mx + b
|
// Calculate slope (m) and intercept (b) of the line: y = mx + b
|
||||||
float denominator = (count * sumX2 - sumX * sumX);
|
float denominator = (count * sumX2 - sumX * sumX);
|
||||||
if (fabs(denominator) < 1e-6) // Avoid division by zero
|
if (fabs(denominator) < 1e-6) // Avoid division by zero
|
||||||
return samples[bufferIndex]; // Return the latest value as prediction
|
return samples[count - 1]; // Return last value as prediction
|
||||||
|
|
||||||
float m = (count * sumXY - sumX * sumY) / denominator;
|
float m = (count * sumXY - sumX * sumY) / denominator;
|
||||||
float b = (sumY - m * sumX) / count;
|
float b = (sumY - m * sumX) / count;
|
||||||
|
Loading…
Reference in New Issue
Block a user