first throw of PID parameters
This commit is contained in:
parent
87cca64c79
commit
fb6edf1828
@ -8,6 +8,7 @@
|
||||
#define SENSOR_GPIO D4
|
||||
#define CONTROL_GPIO D2
|
||||
#define CONTROL_PWM_BITS 10
|
||||
#define CONTROL_PWM_MAX (pow(10, CONTROL_PWM_BITS))
|
||||
|
||||
Dallas dallas(SENSOR_GPIO);
|
||||
|
||||
@ -23,9 +24,9 @@ double temperatureMaxOvershoot = 5;
|
||||
|
||||
double heaterPWM = 0;
|
||||
|
||||
double proportional = 1;
|
||||
double proportional = 10;
|
||||
|
||||
double integral = 0;
|
||||
double integral = 2;
|
||||
|
||||
double derivative = 0;
|
||||
|
||||
@ -36,7 +37,7 @@ void patrixSetup() {
|
||||
configLoad();
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
@ -55,13 +56,16 @@ void patrixLoop() {
|
||||
if (emergencyCutOff) {
|
||||
heaterPWM = 0;
|
||||
}
|
||||
|
||||
heaterPWM = min(0.0, max(CONTROL_PWM_MAX, heaterPWM));
|
||||
analogWrite(CONTROL_GPIO, (int) round(heaterPWM));
|
||||
|
||||
static unsigned long lastDebug = 0;
|
||||
unsigned long now = millis();
|
||||
if (now - lastDebug >= 1000) {
|
||||
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) {
|
||||
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;
|
||||
}
|
||||
|
||||
bool patrix_command(char *cmd) {
|
||||
const char *first = strtok(cmd, " ");
|
||||
bool patrix_command(char *first) {
|
||||
bool result = false;
|
||||
if (strcmp(first, "over") == 0) {
|
||||
result = setDouble("over", &temperatureMaxOvershoot, 0, 20);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user