From 3caf7b2eaa20cffde3153c8a8fa5f8f8b7ae071a Mon Sep 17 00:00:00 2001 From: Isaac Date: Wed, 7 Sep 2022 18:25:50 +1000 Subject: [PATCH] Committer: Isaac Updates to remove unnecessary autotune functionality. Clean timer rollover issue. --- GaggiaPID.ino | 98 ++------------------------------------------------- 1 file changed, 3 insertions(+), 95 deletions(-) diff --git a/GaggiaPID.ino b/GaggiaPID.ino index 14a5e55..104be20 100644 --- a/GaggiaPID.ino +++ b/GaggiaPID.ino @@ -17,7 +17,6 @@ #include #include #include -#include #include "src/SevenSegmentTM1637/SevenSegmentTM1637.h" #include "src/SevenSegmentTM1637/SevenSegmentExtended.h" @@ -46,14 +45,12 @@ #define MQTT_PUBLISH_RATE 2000 #define BUTTON_POLL_RATE 50 -#define DEEP_SLEEP false // deep sleep then reset or idling (D0 must be connected to RST) https://github.com/nodemcu/nodemcu-devkit-v1.0 #define DEBUG false // debug to serial port #define TIMER_DEBUG false // debug interrupt to serial port // --- INIT --- - // Milk Probe OneWire oneWire(DS_MILK_PIN); DallasTemperature ds(&oneWire); @@ -73,7 +70,7 @@ float tempMilk = 0; double tempDesired = 93; double tempActual = 0; double maxBoilerTemp = 110; // Safety value, will always turn off the relay if this is exceeded (note: steam goes higher than this, but that's okay) -double Kp = 2.2; // PID setup (note: these values are potentially overwritten from EEPROM +double Kp = 2.2; // PID setup (note: these values are overwritten from EEPROM, initialize only) double Ki = 0.3; double Kd = 0.5; @@ -83,11 +80,6 @@ double PWMOutput; unsigned long windowStartTime; int WindowSize = 5000; -// PID Autotune parameters -byte ATuneModeRemember = 2; -bool tuning = false; -PID_ATune aTune(&Input, &Output); - ESP8266WebServer server(80); char jsonresult[512]; @@ -133,34 +125,6 @@ void ICACHE_RAM_ATTR TimerHandler(void) { } } -void enableAutoTune(double step, double noise, int lookback) { - tuning = true; - - aTune.SetNoiseBand(noise); - aTune.SetOutputStep(step); - aTune.SetLookbackSec(lookback); - AutoTuneHelper(true); -} - -void disableAutoTune() { - tuning = false; - - // Cancel autotune - aTune.Cancel(); - AutoTuneHelper(false); -} - -void AutoTuneHelper(boolean start) { - if (start) - { - ATuneModeRemember = myPID.GetMode(); - } - else - { - myPID.SetMode(ATuneModeRemember); - } -} - double round2(double value) { // Round down to 2 decimal places return (int)(value * 100 + 0.5) / 100.0; @@ -174,7 +138,6 @@ char *genJSON() { doc["Kp"] = round2(Kp); doc["Ki"] = round2(Ki); doc["Kd"] = round2(Kd); - doc["autotuning"] = tuning; doc["RelayOnTime"] = round2(ontime); // send rolling window for on time of PWM from 0 to 1. serializeJson(doc, jsonresult); @@ -237,39 +200,6 @@ void handleSave() { server.send(200, "text/plain", "Wrote config to EEPROM."); } -void handleAutotuneStart() { - - double step = 750; - String step_val = server.arg("step"); - if (step_val != NULL) - { - step = step_val.toFloat(); - } - - double noise = 1; - String noise_val = server.arg("noise"); - if (noise_val != NULL) - { - noise = noise_val.toFloat(); - } - - unsigned int lookback = 20; - String lookback_val = server.arg("lookback"); - if (lookback_val != NULL) - { - lookback = lookback_val.toInt(); - } - - String message = "Autotune started: noise(" + String(noise) + ") " + "step(" + String(step) + ") lookback(" + String(lookback) + ")"; - enableAutoTune(step, noise, lookback); - server.send(200, "text/plain", message); -} - -void handleAutotuneStop() { - disableAutoTune(); - server.send(200, "text/plain", "Autotune stopped."); -} - void controlRelay() { // Provide the PID loop with the current temperature Input = tempActual; @@ -281,24 +211,7 @@ void controlRelay() { return; } - if (tuning) - { - if (aTune.Runtime()) - { - tuning = false; - - // We're done, set the tuning parameters - Kp = aTune.GetKp(); - Ki = aTune.GetKi(); - Kd = aTune.GetKd(); - myPID.SetTunings(Kp, Ki, Kd); - AutoTuneHelper(false); - } - } - else - { - myPID.Compute(); - } + myPID.Compute(); // Starts a new PWM cycle every WindowSize milliseconds if ((now - windowStartTime) > WindowSize) @@ -387,7 +300,7 @@ void displayUpdate() { break; case 2: // Timer Display // Update later with switch/case for other temps - display.printDualCounter((int)(round(tempActual)), (int)(round(((millis()-shotTimer)/1000)))); + display.printDualCounter((int)(round(tempActual)), (int)(round(((millis()-shotTimer)/1000)%99))); display.setColonOn(true); break; case 3: // Milk Temperature Display @@ -471,8 +384,6 @@ void initServer() { server.on("/json", handleJSON); server.on("/set", HTTP_POST, handleSetvals); server.on("/save", HTTP_POST, handleSave); - server.on("/autotunestart", HTTP_POST, handleAutotuneStart); - server.on("/autotunestop", HTTP_POST, handleAutotuneStop); server.begin(); #if (DEBUG > 0) @@ -502,9 +413,6 @@ void initPID() { // Set PID values from EEPROM myPID.SetTunings(Kp, Ki, Kd); - - // Set 1 for PID or 0 for PI controller autotuning parameters - aTune.SetControlType(1); } void setup() {