Sat, 12 Dec 2015 19:31:35 +0100
Most parts of the simulator are working, needs some tuning.
brewco/README | file | annotate | diff | comparison | revisions | |
brewco/brewco.c | file | annotate | diff | comparison | revisions | |
brewco/brewco.h | file | annotate | diff | comparison | revisions | |
brewco/rdconfig.c | file | annotate | diff | comparison | revisions | |
brewco/simulator.c | file | annotate | diff | comparison | revisions |
--- a/brewco/README Fri Dec 11 15:52:37 2015 +0100 +++ b/brewco/README Sat Dec 12 19:31:35 2015 +0100 @@ -11,6 +11,13 @@ Default start, kies installatie. Tenzij een programma loopt (na een crash) start laatst gekozen installatie. +Extra t.o.v. ArdBir: hopstands. +1. 88..100 graden, 93 graden hold. +2. 71..77 graden +3. 60..66 graden +Inbouwn in Cooling. Timings: 1..4 uur. + + Menus: Buttons: Up Down Start Enter
--- a/brewco/brewco.c Fri Dec 11 15:52:37 2015 +0100 +++ b/brewco/brewco.c Sat Dec 12 19:31:35 2015 +0100 @@ -107,7 +107,7 @@ -void tempstatus(float hlttemp, float mlttemp) +void tempstatus(double hlttemp, double mlttemp) { char text[81]; @@ -132,10 +132,10 @@ -int manual_menu(units_list *); -int manual_menu(units_list *unit) +int manual_menu(units_list *, double, double); +int manual_menu(units_list *unit, double hlt, double mlt) { - int key; + int key, i; static int man_hlt_heat, man_mlt_heat, man_mlt_pump; switch (manual) { @@ -177,8 +177,15 @@ break; case MANUAL_HLT: prompt(104, NULL); prompt(413, NULL); - - key = keywait(); + tempstatus(*unit->PID_hlt->myInput, *unit->PID_mlt->myInput); + + for (i = 1; i < 100; i++) { + usleep(10000); + slcdDummy(slcdHandle); + key = keycheck(); + if ((key != KEY_NONE) || my_shutdown) + break; + } if (key == KEY_RETURN) { if (man_hlt_heat) man_hlt_heat = 0; @@ -195,7 +202,15 @@ break; case MANUAL_MLT: prompt(104, NULL); prompt(406, NULL); - key = keywait(); + tempstatus(*unit->PID_hlt->myInput, *unit->PID_mlt->myInput); + + for (i = 1; i < 100; i++) { + usleep(10000); + slcdDummy(slcdHandle); + key = keycheck(); + if ((key != KEY_NONE) || my_shutdown) + break; + } if (key == KEY_RETURN) { if (man_mlt_heat) man_mlt_heat = 0; @@ -225,14 +240,13 @@ int server(void); int server(void) { - int rc = 0, run = 1, key; + int rc = 0, run = 1, key, temp; int do_init = TRUE, seconds = 0, minutes = 0; units_list *unit; brew_session *brew = NULL; #ifndef HAVE_WIRINGPI_H long t = 0; #endif - struct tm *tm; time_t now, last = (time_t)0; static double hltInput, hltOutput, hltSetpoint, mltInput, mltOutput, mltSetpoint; @@ -426,7 +440,32 @@ */ last = now; seconds++; -fprintf(stdout, "1 second %ld millis\n", millis()); + if (seconds > 59) { + seconds = 0; + minutes++; + } + +fprintf(stdout, "%d seconds %d minutes %ld millis\n", seconds, minutes, millis()); + + rc = device_in(unit->hlt_sensor.uuid, &temp); + if (rc == DEVPRESENT_YES) { + hltInput = temp / 1000.0; + unit->hlt_sensor.state = 0; + } else if (rc == DEVPRESENT_ERROR) { + unit->hlt_sensor.state = 1; + } else { + unit->hlt_sensor.state = 2; + } + rc = device_in(unit->mlt_sensor.uuid, &temp); + if (rc == DEVPRESENT_YES) { + mltInput = temp / 1000.0; + unit->mlt_sensor.state = 0; + } else if (rc == DEVPRESENT_ERROR) { + unit->mlt_sensor.state = 1; + } else { + unit->mlt_sensor.state = 2; + } + if (debug && ((seconds % 10) == 1)) { fprintf(stdout, "MLT: In=%.2lf Out=%.2lf Set=%.2lf HLT: In=%.2lf Out=%.2lf Set=%.2lf\n", mltInput, mltOutput, mltSetpoint, hltInput, hltOutput, hltSetpoint); @@ -443,7 +482,7 @@ /* * Manual mode */ - manual_menu(unit); + manual_menu(unit, hltInput, mltInput); if (manual == MANUAL_NONE) { /* * Rewrite the display @@ -456,7 +495,7 @@ /* * Not running. */ - tempstatus(120.3, 165.34); + tempstatus(hltInput, mltInput); key = keycheck(); if (key == KEY_ENTER) { setup();
--- a/brewco/brewco.h Fri Dec 11 15:52:37 2015 +0100 +++ b/brewco/brewco.h Sat Dec 12 19:31:35 2015 +0100 @@ -241,20 +241,14 @@ double room_temperature; /* Simulated envionment temp */ double hlt_temperature; /* Simulated HLT temperature */ double hlt_heater_temp; /* Maximum heater temp */ - int hlt_heater_time; /* Time to reach temperature */ - float hlt_heater_size; /* Size of the heater */ + int hlt_heater_volume; /* Water volume */ + int hlt_heater_power; /* Power of the heater */ int hlt_heater_state; /* Heater status */ double mlt_temperature; /* Simulated MLT temperature */ double mlt_heater_temp; /* Maximum heater temp */ - int mlt_heater_time; /* Time to reach temperature */ - float mlt_heater_size; /* Size of the heater */ + int mlt_heater_volume; /* Water volume */ + int mlt_heater_power; /* Power of the heater */ int mlt_heater_state; /* Heater status */ - /* - * Status values, maintained by the simulator but stored - * here so they don't get lost over program restarts. - */ - double s_hlt_temp; /* Temp HLT */ - double s_mlt_temp; /* Temp MLT */ } simulator_var; #endif
--- a/brewco/rdconfig.c Fri Dec 11 15:52:37 2015 +0100 +++ b/brewco/rdconfig.c Sat Dec 12 19:31:35 2015 +0100 @@ -551,11 +551,11 @@ syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement"); return 1; } - if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "HLT_HEATER_TIME", "%d", Config.simulator->hlt_heater_time)) < 0) { + if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "HLT_HEATER_VOLUME", "%d", Config.simulator->hlt_heater_volume)) < 0) { syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement"); return 1; } - if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "HLT_HEATER_SIZE", "%f", Config.simulator->hlt_heater_size)) < 0) { + if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "HLT_HEATER_POWER", "%d", Config.simulator->hlt_heater_power)) < 0) { syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement"); return 1; } @@ -572,11 +572,11 @@ syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement"); return 1; } - if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "MLT_HEATER_TIME", "%d", Config.simulator->mlt_heater_time)) < 0) { + if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "MLT_HEATER_VOLUME", "%d", Config.simulator->mlt_heater_volume)) < 0) { syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement"); return 1; } - if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "MLT_HEATER_SIZE", "%f", Config.simulator->mlt_heater_size)) < 0) { + if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "MLT_HEATER_POWER", "%d", Config.simulator->mlt_heater_power)) < 0) { syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement"); return 1; } @@ -585,15 +585,6 @@ return 1; } - if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "S_HLT_TEMP", "%f", Config.simulator->s_hlt_temp)) < 0) { - syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement"); - return 1; - } - if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "S_MLT_TEMP", "%f", Config.simulator->s_mlt_temp)) < 0) { - syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement"); - return 1; - } - if ((rc = xmlTextWriterEndElement(writer)) < 0) { syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterEndElement"); return 1; @@ -1195,10 +1186,10 @@ if (! Config.simulator) { Config.simulator = (simulator_var *)malloc(sizeof(simulator_var)); Config.simulator->room_temperature = Config.simulator->hlt_temperature = Config.simulator->hlt_heater_temp = \ - Config.simulator->mlt_temperature = Config.simulator->mlt_heater_temp = \ - Config.simulator->s_hlt_temp = Config.simulator->s_mlt_temp = 0.0; - Config.simulator->hlt_heater_size = Config.simulator->mlt_heater_size = 0.0; - Config.simulator->hlt_heater_time = Config.simulator->mlt_heater_time = Config.simulator->hlt_heater_state = Config.simulator->mlt_heater_state = 0; + Config.simulator->mlt_temperature = Config.simulator->mlt_heater_temp = 20.0; + Config.simulator->hlt_heater_volume = Config.simulator->mlt_heater_volume = 20; + Config.simulator->hlt_heater_power = Config.simulator->mlt_heater_power = 2000; + Config.simulator->hlt_heater_state = Config.simulator->mlt_heater_state = 0; } cur = cur->xmlChildrenNode; @@ -1221,16 +1212,16 @@ Config.simulator->hlt_heater_temp = fval; xmlFree(key); } - if ((!xmlStrcmp(cur->name, (const xmlChar *)"HLT_HEATER_TIME"))) { + if ((!xmlStrcmp(cur->name, (const xmlChar *)"HLT_HEATER_VOLUME"))) { key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); if (sscanf((const char *)key, "%d", &ival) == 1) - Config.simulator->hlt_heater_time = ival; + Config.simulator->hlt_heater_volume = ival; xmlFree(key); } - if ((!xmlStrcmp(cur->name, (const xmlChar *)"HLT_HEATER_SIZE"))) { + if ((!xmlStrcmp(cur->name, (const xmlChar *)"HLT_HEATER_POWER"))) { key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (sscanf((const char *)key, "%f", &fval) == 1) - Config.simulator->hlt_heater_size = fval; + if (sscanf((const char *)key, "%d", &ival) == 1) + Config.simulator->hlt_heater_power = ival; xmlFree(key); } if ((!xmlStrcmp(cur->name, (const xmlChar *)"HLT_HEATER_STATE"))) { @@ -1251,16 +1242,16 @@ Config.simulator->mlt_heater_temp = fval; xmlFree(key); } - if ((!xmlStrcmp(cur->name, (const xmlChar *)"MLT_HEATER_TIME"))) { + if ((!xmlStrcmp(cur->name, (const xmlChar *)"MLT_HEATER_VOLUME"))) { key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); if (sscanf((const char *)key, "%d", &ival) == 1) - Config.simulator->mlt_heater_time = ival; + Config.simulator->mlt_heater_volume = ival; xmlFree(key); } - if ((!xmlStrcmp(cur->name, (const xmlChar *)"MLT_HEATER_SIZE"))) { + if ((!xmlStrcmp(cur->name, (const xmlChar *)"MLT_HEATER_POWER"))) { key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (sscanf((const char *)key, "%f", &fval) == 1) - Config.simulator->mlt_heater_size = fval; + if (sscanf((const char *)key, "%d", &ival) == 1) + Config.simulator->mlt_heater_power = ival; xmlFree(key); } if ((!xmlStrcmp(cur->name, (const xmlChar *)"MLT_HEATER_STATE"))) { @@ -1269,18 +1260,6 @@ Config.simulator->mlt_heater_state = ival; xmlFree(key); } - if ((!xmlStrcmp(cur->name, (const xmlChar *)"S_HLT_TEMP"))) { - key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (sscanf((const char *)key, "%f", &fval) == 1) - Config.simulator->s_hlt_temp = fval; - xmlFree(key); - } - if ((!xmlStrcmp(cur->name, (const xmlChar *)"S_MLT_TEMP"))) { - key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (sscanf((const char *)key, "%f", &fval) == 1) - Config.simulator->s_mlt_temp = fval; - xmlFree(key); - } cur = cur->next; } @@ -1404,10 +1383,10 @@ Config.simulator = (simulator_var *)malloc(sizeof(simulator_var)); syslog(LOG_NOTICE, "rdconfig() init a new simulator"); Config.simulator->room_temperature = Config.simulator->hlt_temperature = Config.simulator->hlt_heater_temp = \ - Config.simulator->mlt_temperature = Config.simulator->mlt_heater_temp = \ - Config.simulator->s_hlt_temp = Config.simulator->s_mlt_temp = 20.0; - Config.simulator->hlt_heater_size = Config.simulator->mlt_heater_size = 0.0; - Config.simulator->hlt_heater_time = Config.simulator->mlt_heater_time = Config.simulator->hlt_heater_state = Config.simulator->mlt_heater_state = 0; + Config.simulator->mlt_temperature = Config.simulator->mlt_heater_temp = 20.0; + Config.simulator->hlt_heater_volume = Config.simulator->mlt_heater_volume = 20; + Config.simulator->hlt_heater_power = Config.simulator->mlt_heater_power = 2000; + Config.simulator->hlt_heater_state = Config.simulator->mlt_heater_state = 0; } #endif
--- a/brewco/simulator.c Fri Dec 11 15:52:37 2015 +0100 +++ b/brewco/simulator.c Sat Dec 12 19:31:35 2015 +0100 @@ -39,8 +39,8 @@ void *my_simulator_loop(void *threadid) #endif { - time_t now, last = (time_t)0; - int seconds = 0; + time_t now, last; + int loops = 0; // double hlt_heat_transfer, mlt_heat_transfer; // double vhc_air = 0.00121, vhc_water = 4.1796; @@ -49,52 +49,72 @@ fprintf(stdout, "Thread my_simulator_loop started\n"); /* - * Heater and cooler have the air temperature + * Initial temperatures */ - Config.simulator->hlt_heater_temp = Config.simulator->mlt_heater_temp = Config.simulator->room_temperature; + Config.simulator->hlt_heater_temp = Config.simulator->hlt_temperature; + Config.simulator->mlt_heater_temp = Config.simulator->mlt_temperature; + last = now = time(NULL); + /* + * About 50 mSec loops + */ for (;;) { if (my_shutdown) break; + /* + * First calculate the heat loss for the HLT and MLT liquids. + * Then decrease both liquid temperatures and consider the volume. + */ + Config.simulator->hlt_temperature -= (Config.simulator->hlt_temperature - Config.simulator->room_temperature) / + (40000 * (Config.simulator->hlt_heater_volume / 2)); + Config.simulator->mlt_temperature -= (Config.simulator->mlt_temperature - Config.simulator->room_temperature) / + (40000 * (Config.simulator->mlt_heater_volume / 2)); + + /* + * If heating, calculate the heating element temperature but not higher then 250 degrees celcius. + * I have no data about real temperatures of electric elements, so this is a rough guess. + * If not heating, the elements are couling towards the current liquid temperature. + */ + Config.simulator->hlt_heater_state = SIM_hlt_value; + if (SIM_hlt_value) { + Config.simulator->hlt_heater_temp += (250 - Config.simulator->hlt_heater_temp) / 2000; + } else { + Config.simulator->hlt_heater_temp -= (Config.simulator->hlt_heater_temp - Config.simulator->hlt_temperature) / 1000; + } + Config.simulator->mlt_heater_state = SIM_mlt_value; + if (SIM_mlt_value) { + Config.simulator->mlt_heater_temp += (250 - Config.simulator->mlt_heater_temp) / 2000; + } else { + Config.simulator->mlt_heater_temp -= (Config.simulator->mlt_heater_temp - Config.simulator->mlt_temperature) / 1000; + } + + /* + * Shift the liquid temperature towards the heating elements temperature, + * but never higher then 100 degrees celcius. + */ + Config.simulator->hlt_temperature += (Config.simulator->hlt_heater_temp - Config.simulator->hlt_temperature) / (10000 * Config.simulator->hlt_heater_volume); + if (Config.simulator->hlt_temperature > 100.25) + Config.simulator->hlt_temperature = 100.25; + Config.simulator->mlt_temperature += (Config.simulator->mlt_heater_temp - Config.simulator->mlt_temperature) / (10000 * Config.simulator->mlt_heater_volume); + if (Config.simulator->mlt_temperature > 100.25) + Config.simulator->mlt_temperature = 100.25; + + loops++; now = time(NULL); if (now != last) { last = now; /* * Each second */ - seconds++; - - /* - * First calculate the heat loss for the HLT and MLT liquids. - * Then decrease both liquid temperatures. - */ - - /* - * If heating, calculate the heating element temperature. - * If not heating, shift towards the liquid temperature. - */ - - /* - * Shift the liquid temperature towards the heating elements temperature, - * but never higher then 100 degrees celcius. - */ - - /* - * If heating, calculate temperature of the heating plate. If heating is off but - * the plate is warmer then the air, calculate the cooling down temperature. - * Finally, calculate the new air and plate temperature. - */ - -// syslog(LOG_NOTICE, "air=%.3f beer=%.3f heater=%.3f cooler=%.3f", simulator->air_temperature, simulator->beer_temperature, -// simulator->s_heat_temp, simulator->s_cool_temp); - -// if (debug) -// fprintf(stdout, "sqm_room_air=%f air=%f air_heat_transfer=%f air_change=%f sqm_beer_air=%f beer=%f beer_heat_transfer=%f\n", -// sqm_room_air, simulator->air_temperature, air_heat_transfer, air_change, -// sqm_beer_air, simulator->beer_temperature, beer_heat_transfer); + if (debug) + fprintf(stdout, "HLT temp=%f plate=%f val=%d MLT temp=%f plate=%f val=%d Room %.1f loops=%d\n", + Config.simulator->hlt_temperature, Config.simulator->hlt_heater_temp, Config.simulator->hlt_heater_state, + Config.simulator->mlt_temperature, Config.simulator->mlt_heater_temp, Config.simulator->mlt_heater_state, + Config.simulator->room_temperature, loops); + loops = 0; } - usleep(100000); + usleep(50000); } syslog(LOG_NOTICE, "Thread my_simulator_loop stopped");