thermferm/thermferm.c

changeset 364
2f9bbbcd2407
parent 363
468ec0d96cce
child 367
b9130db48c63
equal deleted inserted replaced
363:468ec0d96cce 364:2f9bbbcd2407
1397 } 1397 }
1398 1398
1399 /* 1399 /*
1400 * PID controller compute 1400 * PID controller compute
1401 */ 1401 */
1402 UpdatePID(unit->PID_heat);
1403 UpdatePID(unit->PID_cool);
1404
1405 /*
1406 * Logging
1407 */
1402 if (unit->heater_address) { 1408 if (unit->heater_address) {
1403 UpdatePID(unit->PID_heat);
1404
1405 if (debug) 1409 if (debug)
1406 fprintf(stdout, "Heat: sp=%.2f Input=%.2f iState=%.2f Err=%.2f Out=%.2f\n", 1410 fprintf(stdout, "Heat: sp=%.2f Input=%.2f iState=%.2f Err=%.2f Out=%.2f\n",
1407 unit->PID_heat->SetP, unit->PID_heat->Input, unit->PID_heat->iState, unit->PID_heat->Err, unit->PID_heat->OutP); 1411 unit->PID_heat->SetP, unit->PID_heat->Input, unit->PID_heat->iState, unit->PID_heat->Err, unit->PID_heat->OutP);
1408 if (((unit->PID_heat->OutP >= 1) && unit->heater_address) || (seconds == 60) || unit->heater_state) { 1412 if (((unit->PID_heat->OutP >= 2) && unit->heater_address) || (seconds == 60) || unit->heater_state) {
1409 syslog(LOG_NOTICE, "Heat: sp=%.2f Input=%.2f iState=%.2f Err=%.2f Out=%.2f", 1413 syslog(LOG_NOTICE, "Heat: sp=%.2f Input=%.2f iState=%.2f Err=%.2f Out=%.2f",
1410 unit->PID_heat->SetP, unit->PID_heat->Input, unit->PID_heat->iState, unit->PID_heat->Err, unit->PID_heat->OutP); 1414 unit->PID_heat->SetP, unit->PID_heat->Input, unit->PID_heat->iState, unit->PID_heat->Err, unit->PID_heat->OutP);
1411 } 1415 }
1412 } 1416 }
1413 if (unit->cooler_address) { 1417 if (unit->cooler_address) {
1414 UpdatePID(unit->PID_cool);
1415
1416 if (debug) 1418 if (debug)
1417 fprintf(stdout, "Cool: sp=%.2f Input=%.2f iState=%.2f Err=%.2f Out=%.2f\n", 1419 fprintf(stdout, "Cool: sp=%.2f Input=%.2f iState=%.2f Err=%.2f Out=%.2f\n",
1418 unit->PID_cool->SetP, unit->PID_cool->Input, unit->PID_cool->iState, unit->PID_cool->Err, unit->PID_cool->OutP); 1420 unit->PID_cool->SetP, unit->PID_cool->Input, unit->PID_cool->iState, unit->PID_cool->Err, unit->PID_cool->OutP);
1419 if (((unit->PID_cool->OutP >= 1) && unit->cooler_address) || (seconds == 60) || unit->cooler_state) { 1421 if (((unit->PID_cool->OutP >= 2) && unit->cooler_address) || (seconds == 60) || unit->cooler_state) {
1420 syslog(LOG_NOTICE, "Cool: sp=%.2f Input=%.2f iState=%.2f Err=%.2f Out=%.2f", 1422 syslog(LOG_NOTICE, "Cool: sp=%.2f Input=%.2f iState=%.2f Err=%.2f Out=%.2f",
1421 unit->PID_cool->SetP, unit->PID_cool->Input, unit->PID_cool->iState, unit->PID_cool->Err, unit->PID_cool->OutP); 1423 unit->PID_cool->SetP, unit->PID_cool->Input, unit->PID_cool->iState, unit->PID_cool->Err, unit->PID_cool->OutP);
1422 } 1424 }
1423 } 1425 }
1424 1426
1427 /*
1428 * Deadlock
1429 */
1425 if (unit->PID_cool->OutP && unit->PID_heat->OutP) { 1430 if (unit->PID_cool->OutP && unit->PID_heat->OutP) {
1426 syslog(LOG_NOTICE, "Heat and Cool lockdown"); 1431 syslog(LOG_NOTICE, "Heat and Cool lockdown");
1427 unit->PID_cool->OutP = unit->PID_heat->OutP = 0.0; 1432 unit->PID_cool->OutP = unit->PID_heat->OutP = 0.0;
1428 } 1433 }
1429 1434
1430 if (unit->heater_address && ! unit->cooler_state) { 1435 if (unit->heater_address && ! unit->cooler_state) {
1431 if (unit->PID_heat->OutP >= 1) { 1436 if (unit->PID_heat->OutP >= 2) {
1432 if (unit->heater_wait < unit->heater_delay) { 1437 if (unit->heater_wait < unit->heater_delay) {
1433 unit->heater_wait++; 1438 unit->heater_wait++;
1434 // syslog(LOG_NOTICE, "heater_wait + %d/%d", unit->heater_wait, unit->heater_delay);
1435 } else { 1439 } else {
1436 int power = round(unit->PID_heat->OutP); 1440 int power = round(unit->PID_heat->OutP);
1437 if (unit->heater_state != power) { 1441 if (unit->heater_state != power) {
1438 syslog(LOG_NOTICE, "Unit `%s' heater %d%% => %d%%", unit->name, unit->heater_state, power); 1442 syslog(LOG_NOTICE, "Unit `%s' heater %d%% => %d%%", unit->name, unit->heater_state, power);
1439 unit->heater_state = power; 1443 unit->heater_state = power;
1440 } 1444 }
1441 } 1445 }
1442 } else { 1446 } else {
1443 if (unit->heater_wait > 0) { 1447 if (unit->heater_wait > 0) {
1444 unit->heater_wait--; 1448 unit->heater_wait--;
1445 // syslog(LOG_NOTICE, "heater_wait - %d/%d", unit->heater_wait, unit->heater_delay);
1446 } else { 1449 } else {
1447 if (unit->heater_state) { 1450 if (unit->heater_state) {
1448 syslog(LOG_NOTICE, "Unit `%s' heater On => Off", unit->name); 1451 syslog(LOG_NOTICE, "Unit `%s' heater On => Off", unit->name);
1449 unit->heater_state = 0; 1452 unit->heater_state = 0;
1450 } 1453 }
1455 else 1458 else
1456 device_out(unit->heater_address, 0); 1459 device_out(unit->heater_address, 0);
1457 } 1460 }
1458 1461
1459 if (unit->cooler_address && ! unit->heater_state) { 1462 if (unit->cooler_address && ! unit->heater_state) {
1460 if (unit->PID_cool->OutP >= 1) { 1463 if (unit->PID_cool->OutP >= 2) {
1461 if (unit->cooler_wait < unit->cooler_delay) { 1464 if (unit->cooler_wait < unit->cooler_delay) {
1462 unit->cooler_wait++; 1465 unit->cooler_wait++;
1463 // syslog(LOG_NOTICE, "cooler_wait + %d/%d", unit->cooler_wait, unit->cooler_delay);
1464 } else { 1466 } else {
1465 int power = round(unit->PID_cool->OutP); 1467 int power = round(unit->PID_cool->OutP);
1466 if (unit->cooler_state != power) { 1468 if (unit->cooler_state != power) {
1467 syslog(LOG_NOTICE, "Unit `%s' cooler %d%% => %d%%", unit->name, unit->cooler_state, power); 1469 syslog(LOG_NOTICE, "Unit `%s' cooler %d%% => %d%%", unit->name, unit->cooler_state, power);
1468 unit->cooler_state = power; 1470 unit->cooler_state = power;
1469 } 1471 }
1470 } 1472 }
1471 } else { 1473 } else {
1472 if (unit->cooler_wait > 0) { 1474 if (unit->cooler_wait > 0) {
1473 unit->cooler_wait--; 1475 unit->cooler_wait--;
1474 // syslog(LOG_NOTICE, "cooler_wait - %d/%d", unit->cooler_wait, unit->cooler_delay);
1475 } else { 1476 } else {
1476 if (unit->cooler_state) { 1477 if (unit->cooler_state) {
1477 syslog(LOG_NOTICE, "Unit `%s' cooler On => Off", unit->name); 1478 syslog(LOG_NOTICE, "Unit `%s' cooler On => Off", unit->name);
1478 unit->cooler_state = 0; 1479 unit->cooler_state = 0;
1479 } 1480 }

mercurial