PID evolve
This commit is contained in:
parent
6a7118635f
commit
d5f86fe472
@ -8,7 +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))
|
#define CONTROL_PWM_MAX (pow(2, CONTROL_PWM_BITS) - 1)
|
||||||
|
|
||||||
Dallas dallas(SENSOR_GPIO);
|
Dallas dallas(SENSOR_GPIO);
|
||||||
|
|
||||||
@ -37,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, CONTROL_PWM_MAX - 1);
|
pid.setOutputLimits(0, CONTROL_PWM_MAX);
|
||||||
pid.start();
|
pid.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ void patrixLoop() {
|
|||||||
heaterPWM = 0;
|
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));
|
analogWrite(CONTROL_GPIO, (int) round(heaterPWM));
|
||||||
|
|
||||||
static unsigned long lastDebug = 0;
|
static unsigned long lastDebug = 0;
|
||||||
@ -65,7 +65,7 @@ void patrixLoop() {
|
|||||||
if (now - lastDebug >= 1000) {
|
if (now - lastDebug >= 1000) {
|
||||||
lastDebug = now;
|
lastDebug = now;
|
||||||
int heaterPercent = (int) round(100.0 * heaterPWM / CONTROL_PWM_MAX);
|
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) {
|
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);
|
||||||
}
|
}
|
||||||
@ -117,10 +117,8 @@ bool patrix_command(char *first) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void configLoad() {
|
void configLoad() {
|
||||||
proportional = configGetDouble("p", 1);
|
proportional = configGetDouble("p", 200);
|
||||||
integral = configGetDouble("i", 0);
|
integral = configGetDouble("i", 0);
|
||||||
proportional = configGetDouble("p", 5);
|
|
||||||
integral = configGetDouble("i", 2);
|
|
||||||
derivative = configGetDouble("d", 0);
|
derivative = configGetDouble("d", 0);
|
||||||
temperatureTarget = configGetDouble("target", 31);
|
temperatureTarget = configGetDouble("target", 31);
|
||||||
temperatureMaxOvershoot = configGetDouble("over", 5);
|
temperatureMaxOvershoot = configGetDouble("over", 5);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user