Committer: Isaac <isaac@iosull.com>
Updates to remove unnecessary autotune functionality. Clean timer rollover issue.
This commit is contained in:
+2
-94
@@ -17,7 +17,6 @@
|
|||||||
#include <OneWire.h>
|
#include <OneWire.h>
|
||||||
#include <DallasTemperature.h>
|
#include <DallasTemperature.h>
|
||||||
#include <PID_v1.h>
|
#include <PID_v1.h>
|
||||||
#include <PID_AutoTune_v0.h>
|
|
||||||
#include "src/SevenSegmentTM1637/SevenSegmentTM1637.h"
|
#include "src/SevenSegmentTM1637/SevenSegmentTM1637.h"
|
||||||
#include "src/SevenSegmentTM1637/SevenSegmentExtended.h"
|
#include "src/SevenSegmentTM1637/SevenSegmentExtended.h"
|
||||||
|
|
||||||
@@ -46,14 +45,12 @@
|
|||||||
#define MQTT_PUBLISH_RATE 2000
|
#define MQTT_PUBLISH_RATE 2000
|
||||||
#define BUTTON_POLL_RATE 50
|
#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 DEBUG false // debug to serial port
|
||||||
#define TIMER_DEBUG false // debug interrupt to serial port
|
#define TIMER_DEBUG false // debug interrupt to serial port
|
||||||
|
|
||||||
|
|
||||||
// --- INIT ---
|
// --- INIT ---
|
||||||
|
|
||||||
|
|
||||||
// Milk Probe
|
// Milk Probe
|
||||||
OneWire oneWire(DS_MILK_PIN);
|
OneWire oneWire(DS_MILK_PIN);
|
||||||
DallasTemperature ds(&oneWire);
|
DallasTemperature ds(&oneWire);
|
||||||
@@ -73,7 +70,7 @@ float tempMilk = 0;
|
|||||||
double tempDesired = 93;
|
double tempDesired = 93;
|
||||||
double tempActual = 0;
|
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 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 Ki = 0.3;
|
||||||
double Kd = 0.5;
|
double Kd = 0.5;
|
||||||
|
|
||||||
@@ -83,11 +80,6 @@ double PWMOutput;
|
|||||||
unsigned long windowStartTime;
|
unsigned long windowStartTime;
|
||||||
int WindowSize = 5000;
|
int WindowSize = 5000;
|
||||||
|
|
||||||
// PID Autotune parameters
|
|
||||||
byte ATuneModeRemember = 2;
|
|
||||||
bool tuning = false;
|
|
||||||
PID_ATune aTune(&Input, &Output);
|
|
||||||
|
|
||||||
ESP8266WebServer server(80);
|
ESP8266WebServer server(80);
|
||||||
char jsonresult[512];
|
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) {
|
double round2(double value) {
|
||||||
// Round down to 2 decimal places
|
// Round down to 2 decimal places
|
||||||
return (int)(value * 100 + 0.5) / 100.0;
|
return (int)(value * 100 + 0.5) / 100.0;
|
||||||
@@ -174,7 +138,6 @@ char *genJSON() {
|
|||||||
doc["Kp"] = round2(Kp);
|
doc["Kp"] = round2(Kp);
|
||||||
doc["Ki"] = round2(Ki);
|
doc["Ki"] = round2(Ki);
|
||||||
doc["Kd"] = round2(Kd);
|
doc["Kd"] = round2(Kd);
|
||||||
doc["autotuning"] = tuning;
|
|
||||||
doc["RelayOnTime"] = round2(ontime); // send rolling window for on time of PWM from 0 to 1.
|
doc["RelayOnTime"] = round2(ontime); // send rolling window for on time of PWM from 0 to 1.
|
||||||
|
|
||||||
serializeJson(doc, jsonresult);
|
serializeJson(doc, jsonresult);
|
||||||
@@ -237,39 +200,6 @@ void handleSave() {
|
|||||||
server.send(200, "text/plain", "Wrote config to EEPROM.");
|
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() {
|
void controlRelay() {
|
||||||
// Provide the PID loop with the current temperature
|
// Provide the PID loop with the current temperature
|
||||||
Input = tempActual;
|
Input = tempActual;
|
||||||
@@ -281,24 +211,7 @@ void controlRelay() {
|
|||||||
return;
|
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
|
// Starts a new PWM cycle every WindowSize milliseconds
|
||||||
if ((now - windowStartTime) > WindowSize)
|
if ((now - windowStartTime) > WindowSize)
|
||||||
@@ -387,7 +300,7 @@ void displayUpdate() {
|
|||||||
break;
|
break;
|
||||||
case 2: // Timer Display
|
case 2: // Timer Display
|
||||||
// Update later with switch/case for other temps
|
// 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);
|
display.setColonOn(true);
|
||||||
break;
|
break;
|
||||||
case 3: // Milk Temperature Display
|
case 3: // Milk Temperature Display
|
||||||
@@ -471,8 +384,6 @@ void initServer() {
|
|||||||
server.on("/json", handleJSON);
|
server.on("/json", handleJSON);
|
||||||
server.on("/set", HTTP_POST, handleSetvals);
|
server.on("/set", HTTP_POST, handleSetvals);
|
||||||
server.on("/save", HTTP_POST, handleSave);
|
server.on("/save", HTTP_POST, handleSave);
|
||||||
server.on("/autotunestart", HTTP_POST, handleAutotuneStart);
|
|
||||||
server.on("/autotunestop", HTTP_POST, handleAutotuneStop);
|
|
||||||
server.begin();
|
server.begin();
|
||||||
|
|
||||||
#if (DEBUG > 0)
|
#if (DEBUG > 0)
|
||||||
@@ -502,9 +413,6 @@ void initPID() {
|
|||||||
|
|
||||||
// Set PID values from EEPROM
|
// Set PID values from EEPROM
|
||||||
myPID.SetTunings(Kp, Ki, Kd);
|
myPID.SetTunings(Kp, Ki, Kd);
|
||||||
|
|
||||||
// Set 1 for PID or 0 for PI controller autotuning parameters
|
|
||||||
aTune.SetControlType(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
|||||||
Reference in New Issue
Block a user