PID evolve

This commit is contained in:
Patrick Haßel 2024-04-11 21:28:31 +02:00
parent 6a7118635f
commit d5f86fe472

View File

@ -8,7 +8,7 @@
#define SENSOR_GPIO D4
#define CONTROL_GPIO D2
#define CONTROL_PWM_BITS 10
#define CONTROL_PWM_MAX (pow(10, CONTROL_PWM_BITS))
#define CONTROL_PWM_MAX (pow(2, CONTROL_PWM_BITS) - 1)
Dallas dallas(SENSOR_GPIO);
@ -37,7 +37,7 @@ void patrixSetup() {
configLoad();
pid.begin(&temperatureCurrent, &heaterPWM, &temperatureTarget, proportional, integral, derivative);
pid.setOutputLimits(0, CONTROL_PWM_MAX - 1);
pid.setOutputLimits(0, CONTROL_PWM_MAX);
pid.start();
}
@ -57,7 +57,7 @@ void patrixLoop() {
heaterPWM = 0;
}
heaterPWM = min(0.0, max(CONTROL_PWM_MAX, heaterPWM));
heaterPWM = min(CONTROL_PWM_MAX, max(0.0, heaterPWM));
analogWrite(CONTROL_GPIO, (int) round(heaterPWM));
static unsigned long lastDebug = 0;
@ -65,7 +65,7 @@ void patrixLoop() {
if (now - lastDebug >= 1000) {
lastDebug = now;
int heaterPercent = (int) round(100.0 * heaterPWM / CONTROL_PWM_MAX);
debug("p: %f | i: %f | d: %f | current: %4.1f | target: %4.1f | pwm: %3d%%", proportional, integral, derivative, temperatureCurrent, temperatureTarget, heaterPercent);
debug("p: %f | i: %f | d: %f | current: %4.1f | target: %4.1f | heater: %3d%%", proportional, integral, derivative, temperatureCurrent, temperatureTarget, heaterPercent);
if (emergencyCutOff) {
error("[EMERGENCY CUTOFF] temperatureCurrent (=%4.1f) > temperatureTarget + %4.1f (=%4.1f) [EMERGENCY CUTOFF]", temperatureCurrent, temperatureMaxOvershoot, temperatureTarget);
}
@ -117,10 +117,8 @@ bool patrix_command(char *first) {
}
void configLoad() {
proportional = configGetDouble("p", 1);
proportional = configGetDouble("p", 200);
integral = configGetDouble("i", 0);
proportional = configGetDouble("p", 5);
integral = configGetDouble("i", 2);
derivative = configGetDouble("d", 0);
temperatureTarget = configGetDouble("target", 31);
temperatureMaxOvershoot = configGetDouble("over", 5);