From d5f86fe4725ed6c298ca18f8c0d0349935dc789e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Ha=C3=9Fel?= Date: Thu, 11 Apr 2024 21:28:31 +0200 Subject: [PATCH] PID evolve --- src/Fermenter.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/Fermenter.cpp b/src/Fermenter.cpp index e0d441e..8187f4a 100644 --- a/src/Fermenter.cpp +++ b/src/Fermenter.cpp @@ -8,7 +8,7 @@ #define SENSOR_GPIO D4 #define CONTROL_GPIO D2 #define CONTROL_PWM_BITS 10 -#define CONTROL_PWM_MAX (pow(10, CONTROL_PWM_BITS)) +#define CONTROL_PWM_MAX (pow(2, CONTROL_PWM_BITS) - 1) Dallas dallas(SENSOR_GPIO); @@ -37,7 +37,7 @@ void patrixSetup() { configLoad(); pid.begin(&temperatureCurrent, &heaterPWM, &temperatureTarget, proportional, integral, derivative); - pid.setOutputLimits(0, CONTROL_PWM_MAX - 1); + pid.setOutputLimits(0, CONTROL_PWM_MAX); pid.start(); } @@ -57,7 +57,7 @@ void patrixLoop() { heaterPWM = 0; } - heaterPWM = min(0.0, max(CONTROL_PWM_MAX, heaterPWM)); + heaterPWM = min(CONTROL_PWM_MAX, max(0.0, heaterPWM)); analogWrite(CONTROL_GPIO, (int) round(heaterPWM)); static unsigned long lastDebug = 0; @@ -65,7 +65,7 @@ void patrixLoop() { if (now - lastDebug >= 1000) { lastDebug = now; int heaterPercent = (int) round(100.0 * heaterPWM / CONTROL_PWM_MAX); - debug("p: %f | i: %f | d: %f | current: %4.1f | target: %4.1f | pwm: %3d%%", proportional, integral, derivative, temperatureCurrent, temperatureTarget, heaterPercent); + debug("p: %f | i: %f | d: %f | current: %4.1f | target: %4.1f | heater: %3d%%", proportional, integral, derivative, temperatureCurrent, temperatureTarget, heaterPercent); if (emergencyCutOff) { error("[EMERGENCY CUTOFF] temperatureCurrent (=%4.1f) > temperatureTarget + %4.1f (=%4.1f) [EMERGENCY CUTOFF]", temperatureCurrent, temperatureMaxOvershoot, temperatureTarget); } @@ -117,10 +117,8 @@ bool patrix_command(char *first) { } void configLoad() { - proportional = configGetDouble("p", 1); + proportional = configGetDouble("p", 200); integral = configGetDouble("i", 0); - proportional = configGetDouble("p", 5); - integral = configGetDouble("i", 2); derivative = configGetDouble("d", 0); temperatureTarget = configGetDouble("target", 31); temperatureMaxOvershoot = configGetDouble("over", 5);