Compare commits

...

1 Commits

Author SHA1 Message Date
Chris Giacofei
9be0cabfe3 Heat all the way to the setpoint. 2024-05-01 15:44:29 -04:00
2 changed files with 7 additions and 3 deletions

View File

@ -14,24 +14,27 @@ thermoControl::thermoControl(double* current_temp, double* setpoint, double* pow
actual_temp = current_temp;
hysteresis = 1.0;
max_pwr_threshold = 5.0;
isheating=false;
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) {
isheating=true;
} else if (error > hysteresis || (error <= hysteresis && error > 0 && isheating)) {
*output_pwm = 100 * error / max_pwr_threshold;
if (*output_pwm > 100) *output_pwm = 100;
if (*output_pwm < 0) *output_pwm = 0;
isheating=true;
} else {
*output_pwm = 0;
isheating=false;
}
lastTime = now;

View File

@ -17,6 +17,7 @@ class thermoControl {
int outMin;
int SampleInterval;
unsigned long lastTime;
bool isheating;
modes OpMode;
public: