logging pid-parameters too
This commit is contained in:
parent
3ca74503d9
commit
be49cd9123
@ -31,7 +31,7 @@ private:
|
|||||||
|
|
||||||
Entry *bufferWrite = buffer;
|
Entry *bufferWrite = buffer;
|
||||||
|
|
||||||
size_t dataCount = 0;
|
size_t usage = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -41,18 +41,18 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool add(const time_t timestamp, const T &data) {
|
bool add(const time_t timestamp, const T &data) {
|
||||||
if (dataCount >= size) {
|
if (usage >= size) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
bufferWrite->timestamp = timestamp;
|
bufferWrite->timestamp = timestamp;
|
||||||
bufferWrite->data = data;
|
bufferWrite->data = data;
|
||||||
bufferWrite = (bufferWrite - buffer + 1) % size + buffer;
|
bufferWrite = (bufferWrite - buffer + 1) % size + buffer;
|
||||||
dataCount++;
|
usage++;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
if (dataCount == 0 || !isTimeSet()) {
|
if (usage == 0 || !isTimeSet()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
JsonDocument json;
|
JsonDocument json;
|
||||||
@ -61,10 +61,18 @@ public:
|
|||||||
bufferRead->data.toJson(data);
|
bufferRead->data.toJson(data);
|
||||||
if (mqttPublishData(name, json)) {
|
if (mqttPublishData(name, json)) {
|
||||||
bufferRead = (bufferRead - buffer + 1) % size + buffer;
|
bufferRead = (bufferRead - buffer + 1) % size + buffer;
|
||||||
dataCount--;
|
usage--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t getUsage() const {
|
||||||
|
return usage;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t getSize() const {
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -15,8 +15,6 @@ private:
|
|||||||
|
|
||||||
uint64_t address;
|
uint64_t address;
|
||||||
|
|
||||||
const char *name;
|
|
||||||
|
|
||||||
const double valueThreshold;
|
const double valueThreshold;
|
||||||
|
|
||||||
const time_t timeoutSec;
|
const time_t timeoutSec;
|
||||||
@ -37,10 +35,9 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
DallasSensor(Dallas &sensors, const uint64_t address, const char *name, const double valueThreshold, const time_t timeoutSec, const time_t minIntervalMillis) :
|
DallasSensor(Dallas &sensors, const uint64_t address, const double valueThreshold, const time_t timeoutSec, const time_t minIntervalMillis) :
|
||||||
sensors(sensors),
|
sensors(sensors),
|
||||||
address(address),
|
address(address),
|
||||||
name(name),
|
|
||||||
valueThreshold(valueThreshold),
|
valueThreshold(valueThreshold),
|
||||||
timeoutSec(timeoutSec),
|
timeoutSec(timeoutSec),
|
||||||
minIntervalMillis(minIntervalMillis) {
|
minIntervalMillis(minIntervalMillis) {
|
||||||
@ -73,10 +70,6 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] const char *getName() const {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
[[nodiscard]] double getLastValue() const {
|
[[nodiscard]] double getLastValue() const {
|
||||||
return lastValue;
|
return lastValue;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
#if defined(FERMENTER)
|
#if defined(FERMENTER) || defined(TEST8266)
|
||||||
|
|
||||||
#include <Patrix.h>
|
#include <Patrix.h>
|
||||||
#include "sensors/Dallas.h"
|
#include "sensors/Dallas.h"
|
||||||
@ -8,26 +8,27 @@
|
|||||||
#include "console.h"
|
#include "console.h"
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include "LedControl.h"
|
#include "LedControl.h"
|
||||||
|
#include "FermenterData.h"
|
||||||
|
|
||||||
#define SENSOR_GPIO D4
|
#define SENSOR_GPIO D4
|
||||||
#define CONTROL_GPIO D2
|
#define CONTROL_GPIO D2
|
||||||
#define CONTROL_PWM_BITS 10
|
#define CONTROL_PWM_BITS 10
|
||||||
#define CONTROL_PWM_MAX (pow(2, CONTROL_PWM_BITS) - 1)
|
#define CONTROL_PWM_MAX (pow(2, CONTROL_PWM_BITS) - 1)
|
||||||
|
|
||||||
#define PID_DEFAULT_P 100
|
#define PID_DEFAULT_P 1500
|
||||||
#define PID_DEFAULT_I 10
|
#define PID_DEFAULT_I 0
|
||||||
#define PID_DEFAULT_D 0
|
#define PID_DEFAULT_D 0
|
||||||
#define PID_DEFAULT_TARGET 31
|
#define PID_DEFAULT_TARGET 31
|
||||||
#define PID_DEFAULT_OVER 5
|
#define PID_DEFAULT_OVER 5
|
||||||
|
|
||||||
Dallas dallas(SENSOR_GPIO);
|
Dallas dallas(SENSOR_GPIO);
|
||||||
|
|
||||||
DallasSensor sensor(dallas, 0x3D0417C1D740FF28, "temperatur.ist", 0.1, 5, 60 * 1000);
|
DallasSensor sensor(dallas, 0x3D0417C1D740FF28, 0.1, 5, 60 * 1000);
|
||||||
|
|
||||||
ArduPID pid;
|
|
||||||
|
|
||||||
LedControl lc = LedControl(13, 14, 15, 1);
|
LedControl lc = LedControl(13, 14, 15, 1);
|
||||||
|
|
||||||
|
ArduPID pid;
|
||||||
|
|
||||||
double proportional = PID_DEFAULT_P;
|
double proportional = PID_DEFAULT_P;
|
||||||
|
|
||||||
double integral = PID_DEFAULT_I;
|
double integral = PID_DEFAULT_I;
|
||||||
@ -42,41 +43,14 @@ double temperatureCurrent = NAN;
|
|||||||
|
|
||||||
double heaterPWM = 0;
|
double heaterPWM = 0;
|
||||||
|
|
||||||
struct Data : IData {
|
Cache<FermenterData, 500> cache("data");
|
||||||
double temperature;
|
|
||||||
double target;
|
|
||||||
double p;
|
|
||||||
double i;
|
|
||||||
double d;
|
|
||||||
|
|
||||||
Data() {
|
|
||||||
temperature = NAN;
|
|
||||||
target = NAN;
|
|
||||||
p = NAN;
|
|
||||||
i = NAN;
|
|
||||||
d = NAN;
|
|
||||||
}
|
|
||||||
|
|
||||||
Data(double temperature, double target, double p, double i, double d) : temperature(temperature), target(target), p(p), i(i), d(d) {
|
|
||||||
// -
|
|
||||||
}
|
|
||||||
|
|
||||||
void toJson(JsonObject &json) const override {
|
|
||||||
json["temperature"] = temperature;
|
|
||||||
json["target"] = target;
|
|
||||||
json["p"] = p;
|
|
||||||
json["i"] = i;
|
|
||||||
json["d"] = d;
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
Cache<Data, 500> cache("data");
|
|
||||||
|
|
||||||
void writeDecimal(int *digit, double value);
|
void writeDecimal(int *digit, double value);
|
||||||
|
|
||||||
void displayLoop();
|
void displayLoop();
|
||||||
|
|
||||||
|
void pidLoop();
|
||||||
|
|
||||||
void patrixSetup() {
|
void patrixSetup() {
|
||||||
dallas.begin();
|
dallas.begin();
|
||||||
analogWriteResolution(CONTROL_PWM_BITS);
|
analogWriteResolution(CONTROL_PWM_BITS);
|
||||||
@ -90,21 +64,16 @@ void patrixSetup() {
|
|||||||
|
|
||||||
void patrixLoop() {
|
void patrixLoop() {
|
||||||
dallas.loop();
|
dallas.loop();
|
||||||
|
|
||||||
if (sensor.loop()) {
|
if (sensor.loop()) {
|
||||||
Data data = {
|
const FermenterData data = {sensor.getLastValue(), temperatureTarget, proportional, integral, derivative};
|
||||||
temperatureCurrent,
|
|
||||||
temperatureTarget,
|
|
||||||
proportional,
|
|
||||||
integral,
|
|
||||||
derivative,
|
|
||||||
};
|
|
||||||
cache.add(sensor.getLastTimestamp(), data);
|
cache.add(sensor.getLastTimestamp(), data);
|
||||||
}
|
}
|
||||||
cache.loop();
|
cache.loop();
|
||||||
|
|
||||||
displayLoop();
|
displayLoop();
|
||||||
|
pidLoop();
|
||||||
|
}
|
||||||
|
|
||||||
|
void pidLoop() {
|
||||||
temperatureCurrent = sensor.getLastValue();
|
temperatureCurrent = sensor.getLastValue();
|
||||||
if (!isnan(temperatureCurrent)) {
|
if (!isnan(temperatureCurrent)) {
|
||||||
pid.compute();
|
pid.compute();
|
||||||
@ -126,7 +95,10 @@ void patrixLoop() {
|
|||||||
lastDebug = now;
|
lastDebug = now;
|
||||||
int heaterPercent = (int) round(100.0 * heaterPWM / CONTROL_PWM_MAX);
|
int heaterPercent = (int) round(100.0 * heaterPWM / CONTROL_PWM_MAX);
|
||||||
debug(
|
debug(
|
||||||
"p: %f | i: %f | d: %f | t: %4.1f | %3d%% | %5.2f %s",
|
"cache: %3d/%d | p: %f | i: %f | d: %f | target: %4.1f | heater: %3d%% | temperature: %5.2f %s",
|
||||||
|
cache.getUsage(),
|
||||||
|
cache.getSize(),
|
||||||
|
|
||||||
proportional == 0 ? NAN : proportional,
|
proportional == 0 ? NAN : proportional,
|
||||||
integral == 0 ? NAN : integral,
|
integral == 0 ? NAN : integral,
|
||||||
derivative == 0 ? NAN : derivative,
|
derivative == 0 ? NAN : derivative,
|
||||||
@ -140,7 +112,6 @@ void patrixLoop() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void displayLoop() {
|
void displayLoop() {
|
||||||
static unsigned long lastDisplayInit = 0;
|
static unsigned long lastDisplayInit = 0;
|
||||||
if (lastDisplayInit == 0 || millis() - lastDisplayInit > 60 * 60 * 1000) {
|
if (lastDisplayInit == 0 || millis() - lastDisplayInit > 60 * 60 * 1000) {
|
||||||
35
src/Fermenter/FermenterData.h
Normal file
35
src/Fermenter/FermenterData.h
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
#ifndef SENSOR3_FERMENTERDATA_H
|
||||||
|
#define SENSOR3_FERMENTERDATA_H
|
||||||
|
|
||||||
|
#include "data.h"
|
||||||
|
|
||||||
|
struct FermenterData : IData {
|
||||||
|
double temperature;
|
||||||
|
double target;
|
||||||
|
double p;
|
||||||
|
double i;
|
||||||
|
double d;
|
||||||
|
|
||||||
|
FermenterData() {
|
||||||
|
temperature = NAN;
|
||||||
|
target = NAN;
|
||||||
|
p = NAN;
|
||||||
|
i = NAN;
|
||||||
|
d = NAN;
|
||||||
|
}
|
||||||
|
|
||||||
|
FermenterData(double temperature, double target, double p, double i, double d) : temperature(temperature), target(target), p(p), i(i), d(d) {
|
||||||
|
// -
|
||||||
|
}
|
||||||
|
|
||||||
|
void toJson(JsonObject &json) const override {
|
||||||
|
json["temperature"] = temperature;
|
||||||
|
json["target"] = target;
|
||||||
|
json["p"] = p;
|
||||||
|
json["i"] = i;
|
||||||
|
json["d"] = d;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
27
src/Test.cpp
27
src/Test.cpp
@ -1,27 +0,0 @@
|
|||||||
#if defined(TEST8266) || defined(TEST32)
|
|
||||||
|
|
||||||
#include <Patrix.h>
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
void patrixSetup() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void patrixLoop() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void configLoaded() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
bool patrix_command(char *first) {
|
|
||||||
if (strcmp(first, "test") == 0 || strcmp(first, "t") == 0) {
|
|
||||||
configPutDouble("test", millis());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
Loading…
Reference in New Issue
Block a user