7 Commits

Author SHA256 Message Date
a72c0673b1 Improve efficiency (#21)
- Change to new One Wire Sensors that are no fakes
- Increase chamber temperature

Reviewed-on: #21
Co-authored-by: localhorst <localhorst@mosad.xyz>
Co-committed-by: localhorst <localhorst@mosad.xyz>
2025-02-08 20:05:14 +01:00
999af9d888 Merge pull request 'bugfix/linear-regression-prediction' (#19) from bugfix/linear-regression-prediction into main
Reviewed-on: #19
2024-12-26 22:47:35 +01:00
8a8bcd078b disable log 2024-12-26 22:47:12 +01:00
59b8c3e2b2 revert lab setup 2024-12-26 22:46:30 +01:00
06c6612ef6 fix algo 2024-12-26 22:40:20 +01:00
e790660c36 Merge branch 'main' into testing/lab-temperature-sensor 2024-12-26 22:19:41 +01:00
b21dc720ed use lab single sensor 2024-12-26 20:00:37 +01:00
2 changed files with 16 additions and 12 deletions

View File

@ -12,7 +12,7 @@
#define RETURN_FLOW_TEMPERATURE_LOWER_LIMIT_DAY 30.0
#define RETURN_FLOW_TEMPERATURE_LOWER_LIMIT_NIGHT 25.0
#define CHAMPER_TEMPERATURE_TARGET 70.0
#define CHAMPER_TEMPERATURE_TARGET 80.0
#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";
@ -98,7 +98,7 @@ void taskControl(void *pvParameters)
if (bHeatingInAction == true)
{
if (getChamberTemperature().fCurrentValue >= currentControlEntry.fChamberTemperature)
if ((getChamberTemperature().fCurrentValue >= currentControlEntry.fChamberTemperature) || (getChamberTemperature().predict60s.fValue >= currentControlEntry.fChamberTemperature))
{
ESP_LOGI(TAG, "Chamber Target Temperature reached: Disable burner");
bHeatingInAction = false;

View File

@ -16,10 +16,10 @@ static const char *TAG = "smart-oil-heater-control-system-inputs";
const uint8_t uBurnerFaultPin = 19U;
const uint8_t uDS18B20Pin = 4U;
const onewire_addr_t uChamperTempSensorAddr = 0x3e0000001754be28;
const onewire_addr_t uOutdoorTempSensorAddr = 0x880000001648e328;
const onewire_addr_t uInletFlowTempSensorAddr = 0xe59cdef51e64ff28;
const onewire_addr_t uReturnFlowTempSensorAddr = 0xa7a8e1531f64ff28;
const onewire_addr_t uChamperTempSensorAddr = 0xd00000108cd01d28;
const onewire_addr_t uOutdoorTempSensorAddr = 0x78000000c6c2f728;
const onewire_addr_t uInletFlowTempSensorAddr = 0x410000108b8c0628;
const onewire_addr_t uReturnFlowTempSensorAddr = 0x90000108cc77c28;
onewire_addr_t uOneWireAddresses[MAX_DN18B20_SENSORS];
float fDS18B20Temps[MAX_DN18B20_SENSORS];
@ -36,7 +36,7 @@ void taskInput(void *pvParameters);
void initMeasurement(sMeasurement *pMeasurement);
void updateAverage(sMeasurement *pMeasurement);
void updatePrediction(sMeasurement *pMeasurement);
float linearRegressionPredict(const float *samples, size_t count, float futureIndex);
float linearRegressionPredict(const float *samples, size_t count, size_t bufferIndex, float futureIndex);
void initInputs(void)
{
@ -162,6 +162,7 @@ void updatePrediction(sMeasurement *pMeasurement)
predict60s->fValue = linearRegressionPredict(
predict60s->samples,
predict60s->bufferCount,
predict60s->bufferIndex,
predict60s->bufferCount + 60.0f);
}
@ -267,7 +268,7 @@ void taskInput(void *pvParameters)
}
}
float linearRegressionPredict(const float *samples, size_t count, float futureIndex)
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
@ -276,8 +277,11 @@ float linearRegressionPredict(const float *samples, size_t count, float futureIn
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 y = samples[i]; // Sample value
float y = samples[circularIndex]; // Sample value
sumX += x;
sumY += y;
@ -288,7 +292,7 @@ float linearRegressionPredict(const float *samples, size_t count, float futureIn
// Calculate slope (m) and intercept (b) of the line: y = mx + b
float denominator = (count * sumX2 - sumX * sumX);
if (fabs(denominator) < 1e-6) // Avoid division by zero
return samples[count - 1]; // Return last value as prediction
return samples[bufferIndex]; // Return the latest value as prediction
float m = (count * sumXY - sumX * sumY) / denominator;
float b = (sumY - m * sumX) / count;