first throw of PID parameters

This commit is contained in:
Patrick Haßel 2024-04-11 21:03:55 +02:00
parent 87cca64c79
commit fb6edf1828

View File

@ -8,6 +8,7 @@
#define SENSOR_GPIO D4 #define SENSOR_GPIO D4
#define CONTROL_GPIO D2 #define CONTROL_GPIO D2
#define CONTROL_PWM_BITS 10 #define CONTROL_PWM_BITS 10
#define CONTROL_PWM_MAX (pow(10, CONTROL_PWM_BITS))
Dallas dallas(SENSOR_GPIO); Dallas dallas(SENSOR_GPIO);
@ -23,9 +24,9 @@ double temperatureMaxOvershoot = 5;
double heaterPWM = 0; double heaterPWM = 0;
double proportional = 1; double proportional = 10;
double integral = 0; double integral = 2;
double derivative = 0; double derivative = 0;
@ -36,7 +37,7 @@ void patrixSetup() {
configLoad(); configLoad();
pid.begin(&temperatureCurrent, &heaterPWM, &temperatureTarget, proportional, integral, derivative); pid.begin(&temperatureCurrent, &heaterPWM, &temperatureTarget, proportional, integral, derivative);
pid.setOutputLimits(0, pow(10, CONTROL_PWM_BITS) - 1); pid.setOutputLimits(0, CONTROL_PWM_MAX - 1);
pid.start(); pid.start();
} }
@ -55,13 +56,16 @@ void patrixLoop() {
if (emergencyCutOff) { if (emergencyCutOff) {
heaterPWM = 0; heaterPWM = 0;
} }
heaterPWM = min(0.0, max(CONTROL_PWM_MAX, heaterPWM));
analogWrite(CONTROL_GPIO, (int) round(heaterPWM)); analogWrite(CONTROL_GPIO, (int) round(heaterPWM));
static unsigned long lastDebug = 0; static unsigned long lastDebug = 0;
unsigned long now = millis(); unsigned long now = millis();
if (now - lastDebug >= 1000) { if (now - lastDebug >= 1000) {
lastDebug = now; lastDebug = now;
debug("p: %f | i: %f | d: %f | current: %4.1f | target: %4.1f | pwm: %f", proportional, integral, derivative, temperatureCurrent, temperatureTarget, heaterPWM); 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);
if (emergencyCutOff) { if (emergencyCutOff) {
error("[EMERGENCY CUTOFF] temperatureCurrent (=%4.1f) > temperatureTarget + %4.1f (=%4.1f) [EMERGENCY CUTOFF]", temperatureCurrent, temperatureMaxOvershoot, temperatureTarget); error("[EMERGENCY CUTOFF] temperatureCurrent (=%4.1f) > temperatureTarget + %4.1f (=%4.1f) [EMERGENCY CUTOFF]", temperatureCurrent, temperatureMaxOvershoot, temperatureTarget);
} }
@ -93,8 +97,7 @@ bool setDouble(const char *name, double *destinationPtr, double min, double max)
return true; return true;
} }
bool patrix_command(char *cmd) { bool patrix_command(char *first) {
const char *first = strtok(cmd, " ");
bool result = false; bool result = false;
if (strcmp(first, "over") == 0) { if (strcmp(first, "over") == 0) {
result = setDouble("over", &temperatureMaxOvershoot, 0, 20); result = setDouble("over", &temperatureMaxOvershoot, 0, 20);