# HG changeset patch # User Michiel Broek # Date 1424444729 -3600 # Node ID b95baa89c5097b9a96ec4eedd5075595902b175e # Parent 9e419f3c4e49a0445673fafbd27c2164e05e09b5 Code cleanup and more conditions for debug temperature logging diff -r 9e419f3c4e49 -r b95baa89c509 thermferm/thermferm.c --- a/thermferm/thermferm.c Thu Feb 19 16:41:42 2015 +0100 +++ b/thermferm/thermferm.c Fri Feb 20 16:05:29 2015 +0100 @@ -1306,11 +1306,10 @@ } /* - * PID controller per unit, each second + * Temperature control per unit, each second */ for (unit = Config.units; unit; unit = unit->next) { if ((unit->mode == UNITMODE_FRIDGE) || (unit->mode == UNITMODE_BEER) || (unit->mode == UNITMODE_PROFILE)) { -// double pTerm, dTerm, iTerm; int usePid = TRUE; sp = unit->beer_set; @@ -1351,7 +1350,8 @@ if (debug) fprintf(stdout, "sp=%.2f pv=%.2f dState=%.2f P_err=%.2f iState=%.2f Out=%.2f\n", sp, pv, unit->PID_dState, P_err, unit->PID_iState, Out); - if ((Out >= 1) || (Out <= -1) || (seconds == 60) || unit->heater_state || unit->cooler_state) { + if (((Out >= 1) && unit->heater_address) || ((Out <= -1) && unit->cooler_address) || + (seconds == 60) || unit->heater_state || unit->cooler_state) { syslog(LOG_NOTICE, "sp=%.2f pv=%.2f P_err=%.2f dState=%.2f iState=%.2f Out=%.2f", sp, pv, P_err, unit->PID_dState, unit->PID_iState, Out); } @@ -1371,47 +1371,13 @@ } else { Out = 0.0; } - if ((Out >= 1) || (Out <= -1) || (seconds == 60) || unit->heater_state || unit->cooler_state) { + if (((Out >= 1) && unit->heater_address) || ((Out <= -1) && unit->cooler_address) || + (seconds == 60) || unit->heater_state || unit->cooler_state) { syslog(LOG_NOTICE, "sp=%.2f pv=%.2f P_err=%.2f Out=%.2f", sp, pv, P_err, Out); } } -// pTerm = unit->PID_Kp * P_err; - - /* - * Calculate the intergral state with appropriate limiting - */ -// unit->PID_iState += P_err; - /* Limit integral error */ -// if (unit->PID_iState < -100.0) -// unit->PID_iState = -100.0; -// if (unit->PID_iState > 100.0) -// unit->PID_iState = 100.0; -// iTerm = unit->PID_iState * unit->PID_Ki; -// dTerm = (unit->PID_dState - pv) * unit->PID_Kd; - - /* - * A postive value means heating, a negative value cooling. - * Start with Kp, Kd and Ki set to 0. - * Increase Kp until small oscillation. - * Increase Kd until a little damping. - * Increase Ki after Kp and Kd are set until longterm convergence. - */ -// Out = pTerm + dTerm + iTerm; -// if (Out > 100.0) -// Out = 100.0; -// if (Out < -100.0) -// Out = -100.0; -// if (debug) -// fprintf(stdout, "sp=%.2f pv=%.2f dState=%.2f P_err=%.2f iState=%.2f Out=%.2f\n", -// sp, pv, unit->PID_dState, P_err, unit->PID_iState, Out); -// if ((Out >= 1) || (Out <= -1) || (seconds == 60) || unit->heater_state || unit->cooler_state) { -// syslog(LOG_NOTICE, "sp=%.2f pv=%.2f P_err=%.2f dState=%.2f iState=%.2f pTerm=%.2f iTerm=%.2f dTerm=%.2f Out=%.2f", -// sp, pv, P_err, unit->PID_dState, unit->PID_iState, pTerm, iTerm, dTerm, Out); -// } -// unit->PID_dState = pv; - if (unit->heater_address && ! unit->cooler_state) { if (Out >= 1) { if (unit->heater_wait < unit->heater_delay) {