Tuning PID code. Samll changes on the unit web page.

Sun, 17 May 2015 23:23:25 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sun, 17 May 2015 23:23:25 +0200
changeset 364
2f9bbbcd2407
parent 363
468ec0d96cce
child 365
df0261bb3feb

Tuning PID code. Samll changes on the unit web page.

configure file | annotate | diff | comparison | revisions
configure.ac file | annotate | diff | comparison | revisions
thermferm/server.c file | annotate | diff | comparison | revisions
thermferm/thermferm.c file | annotate | diff | comparison | revisions
www-thermferm/units.php file | annotate | diff | comparison | revisions
--- a/configure	Sun May 17 19:34:55 2015 +0200
+++ b/configure	Sun May 17 23:23:25 2015 +0200
@@ -2034,7 +2034,7 @@
 
 
 PACKAGE="mbsePi-apps"
-VERSION="0.3.1"
+VERSION="0.3.2"
 COPYRIGHT="Copyright (C) 2014-2015 Michiel Broek, All Rights Reserved"
 CYEARS="2014-2015"
 
--- a/configure.ac	Sun May 17 19:34:55 2015 +0200
+++ b/configure.ac	Sun May 17 23:23:25 2015 +0200
@@ -8,7 +8,7 @@
 dnl General settings
 dnl After changeing the version number, run autoconf!
 PACKAGE="mbsePi-apps"
-VERSION="0.3.1"
+VERSION="0.3.2"
 COPYRIGHT="Copyright (C) 2014-2015 Michiel Broek, All Rights Reserved"
 CYEARS="2014-2015"
 AC_SUBST(PACKAGE)
--- a/thermferm/server.c	Sun May 17 19:34:55 2015 +0200
+++ b/thermferm/server.c	Sun May 17 23:23:25 2015 +0200
@@ -1965,10 +1965,10 @@
 		srv_send((char *)"HEATER_USAGE,%d", unit->heater_usage);
 		if (unit->PID_heat) {
 		    srv_send((char *)"PIDH_IMAX,%.1f", unit->PID_heat->iMax);
+		    srv_send((char *)"PIDH_IDLERANGE,%.2f", unit->PID_heat->idleRange);
 		    srv_send((char *)"PIDH_PGAIN,%.2f", unit->PID_heat->pGain);
 		    srv_send((char *)"PIDH_IGAIN,%.2f", unit->PID_heat->iGain);
 		    srv_send((char *)"PIDH_DGAIN,%.2f", unit->PID_heat->dGain);
-		    srv_send((char *)"PIDH_IDLERANGE,%.2f", unit->PID_heat->idleRange);
 		}
 		srv_send((char *)"COOLER_ADDRESS,%s", unit->cooler_address);
 		srv_send((char *)"COOLER_STATE,%d", unit->cooler_state);
@@ -1976,10 +1976,10 @@
 		srv_send((char *)"COOLER_USAGE,%d", unit->cooler_usage);
 		if (unit->PID_cool) {
 		    srv_send((char *)"PIDC_IMAX,%.1f", unit->PID_cool->iMax);
+		    srv_send((char *)"PIDC_IDLERANGE,%.2f", unit->PID_cool->idleRange);
 		    srv_send((char *)"PIDC_PGAIN,%.2f", unit->PID_cool->pGain);
 		    srv_send((char *)"PIDC_IGAIN,%.2f", unit->PID_cool->iGain);
 		    srv_send((char *)"PIDC_DGAIN,%.2f", unit->PID_cool->dGain);
-		    srv_send((char *)"PIDC_IDLERANGE,%.2f", unit->PID_cool->idleRange);
 		}
 		srv_send((char *)"FAN_ADDRESS,%s", unit->fan_address);
 		srv_send((char *)"FAN_STATE,%d", unit->fan_state);
--- a/thermferm/thermferm.c	Sun May 17 19:34:55 2015 +0200
+++ b/thermferm/thermferm.c	Sun May 17 23:23:25 2015 +0200
@@ -1399,39 +1399,43 @@
 		    /*
 		     * PID controller compute
 		     */
+		    UpdatePID(unit->PID_heat);
+		    UpdatePID(unit->PID_cool);
+
+		    /*
+		     * Logging
+		     */
 		    if (unit->heater_address) {
-			UpdatePID(unit->PID_heat);
-
 			if (debug)
 			    fprintf(stdout, "Heat: sp=%.2f Input=%.2f iState=%.2f Err=%.2f Out=%.2f\n",
 				unit->PID_heat->SetP, unit->PID_heat->Input, unit->PID_heat->iState, unit->PID_heat->Err, unit->PID_heat->OutP);
-			if (((unit->PID_heat->OutP >= 1) && unit->heater_address) || (seconds == 60) || unit->heater_state) {
+			if (((unit->PID_heat->OutP >= 2) && unit->heater_address) || (seconds == 60) || unit->heater_state) {
 			    syslog(LOG_NOTICE, "Heat: sp=%.2f Input=%.2f iState=%.2f Err=%.2f Out=%.2f",
 				unit->PID_heat->SetP, unit->PID_heat->Input, unit->PID_heat->iState, unit->PID_heat->Err, unit->PID_heat->OutP);
 			}
 		    }
 		    if (unit->cooler_address) {
-		    	UpdatePID(unit->PID_cool);
-
 		    	if (debug)
 			    fprintf(stdout, "Cool: sp=%.2f Input=%.2f iState=%.2f Err=%.2f Out=%.2f\n",
 				unit->PID_cool->SetP, unit->PID_cool->Input, unit->PID_cool->iState, unit->PID_cool->Err, unit->PID_cool->OutP);
-		    	if (((unit->PID_cool->OutP >= 1) && unit->cooler_address) || (seconds == 60) || unit->cooler_state) {
+		    	if (((unit->PID_cool->OutP >= 2) && unit->cooler_address) || (seconds == 60) || unit->cooler_state) {
 			    syslog(LOG_NOTICE, "Cool: sp=%.2f Input=%.2f iState=%.2f Err=%.2f Out=%.2f",
 				unit->PID_cool->SetP, unit->PID_cool->Input, unit->PID_cool->iState, unit->PID_cool->Err, unit->PID_cool->OutP);
 		    	}
 		    }
 
+		    /*
+		     * Deadlock
+		     */
 		    if (unit->PID_cool->OutP && unit->PID_heat->OutP) {
 			syslog(LOG_NOTICE, "Heat and Cool lockdown");
 			unit->PID_cool->OutP = unit->PID_heat->OutP = 0.0;
 		    }
 
 		    if (unit->heater_address && ! unit->cooler_state) {
-			if (unit->PID_heat->OutP >= 1) {
+			if (unit->PID_heat->OutP >= 2) {
 			    if (unit->heater_wait < unit->heater_delay) {
 				unit->heater_wait++;
-//				syslog(LOG_NOTICE, "heater_wait + %d/%d", unit->heater_wait, unit->heater_delay);
 			    } else {
 				int	power = round(unit->PID_heat->OutP);
 				if (unit->heater_state != power) {
@@ -1442,7 +1446,6 @@
 			} else {
 			    if (unit->heater_wait > 0) {
 				unit->heater_wait--;
-//				syslog(LOG_NOTICE, "heater_wait - %d/%d", unit->heater_wait, unit->heater_delay);
 			    } else {
 				if (unit->heater_state) {
 				    syslog(LOG_NOTICE, "Unit `%s' heater On => Off", unit->name);
@@ -1457,10 +1460,9 @@
 		    }
 
 		    if (unit->cooler_address && ! unit->heater_state) {
-			if (unit->PID_cool->OutP >= 1) {
+			if (unit->PID_cool->OutP >= 2) {
 			    if (unit->cooler_wait < unit->cooler_delay) {
 				unit->cooler_wait++;
-//				syslog(LOG_NOTICE, "cooler_wait + %d/%d", unit->cooler_wait, unit->cooler_delay);
 			    } else {
 				int	power = round(unit->PID_cool->OutP); 
 				if (unit->cooler_state != power) {
@@ -1471,7 +1473,6 @@
 			} else {
 			    if (unit->cooler_wait > 0) {
 				unit->cooler_wait--;
-//				syslog(LOG_NOTICE, "cooler_wait - %d/%d", unit->cooler_wait, unit->cooler_delay);
 			    } else {
 				if (unit->cooler_state) {
 				    syslog(LOG_NOTICE, "Unit `%s' cooler On => Off", unit->name);
--- a/www-thermferm/units.php	Sun May 17 19:34:55 2015 +0200
+++ b/www-thermferm/units.php	Sun May 17 23:23:25 2015 +0200
@@ -446,7 +446,7 @@
 	    }
 	    if ($f[0] == "PIDH_IDLERANGE") {
 		$outstr .= '       <tr class="editor">'.PHP_EOL;
-		$outstr .= '        <td class="editname">PID Heat Idle Range</td>'.PHP_EOL;
+		$outstr .= '        <td class="editname">Heater Idle Range</td>'.PHP_EOL;
 		$outstr .= '        <td class="editfield"><input type="text" name="PIDH_idleRange" size="6" value="'.$f[1].'"> &deg;C (Heater margin)</td>'.PHP_EOL;
 		$outstr .= '       </tr>'.PHP_EOL;
 	    }
@@ -503,7 +503,7 @@
 	    }
 	    if ($f[0] == "PIDC_IDLERANGE") {
 		$outstr .= '       <tr class="editor">'.PHP_EOL;
-		$outstr .= '        <td class="editname">PID Cool Idle Range</td>'.PHP_EOL;
+		$outstr .= '        <td class="editname">Cooler Idle Range</td>'.PHP_EOL;
 		$outstr .= '        <td class="editfield"><input type="text" name="PIDC_idleRange" size="6" value="'.$f[1].'"> &deg;C (Cooler margin)</td>'.PHP_EOL;
 		$outstr .= '       </tr>'.PHP_EOL;
 	    }

mercurial