rearrange custom libraries.
This commit is contained in:
parent
1fb657f491
commit
99600c9135
1
boil_kettle/src/Arduino-PID-Library
Submodule
1
boil_kettle/src/Arduino-PID-Library
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit 9b4ca0e5b6d7bab9c6ac023e249d6af2446d99bb
|
@ -7,28 +7,24 @@
|
|||||||
void doEncoder()
|
void doEncoder()
|
||||||
{
|
{
|
||||||
uint8_t result = rotary.read();
|
uint8_t result = rotary.read();
|
||||||
uint8_t inc;
|
int inc;
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
uint8_t speed = rotary.speed();
|
uint8_t speed = rotary.speed();
|
||||||
speed >= 10 ? inc = 5 : inc = 1;
|
speed >= 10 ? inc = 5 : inc = 1;
|
||||||
if (result == DIR_CCW) inc = inc * -1;
|
if (result == DIR_CCW) inc = inc * -1;
|
||||||
}
|
|
||||||
|
|
||||||
SettingChanged = true;
|
SettingChanged = true;
|
||||||
|
|
||||||
if (KettleController.Mode() == MANUAL) {
|
|
||||||
|
|
||||||
uint8_t KettleDuty = (uint8_t)KettleController.Power();
|
|
||||||
KettleDuty = max(0, min((KettleDuty / inc) * inc + inc, 100));
|
|
||||||
KettleController.Power((double)KettleDuty);
|
|
||||||
|
|
||||||
} else if (KettleController.Mode() == AUTOMATIC) {
|
|
||||||
|
|
||||||
uint8_t KettleTemp = (uint8_t)KettleController.Setpoint();
|
|
||||||
KettleTemp = max(0, min((KettleTemp / inc) * inc + inc, 220));
|
|
||||||
KettleController.Setpoint((double)KettleTemp);
|
|
||||||
|
|
||||||
|
if (KettleController.Mode() == MANUAL) {
|
||||||
|
uint8_t KettleDuty = (uint8_t)KettleController.Power();
|
||||||
|
KettleDuty = max(0, min((KettleDuty / inc) * inc + inc, 100));
|
||||||
|
KettleController.Power((double)KettleDuty);
|
||||||
|
} else if (KettleController.Mode() == AUTOMATIC) {
|
||||||
|
uint8_t KettleTemp = (uint8_t)KettleController.Setpoint();
|
||||||
|
KettleTemp = max(0, min((KettleTemp / inc) * inc + inc, 220));
|
||||||
|
KettleController.Setpoint((double)KettleTemp);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
SettingChanged = false;
|
SettingChanged = false;
|
||||||
}
|
}
|
||||||
@ -38,11 +34,11 @@ void doEncoder()
|
|||||||
// state of the kettle.
|
// state of the kettle.
|
||||||
char* ShowKettleState() {
|
char* ShowKettleState() {
|
||||||
if (KettleController.Mode() == MANUAL) {
|
if (KettleController.Mode() == MANUAL) {
|
||||||
return (char*)F("Kettle: Manual");
|
return (char*)"Kettle: Manual";
|
||||||
} else if (KettleController.Mode() == AUTOMATIC) {
|
} else if (KettleController.Mode() == AUTOMATIC) {
|
||||||
return (char*)F("Kettle: Auto");
|
return (char*)"Kettle: Auto";
|
||||||
} else {
|
} else {
|
||||||
return (char*)F("Kettle: Off");
|
return (char*)"Kettle: Off";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,26 +46,27 @@ char* ShowKettleSetting() {
|
|||||||
static char LCD_Line[21];
|
static char LCD_Line[21];
|
||||||
char setting[4];
|
char setting[4];
|
||||||
if (KettleController.Mode() == MANUAL) {
|
if (KettleController.Mode() == MANUAL) {
|
||||||
strcpy(LCD_Line, (char*)F("Kettle Power: "));
|
strcpy(LCD_Line, (char*)"Kettle Power: ");
|
||||||
itoa(KettleController.Power(), setting, 10);
|
itoa(KettleController.Power(), setting, 10);
|
||||||
strcat(LCD_Line, setting);
|
strcat(LCD_Line, setting);
|
||||||
strcat(LCD_Line, (char*)F("%"));
|
strcat(LCD_Line, (char*)"%");
|
||||||
|
|
||||||
return LCD_Line;
|
return LCD_Line;
|
||||||
} else if (KettleController.Mode() == AUTOMATIC) {
|
} else if (KettleController.Mode() == AUTOMATIC) {
|
||||||
strcpy(LCD_Line, (char*)F("Kettle Temp: "));
|
strcpy(LCD_Line, (char*)"Kettle Temp: ");
|
||||||
itoa(KettleController.Setpoint(), setting, 10);
|
itoa(KettleController.Setpoint(), setting, 10);
|
||||||
strcat(LCD_Line, setting);
|
strcat(LCD_Line, setting);
|
||||||
strcat(LCD_Line, (char*)F("F"));
|
strcat(LCD_Line, (char*)"F");
|
||||||
return LCD_Line;
|
return LCD_Line;
|
||||||
} else {
|
} else {
|
||||||
return (char*)"";
|
return (char*)"It's Off stoopid";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateBoilKettle(){
|
void UpdateBoilKettle(){
|
||||||
|
|
||||||
if (Enter.pressed()) {
|
if (Enter.pressed()) {
|
||||||
|
Serial.println("Pressed");
|
||||||
KettleController.CycleMode();
|
KettleController.CycleMode();
|
||||||
SettingChanged = true;
|
SettingChanged = true;
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ class slowPWM {
|
|||||||
pinMode(pin, OUTPUT);
|
pinMode(pin, OUTPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
byte compute(uint8_t duty) {
|
byte Compute(double duty) {
|
||||||
unsigned long onTime = (duty * period) / 1000;
|
unsigned long onTime = (duty * period) / 1000;
|
||||||
unsigned long offTime = period - onTime;
|
unsigned long offTime = period - onTime;
|
||||||
unsigned long currentTime = millis();
|
unsigned long currentTime = millis();
|
@ -1,118 +0,0 @@
|
|||||||
|
|
||||||
#include <Arduino.h>
|
|
||||||
#include <Adafruit_MAX31865.h>
|
|
||||||
#include "thermoControl.h"
|
|
||||||
|
|
||||||
|
|
||||||
void thermoControl::begin(int pinRTD) {
|
|
||||||
RTD = new Adafruit_MAX31865(pinRTD);
|
|
||||||
r_ref = 430.0;
|
|
||||||
r_nominal = 100.0;
|
|
||||||
outMax = 100;
|
|
||||||
outMin = 10;
|
|
||||||
OpMode = OFF;
|
|
||||||
SampleInterval = 100;
|
|
||||||
lastTime = millis()-SampleInterval;
|
|
||||||
output_pwm = 0;
|
|
||||||
control_temp = 0;
|
|
||||||
hysteresis = 1.0;
|
|
||||||
max_pwr_threshold = 5.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void thermoControl::begin(int pinRTD, double temp, double duty, double mpt, double hyst) {
|
|
||||||
RTD = new Adafruit_MAX31865(pinRTD);
|
|
||||||
r_ref = 430.0;
|
|
||||||
r_nominal = 100.0;
|
|
||||||
outMax = 100;
|
|
||||||
outMin = 10;
|
|
||||||
OpMode = OFF;
|
|
||||||
SampleInterval = 100;
|
|
||||||
lastTime = millis()-SampleInterval;
|
|
||||||
|
|
||||||
output_pwm = duty;
|
|
||||||
control_temp = temp;
|
|
||||||
hysteresis = hyst;
|
|
||||||
max_pwr_threshold = mpt;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool thermoControl::Compute() {
|
|
||||||
unsigned long now = millis();
|
|
||||||
unsigned long timeChange = (now - lastTime);
|
|
||||||
|
|
||||||
double temp = RTD->temperature(r_nominal, r_ref);
|
|
||||||
|
|
||||||
if(timeChange>=SampleInterval && OpMode == AUTOMATIC) {
|
|
||||||
double output;
|
|
||||||
double error = control_temp - temp;
|
|
||||||
|
|
||||||
if (error >= max_pwr_threshold) {
|
|
||||||
output = outMax;
|
|
||||||
} else if (error > hysteresis) {
|
|
||||||
output = 100 * error / max_pwr_threshold;
|
|
||||||
output = max(output, outMin);
|
|
||||||
output = min(output, outMax);
|
|
||||||
} else {
|
|
||||||
output = 0;
|
|
||||||
}
|
|
||||||
output_pwm = output;
|
|
||||||
lastTime = now;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
double thermoControl::Power() {
|
|
||||||
return output_pwm;
|
|
||||||
}
|
|
||||||
|
|
||||||
void thermoControl::Power(double pwr) {
|
|
||||||
output_pwm = pwr;
|
|
||||||
}
|
|
||||||
|
|
||||||
double thermoControl::Setpoint() {
|
|
||||||
return control_temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
void thermoControl::Setpoint(double temp) {
|
|
||||||
control_temp = temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
void thermoControl::SampleTime(int NewSampleTime) {
|
|
||||||
if (NewSampleTime > 0) {
|
|
||||||
SampleInterval = (unsigned long)NewSampleTime;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void thermoControl::PowerLimits(double Max, double Min) {
|
|
||||||
if(Min >= Max) return;
|
|
||||||
outMax = Max;
|
|
||||||
outMin = Min;
|
|
||||||
}
|
|
||||||
|
|
||||||
void thermoControl::Hysteresis(double hys) {
|
|
||||||
hysteresis = hys;
|
|
||||||
}
|
|
||||||
|
|
||||||
void thermoControl::ThreshPWR(double thresh) {
|
|
||||||
max_pwr_threshold = thresh;
|
|
||||||
}
|
|
||||||
|
|
||||||
void thermoControl::Mode(modes newMode) {
|
|
||||||
OpMode = newMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
modes thermoControl::Mode() {
|
|
||||||
return OpMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
modes thermoControl::CycleMode() {
|
|
||||||
if (OpMode + 1 == OVERFLOW) {
|
|
||||||
OpMode = (modes)(0);
|
|
||||||
} else {
|
|
||||||
OpMode = (modes)(OpMode + 1);
|
|
||||||
}
|
|
||||||
return OpMode;
|
|
||||||
}
|
|
||||||
|
|
82
boil_kettle/src/thermoControl/thermoControl.cpp
Normal file
82
boil_kettle/src/thermoControl/thermoControl.cpp
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <Adafruit_MAX31865.h>
|
||||||
|
#include "thermoControl.h"
|
||||||
|
|
||||||
|
thermoControl::thermoControl(double* current_temp, double* setpoint, double* power, modes mode) {
|
||||||
|
outMax = 100;
|
||||||
|
outMin = 10;
|
||||||
|
OpMode = mode;
|
||||||
|
SampleInterval = 100;
|
||||||
|
lastTime = millis()-SampleInterval;
|
||||||
|
output_pwm = power;
|
||||||
|
control_temp = setpoint;
|
||||||
|
actual_temp = current_temp;
|
||||||
|
hysteresis = 1.0;
|
||||||
|
max_pwr_threshold = 5.0;
|
||||||
|
Serial.println("Controller Started");
|
||||||
|
}
|
||||||
|
|
||||||
|
bool thermoControl::Compute() {
|
||||||
|
unsigned long now = millis();
|
||||||
|
unsigned long timeChange = (now - lastTime);
|
||||||
|
|
||||||
|
if(timeChange >= SampleInterval && OpMode == AUTOMATIC) {
|
||||||
|
double error = *control_temp - *actual_temp;
|
||||||
|
|
||||||
|
if (error >= max_pwr_threshold) {
|
||||||
|
*output_pwm = outMax;
|
||||||
|
} else if (error > hysteresis) {
|
||||||
|
*output_pwm = 100 * error / max_pwr_threshold;
|
||||||
|
*output_pwm = max(*output_pwm, outMin);
|
||||||
|
*output_pwm = min(*output_pwm, outMax);
|
||||||
|
} else {
|
||||||
|
*output_pwm = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
lastTime = now;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void thermoControl::SampleTime(int NewSampleTime) {
|
||||||
|
if (NewSampleTime > 0) {
|
||||||
|
SampleInterval = NewSampleTime;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void thermoControl::PowerLimits(double Max, double Min) {
|
||||||
|
if(Min >= Max) return;
|
||||||
|
outMax = Max;
|
||||||
|
outMin = Min;
|
||||||
|
}
|
||||||
|
|
||||||
|
void thermoControl::Hysteresis(double hys) {
|
||||||
|
hysteresis = hys;
|
||||||
|
}
|
||||||
|
|
||||||
|
void thermoControl::ThreshPWR(double thresh) {
|
||||||
|
max_pwr_threshold = thresh;
|
||||||
|
}
|
||||||
|
|
||||||
|
void thermoControl::Mode(modes newMode) {
|
||||||
|
Serial.println(newMode);
|
||||||
|
OpMode = newMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
modes thermoControl::Mode() {
|
||||||
|
return OpMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
modes thermoControl::CycleMode() {
|
||||||
|
if (OpMode + 1 == OVERFLOW) {
|
||||||
|
OpMode = (modes)(0);
|
||||||
|
} else {
|
||||||
|
OpMode = (modes)(OpMode + 1);
|
||||||
|
}
|
||||||
|
return OpMode;
|
||||||
|
}
|
||||||
|
|
@ -3,28 +3,28 @@
|
|||||||
|
|
||||||
#include <Adafruit_MAX31865.h>
|
#include <Adafruit_MAX31865.h>
|
||||||
|
|
||||||
|
#ifndef enum modes
|
||||||
enum modes : uint8_t {OFF, AUTOMATIC, MANUAL, OVERFLOW};
|
enum modes : uint8_t {OFF, AUTOMATIC, MANUAL, OVERFLOW};
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
class thermoControl {
|
class thermoControl {
|
||||||
private:
|
private:
|
||||||
Adafruit_MAX31865* RTD;
|
double *output_pwm;
|
||||||
double r_nominal;
|
double *control_temp;
|
||||||
double r_ref;
|
double * actual_temp;
|
||||||
double output_pwm;
|
double current_temp;
|
||||||
double control_temp;
|
|
||||||
double hysteresis;
|
double hysteresis;
|
||||||
double max_pwr_threshold;
|
double max_pwr_threshold;
|
||||||
int outMax;
|
int outMax;
|
||||||
int outMin;
|
int outMin;
|
||||||
|
int SampleInterval;
|
||||||
|
unsigned long lastTime;
|
||||||
modes OpMode;
|
modes OpMode;
|
||||||
|
|
||||||
unsigned long SampleInterval;
|
|
||||||
unsigned long lastTime;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void begin(int, double, double, double, double);
|
thermoControl(double*, double*, double*, modes);
|
||||||
void begin(int);
|
void nope();
|
||||||
bool Compute();
|
bool Compute();
|
||||||
double Power();
|
double Power();
|
||||||
void Power(double);
|
void Power(double);
|
Loading…
Reference in New Issue
Block a user