Heat all the way to the setpoint.
This commit is contained in:
parent
c98aebc716
commit
9be0cabfe3
@ -14,24 +14,27 @@ thermoControl::thermoControl(double* current_temp, double* setpoint, double* pow
|
|||||||
actual_temp = current_temp;
|
actual_temp = current_temp;
|
||||||
hysteresis = 1.0;
|
hysteresis = 1.0;
|
||||||
max_pwr_threshold = 5.0;
|
max_pwr_threshold = 5.0;
|
||||||
|
isheating=false;
|
||||||
Serial.println("Controller Started");
|
Serial.println("Controller Started");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool thermoControl::Compute() {
|
bool thermoControl::Compute() {
|
||||||
unsigned long now = millis();
|
unsigned long now = millis();
|
||||||
unsigned long timeChange = (now - lastTime);
|
unsigned long timeChange = (now - lastTime);
|
||||||
|
|
||||||
if(timeChange >= SampleInterval && OpMode == AUTOMATIC) {
|
if(timeChange >= SampleInterval && OpMode == AUTOMATIC) {
|
||||||
double error = *control_temp - *actual_temp;
|
double error = *control_temp - *actual_temp;
|
||||||
|
|
||||||
if (error >= max_pwr_threshold) {
|
if (error >= max_pwr_threshold) {
|
||||||
*output_pwm = outMax;
|
*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;
|
*output_pwm = 100 * error / max_pwr_threshold;
|
||||||
if (*output_pwm > 100) *output_pwm = 100;
|
if (*output_pwm > 100) *output_pwm = 100;
|
||||||
if (*output_pwm < 0) *output_pwm = 0;
|
isheating=true;
|
||||||
} else {
|
} else {
|
||||||
*output_pwm = 0;
|
*output_pwm = 0;
|
||||||
|
isheating=false;
|
||||||
}
|
}
|
||||||
|
|
||||||
lastTime = now;
|
lastTime = now;
|
||||||
|
@ -17,6 +17,7 @@ class thermoControl {
|
|||||||
int outMin;
|
int outMin;
|
||||||
int SampleInterval;
|
int SampleInterval;
|
||||||
unsigned long lastTime;
|
unsigned long lastTime;
|
||||||
|
bool isheating;
|
||||||
modes OpMode;
|
modes OpMode;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
Loading…
Reference in New Issue
Block a user