Wed, 31 May 2017 16:29:52 +0200
Small web page changes
259
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
1 | /***************************************************************************** |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
2 | * Copyright (C) 2008-2014 |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
3 | * |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
4 | * Michiel Broek <mbroek at mbse dot eu> |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
5 | * |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
6 | * This file is part of the mbsePi-apps |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
7 | * |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
8 | * This is free software; you can redistribute it and/or modify it |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
9 | * under the terms of the GNU General Public License as published by the |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
10 | * Free Software Foundation; either version 2, or (at your option) any |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
11 | * later version. |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
12 | * |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
13 | * mbsePi-apps is distributed in the hope that it will be useful, but |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
16 | * General Public License for more details. |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
17 | * |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
18 | * You should have received a copy of the GNU General Public License |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
19 | * along with ThermFerm; see the file COPYING. If not, write to the Free |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
20 | * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
21 | *****************************************************************************/ |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
22 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
23 | #include "thermferm.h" |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
24 | #include "simulator.h" |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
25 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
26 | #ifdef USE_SIMULATOR |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
27 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
28 | extern int my_shutdown; |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
29 | extern int debug; |
262
d0014ccec615
Simulation of fridge cold loss to the room added for testing.
Michiel Broek <mbroek@mbse.eu>
parents:
259
diff
changeset
|
30 | extern sys_config Config; |
259
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
31 | |
362
c92651a54969
Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents:
265
diff
changeset
|
32 | int SIMcooling = 0; |
c92651a54969
Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents:
265
diff
changeset
|
33 | int SIMheating = 0; |
259
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
34 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
35 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
36 | #ifdef HAVE_WIRINGPI_H |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
37 | PI_THREAD (my_simulator_loop) |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
38 | #else |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
39 | void *my_simulator_loop(void *threadid) |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
40 | #endif |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
41 | { |
262
d0014ccec615
Simulation of fridge cold loss to the room added for testing.
Michiel Broek <mbroek@mbse.eu>
parents:
259
diff
changeset
|
42 | simulator_list *simulator; |
d0014ccec615
Simulation of fridge cold loss to the room added for testing.
Michiel Broek <mbroek@mbse.eu>
parents:
259
diff
changeset
|
43 | time_t now, last = (time_t)0; |
d0014ccec615
Simulation of fridge cold loss to the room added for testing.
Michiel Broek <mbroek@mbse.eu>
parents:
259
diff
changeset
|
44 | int seconds = 0; |
265
63a003914b72
More math for the simulator. Web interface changes for heater in graph.
Michiel Broek <mbroek@mbse.eu>
parents:
264
diff
changeset
|
45 | double k_room_air, k_beer_air, sqm_room_air, sqm_beer_air, thick_room_air, thick_beer_air, air_heat_transfer, beer_heat_transfer; |
365
df0261bb3feb
Version 0.3.3, still not for production. Fixed warnings when the simulator code is compiled. Slowed the simulator air temperature change 60 times. More realistic temperature changes for the heater and cooler elements. Improved logic in the simulator.
Michiel Broek <mbroek@mbse.eu>
parents:
363
diff
changeset
|
46 | double air_change, /* beer_change, */ vhc_air = 0.00121 /*, vhc_water = 4.1796 */; |
259
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
47 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
48 | syslog(LOG_NOTICE, "Thread my_simulator_loop started"); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
49 | if (debug) |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
50 | fprintf(stdout, "Thread my_simulator_loop started\n"); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
51 | |
363
468ec0d96cce
Back to the old PID algorythm. Version 0.3.1.
Michiel Broek <mbroek@mbse.eu>
parents:
362
diff
changeset
|
52 | for (simulator = Config.simulators; simulator; simulator = simulator->next) { |
468ec0d96cce
Back to the old PID algorythm. Version 0.3.1.
Michiel Broek <mbroek@mbse.eu>
parents:
362
diff
changeset
|
53 | /* |
468ec0d96cce
Back to the old PID algorythm. Version 0.3.1.
Michiel Broek <mbroek@mbse.eu>
parents:
362
diff
changeset
|
54 | * Heater and cooler have the air temperature |
468ec0d96cce
Back to the old PID algorythm. Version 0.3.1.
Michiel Broek <mbroek@mbse.eu>
parents:
362
diff
changeset
|
55 | */ |
468ec0d96cce
Back to the old PID algorythm. Version 0.3.1.
Michiel Broek <mbroek@mbse.eu>
parents:
362
diff
changeset
|
56 | simulator->s_heat_temp = simulator->s_cool_temp = simulator->room_temperature; |
468ec0d96cce
Back to the old PID algorythm. Version 0.3.1.
Michiel Broek <mbroek@mbse.eu>
parents:
362
diff
changeset
|
57 | } |
468ec0d96cce
Back to the old PID algorythm. Version 0.3.1.
Michiel Broek <mbroek@mbse.eu>
parents:
362
diff
changeset
|
58 | |
259
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
59 | for (;;) { |
497
18ace27338e5
Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents:
366
diff
changeset
|
60 | if (my_shutdown) |
18ace27338e5
Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents:
366
diff
changeset
|
61 | break; |
18ace27338e5
Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents:
366
diff
changeset
|
62 | |
262
d0014ccec615
Simulation of fridge cold loss to the room added for testing.
Michiel Broek <mbroek@mbse.eu>
parents:
259
diff
changeset
|
63 | for (simulator = Config.simulators; simulator; simulator = simulator->next) { |
d0014ccec615
Simulation of fridge cold loss to the room added for testing.
Michiel Broek <mbroek@mbse.eu>
parents:
259
diff
changeset
|
64 | if (my_shutdown) |
d0014ccec615
Simulation of fridge cold loss to the room added for testing.
Michiel Broek <mbroek@mbse.eu>
parents:
259
diff
changeset
|
65 | break; |
259
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
66 | |
262
d0014ccec615
Simulation of fridge cold loss to the room added for testing.
Michiel Broek <mbroek@mbse.eu>
parents:
259
diff
changeset
|
67 | now = time(NULL); |
d0014ccec615
Simulation of fridge cold loss to the room added for testing.
Michiel Broek <mbroek@mbse.eu>
parents:
259
diff
changeset
|
68 | if (now != last) { |
d0014ccec615
Simulation of fridge cold loss to the room added for testing.
Michiel Broek <mbroek@mbse.eu>
parents:
259
diff
changeset
|
69 | last = now; |
d0014ccec615
Simulation of fridge cold loss to the room added for testing.
Michiel Broek <mbroek@mbse.eu>
parents:
259
diff
changeset
|
70 | /* |
d0014ccec615
Simulation of fridge cold loss to the room added for testing.
Michiel Broek <mbroek@mbse.eu>
parents:
259
diff
changeset
|
71 | * Each second |
d0014ccec615
Simulation of fridge cold loss to the room added for testing.
Michiel Broek <mbroek@mbse.eu>
parents:
259
diff
changeset
|
72 | */ |
d0014ccec615
Simulation of fridge cold loss to the room added for testing.
Michiel Broek <mbroek@mbse.eu>
parents:
259
diff
changeset
|
73 | seconds++; |
d0014ccec615
Simulation of fridge cold loss to the room added for testing.
Michiel Broek <mbroek@mbse.eu>
parents:
259
diff
changeset
|
74 | |
d0014ccec615
Simulation of fridge cold loss to the room added for testing.
Michiel Broek <mbroek@mbse.eu>
parents:
259
diff
changeset
|
75 | /* |
d0014ccec615
Simulation of fridge cold loss to the room added for testing.
Michiel Broek <mbroek@mbse.eu>
parents:
259
diff
changeset
|
76 | * First, calculate temperature difference between the room and the air in the |
d0014ccec615
Simulation of fridge cold loss to the room added for testing.
Michiel Broek <mbroek@mbse.eu>
parents:
259
diff
changeset
|
77 | * fridge. We use the volume air to roughly calculate the total area between |
d0014ccec615
Simulation of fridge cold loss to the room added for testing.
Michiel Broek <mbroek@mbse.eu>
parents:
259
diff
changeset
|
78 | * the in and outside. Calculate the effect and shift the air temperature towards |
d0014ccec615
Simulation of fridge cold loss to the room added for testing.
Michiel Broek <mbroek@mbse.eu>
parents:
259
diff
changeset
|
79 | * the room temperature. |
d0014ccec615
Simulation of fridge cold loss to the room added for testing.
Michiel Broek <mbroek@mbse.eu>
parents:
259
diff
changeset
|
80 | */ |
d0014ccec615
Simulation of fridge cold loss to the room added for testing.
Michiel Broek <mbroek@mbse.eu>
parents:
259
diff
changeset
|
81 | sqm_room_air = (cbrtl(simulator->volume_air) * cbrtl(simulator->volume_air) * 6) / 100; /* square meters all fridge sides */ |
264
91c358556ecf
LIST LOG also output lines on state changes
Michiel Broek <mbroek@mbse.eu>
parents:
263
diff
changeset
|
82 | thick_room_air = 0.04; /* 4 cm walls */ |
262
d0014ccec615
Simulation of fridge cold loss to the room added for testing.
Michiel Broek <mbroek@mbse.eu>
parents:
259
diff
changeset
|
83 | k_room_air = 0.03; /* Polystrene */ |
265
63a003914b72
More math for the simulator. Web interface changes for heater in graph.
Michiel Broek <mbroek@mbse.eu>
parents:
264
diff
changeset
|
84 | air_heat_transfer=(k_room_air * sqm_room_air * (simulator->room_temperature - simulator->air_temperature)) / thick_room_air; |
365
df0261bb3feb
Version 0.3.3, still not for production. Fixed warnings when the simulator code is compiled. Slowed the simulator air temperature change 60 times. More realistic temperature changes for the heater and cooler elements. Improved logic in the simulator.
Michiel Broek <mbroek@mbse.eu>
parents:
363
diff
changeset
|
85 | air_change = (air_heat_transfer / (vhc_air * ((simulator->volume_air - simulator->volume_beer) * 1000))) / 60.0; |
265
63a003914b72
More math for the simulator. Web interface changes for heater in graph.
Michiel Broek <mbroek@mbse.eu>
parents:
264
diff
changeset
|
86 | simulator->air_temperature += air_change; |
259
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
87 | |
262
d0014ccec615
Simulation of fridge cold loss to the room added for testing.
Michiel Broek <mbroek@mbse.eu>
parents:
259
diff
changeset
|
88 | /* |
d0014ccec615
Simulation of fridge cold loss to the room added for testing.
Michiel Broek <mbroek@mbse.eu>
parents:
259
diff
changeset
|
89 | * If heating, calculate temperature of the heating plate. If heating is off but |
d0014ccec615
Simulation of fridge cold loss to the room added for testing.
Michiel Broek <mbroek@mbse.eu>
parents:
259
diff
changeset
|
90 | * the plate is warmer then the air, calculate the cooling down temperature. |
d0014ccec615
Simulation of fridge cold loss to the room added for testing.
Michiel Broek <mbroek@mbse.eu>
parents:
259
diff
changeset
|
91 | * Finally, calculate the new air and plate temperature. |
d0014ccec615
Simulation of fridge cold loss to the room added for testing.
Michiel Broek <mbroek@mbse.eu>
parents:
259
diff
changeset
|
92 | */ |
362
c92651a54969
Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents:
265
diff
changeset
|
93 | if (SIMheating) { |
365
df0261bb3feb
Version 0.3.3, still not for production. Fixed warnings when the simulator code is compiled. Slowed the simulator air temperature change 60 times. More realistic temperature changes for the heater and cooler elements. Improved logic in the simulator.
Michiel Broek <mbroek@mbse.eu>
parents:
363
diff
changeset
|
94 | if (simulator->s_heat_temp < simulator->heater_temp) { |
363
468ec0d96cce
Back to the old PID algorythm. Version 0.3.1.
Michiel Broek <mbroek@mbse.eu>
parents:
362
diff
changeset
|
95 | simulator->s_heat_temp += 0.05; |
365
df0261bb3feb
Version 0.3.3, still not for production. Fixed warnings when the simulator code is compiled. Slowed the simulator air temperature change 60 times. More realistic temperature changes for the heater and cooler elements. Improved logic in the simulator.
Michiel Broek <mbroek@mbse.eu>
parents:
363
diff
changeset
|
96 | if (simulator->s_heat_temp > simulator->air_temperature) |
df0261bb3feb
Version 0.3.3, still not for production. Fixed warnings when the simulator code is compiled. Slowed the simulator air temperature change 60 times. More realistic temperature changes for the heater and cooler elements. Improved logic in the simulator.
Michiel Broek <mbroek@mbse.eu>
parents:
363
diff
changeset
|
97 | simulator->air_temperature += ((simulator->s_heat_temp - simulator->air_temperature) / 100.0); |
df0261bb3feb
Version 0.3.3, still not for production. Fixed warnings when the simulator code is compiled. Slowed the simulator air temperature change 60 times. More realistic temperature changes for the heater and cooler elements. Improved logic in the simulator.
Michiel Broek <mbroek@mbse.eu>
parents:
363
diff
changeset
|
98 | } |
363
468ec0d96cce
Back to the old PID algorythm. Version 0.3.1.
Michiel Broek <mbroek@mbse.eu>
parents:
362
diff
changeset
|
99 | } else { |
365
df0261bb3feb
Version 0.3.3, still not for production. Fixed warnings when the simulator code is compiled. Slowed the simulator air temperature change 60 times. More realistic temperature changes for the heater and cooler elements. Improved logic in the simulator.
Michiel Broek <mbroek@mbse.eu>
parents:
363
diff
changeset
|
100 | /* |
df0261bb3feb
Version 0.3.3, still not for production. Fixed warnings when the simulator code is compiled. Slowed the simulator air temperature change 60 times. More realistic temperature changes for the heater and cooler elements. Improved logic in the simulator.
Michiel Broek <mbroek@mbse.eu>
parents:
363
diff
changeset
|
101 | * Follow the air temperature |
df0261bb3feb
Version 0.3.3, still not for production. Fixed warnings when the simulator code is compiled. Slowed the simulator air temperature change 60 times. More realistic temperature changes for the heater and cooler elements. Improved logic in the simulator.
Michiel Broek <mbroek@mbse.eu>
parents:
363
diff
changeset
|
102 | */ |
df0261bb3feb
Version 0.3.3, still not for production. Fixed warnings when the simulator code is compiled. Slowed the simulator air temperature change 60 times. More realistic temperature changes for the heater and cooler elements. Improved logic in the simulator.
Michiel Broek <mbroek@mbse.eu>
parents:
363
diff
changeset
|
103 | simulator->s_heat_temp -= (simulator->s_heat_temp - simulator->air_temperature) / 25.0; |
362
c92651a54969
Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents:
265
diff
changeset
|
104 | } |
262
d0014ccec615
Simulation of fridge cold loss to the room added for testing.
Michiel Broek <mbroek@mbse.eu>
parents:
259
diff
changeset
|
105 | |
d0014ccec615
Simulation of fridge cold loss to the room added for testing.
Michiel Broek <mbroek@mbse.eu>
parents:
259
diff
changeset
|
106 | /* |
d0014ccec615
Simulation of fridge cold loss to the room added for testing.
Michiel Broek <mbroek@mbse.eu>
parents:
259
diff
changeset
|
107 | * If cooling, calculate temperature of the cooling plate. If cooling is off but |
d0014ccec615
Simulation of fridge cold loss to the room added for testing.
Michiel Broek <mbroek@mbse.eu>
parents:
259
diff
changeset
|
108 | * the plate is colder then the air, calculate the warming up temperature. |
d0014ccec615
Simulation of fridge cold loss to the room added for testing.
Michiel Broek <mbroek@mbse.eu>
parents:
259
diff
changeset
|
109 | * Finsally, calculate the new air and plate temperature. |
d0014ccec615
Simulation of fridge cold loss to the room added for testing.
Michiel Broek <mbroek@mbse.eu>
parents:
259
diff
changeset
|
110 | */ |
362
c92651a54969
Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents:
265
diff
changeset
|
111 | if (SIMcooling) { |
365
df0261bb3feb
Version 0.3.3, still not for production. Fixed warnings when the simulator code is compiled. Slowed the simulator air temperature change 60 times. More realistic temperature changes for the heater and cooler elements. Improved logic in the simulator.
Michiel Broek <mbroek@mbse.eu>
parents:
363
diff
changeset
|
112 | if (simulator->s_cool_temp > simulator->cooler_temp) { |
363
468ec0d96cce
Back to the old PID algorythm. Version 0.3.1.
Michiel Broek <mbroek@mbse.eu>
parents:
362
diff
changeset
|
113 | simulator->s_cool_temp -= 0.05; |
365
df0261bb3feb
Version 0.3.3, still not for production. Fixed warnings when the simulator code is compiled. Slowed the simulator air temperature change 60 times. More realistic temperature changes for the heater and cooler elements. Improved logic in the simulator.
Michiel Broek <mbroek@mbse.eu>
parents:
363
diff
changeset
|
114 | if (simulator->s_cool_temp < simulator->air_temperature) |
df0261bb3feb
Version 0.3.3, still not for production. Fixed warnings when the simulator code is compiled. Slowed the simulator air temperature change 60 times. More realistic temperature changes for the heater and cooler elements. Improved logic in the simulator.
Michiel Broek <mbroek@mbse.eu>
parents:
363
diff
changeset
|
115 | simulator->air_temperature -= ((simulator->air_temperature - simulator->s_cool_temp) / 100.0); |
df0261bb3feb
Version 0.3.3, still not for production. Fixed warnings when the simulator code is compiled. Slowed the simulator air temperature change 60 times. More realistic temperature changes for the heater and cooler elements. Improved logic in the simulator.
Michiel Broek <mbroek@mbse.eu>
parents:
363
diff
changeset
|
116 | } |
363
468ec0d96cce
Back to the old PID algorythm. Version 0.3.1.
Michiel Broek <mbroek@mbse.eu>
parents:
362
diff
changeset
|
117 | } else { |
365
df0261bb3feb
Version 0.3.3, still not for production. Fixed warnings when the simulator code is compiled. Slowed the simulator air temperature change 60 times. More realistic temperature changes for the heater and cooler elements. Improved logic in the simulator.
Michiel Broek <mbroek@mbse.eu>
parents:
363
diff
changeset
|
118 | simulator->s_cool_temp -= (simulator->s_cool_temp - simulator->air_temperature) / 25.0; |
362
c92651a54969
Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents:
265
diff
changeset
|
119 | } |
262
d0014ccec615
Simulation of fridge cold loss to the room added for testing.
Michiel Broek <mbroek@mbse.eu>
parents:
259
diff
changeset
|
120 | |
d0014ccec615
Simulation of fridge cold loss to the room added for testing.
Michiel Broek <mbroek@mbse.eu>
parents:
259
diff
changeset
|
121 | /* |
d0014ccec615
Simulation of fridge cold loss to the room added for testing.
Michiel Broek <mbroek@mbse.eu>
parents:
259
diff
changeset
|
122 | * Calculate the extra beer temperatur rise to simulate the heat produced by the |
d0014ccec615
Simulation of fridge cold loss to the room added for testing.
Michiel Broek <mbroek@mbse.eu>
parents:
259
diff
changeset
|
123 | * fermentation process. Peak about one day after start and slowly decrease after |
d0014ccec615
Simulation of fridge cold loss to the room added for testing.
Michiel Broek <mbroek@mbse.eu>
parents:
259
diff
changeset
|
124 | * that. |
d0014ccec615
Simulation of fridge cold loss to the room added for testing.
Michiel Broek <mbroek@mbse.eu>
parents:
259
diff
changeset
|
125 | */ |
265
63a003914b72
More math for the simulator. Web interface changes for heater in graph.
Michiel Broek <mbroek@mbse.eu>
parents:
264
diff
changeset
|
126 | sqm_beer_air = (cbrtl(simulator->volume_beer) * cbrtl(simulator->volume_beer) * 6) / 100; /* Simple, the beer is in a cubic box */ |
63a003914b72
More math for the simulator. Web interface changes for heater in graph.
Michiel Broek <mbroek@mbse.eu>
parents:
264
diff
changeset
|
127 | thick_beer_air = 0.001; |
63a003914b72
More math for the simulator. Web interface changes for heater in graph.
Michiel Broek <mbroek@mbse.eu>
parents:
264
diff
changeset
|
128 | k_beer_air = 0.5; /* HDPE */ |
63a003914b72
More math for the simulator. Web interface changes for heater in graph.
Michiel Broek <mbroek@mbse.eu>
parents:
264
diff
changeset
|
129 | beer_heat_transfer=(k_beer_air * sqm_beer_air * (simulator->air_temperature - simulator->beer_temperature)) / thick_beer_air; |
365
df0261bb3feb
Version 0.3.3, still not for production. Fixed warnings when the simulator code is compiled. Slowed the simulator air temperature change 60 times. More realistic temperature changes for the heater and cooler elements. Improved logic in the simulator.
Michiel Broek <mbroek@mbse.eu>
parents:
363
diff
changeset
|
130 | /* beer_change = 0; */ |
262
d0014ccec615
Simulation of fridge cold loss to the room added for testing.
Michiel Broek <mbroek@mbse.eu>
parents:
259
diff
changeset
|
131 | |
d0014ccec615
Simulation of fridge cold loss to the room added for testing.
Michiel Broek <mbroek@mbse.eu>
parents:
259
diff
changeset
|
132 | /* |
d0014ccec615
Simulation of fridge cold loss to the room added for testing.
Michiel Broek <mbroek@mbse.eu>
parents:
259
diff
changeset
|
133 | * Calculate final temperature of the beer and the air. |
d0014ccec615
Simulation of fridge cold loss to the room added for testing.
Michiel Broek <mbroek@mbse.eu>
parents:
259
diff
changeset
|
134 | */ |
363
468ec0d96cce
Back to the old PID algorythm. Version 0.3.1.
Michiel Broek <mbroek@mbse.eu>
parents:
362
diff
changeset
|
135 | // Cheap trick, just follow slowly the air temp. |
366
7b698d012a0c
Better simulator temperature reality
Michiel Broek <mbroek@mbse.eu>
parents:
365
diff
changeset
|
136 | simulator->beer_temperature += ((simulator->air_temperature - simulator->beer_temperature) / 500.0); |
7b698d012a0c
Better simulator temperature reality
Michiel Broek <mbroek@mbse.eu>
parents:
365
diff
changeset
|
137 | simulator->air_temperature += ((simulator->beer_temperature - simulator->air_temperature) / 2500.0); |
363
468ec0d96cce
Back to the old PID algorythm. Version 0.3.1.
Michiel Broek <mbroek@mbse.eu>
parents:
362
diff
changeset
|
138 | |
468ec0d96cce
Back to the old PID algorythm. Version 0.3.1.
Michiel Broek <mbroek@mbse.eu>
parents:
362
diff
changeset
|
139 | syslog(LOG_NOTICE, "air=%.3f beer=%.3f heater=%.3f cooler=%.3f", simulator->air_temperature, simulator->beer_temperature, |
468ec0d96cce
Back to the old PID algorythm. Version 0.3.1.
Michiel Broek <mbroek@mbse.eu>
parents:
362
diff
changeset
|
140 | simulator->s_heat_temp, simulator->s_cool_temp); |
468ec0d96cce
Back to the old PID algorythm. Version 0.3.1.
Michiel Broek <mbroek@mbse.eu>
parents:
362
diff
changeset
|
141 | |
265
63a003914b72
More math for the simulator. Web interface changes for heater in graph.
Michiel Broek <mbroek@mbse.eu>
parents:
264
diff
changeset
|
142 | if (debug) |
63a003914b72
More math for the simulator. Web interface changes for heater in graph.
Michiel Broek <mbroek@mbse.eu>
parents:
264
diff
changeset
|
143 | 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", |
63a003914b72
More math for the simulator. Web interface changes for heater in graph.
Michiel Broek <mbroek@mbse.eu>
parents:
264
diff
changeset
|
144 | sqm_room_air, simulator->air_temperature, air_heat_transfer, air_change, |
63a003914b72
More math for the simulator. Web interface changes for heater in graph.
Michiel Broek <mbroek@mbse.eu>
parents:
264
diff
changeset
|
145 | sqm_beer_air, simulator->beer_temperature, beer_heat_transfer); |
262
d0014ccec615
Simulation of fridge cold loss to the room added for testing.
Michiel Broek <mbroek@mbse.eu>
parents:
259
diff
changeset
|
146 | } |
d0014ccec615
Simulation of fridge cold loss to the room added for testing.
Michiel Broek <mbroek@mbse.eu>
parents:
259
diff
changeset
|
147 | usleep(100000); |
d0014ccec615
Simulation of fridge cold loss to the room added for testing.
Michiel Broek <mbroek@mbse.eu>
parents:
259
diff
changeset
|
148 | } |
d0014ccec615
Simulation of fridge cold loss to the room added for testing.
Michiel Broek <mbroek@mbse.eu>
parents:
259
diff
changeset
|
149 | usleep(50000); |
259
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
150 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
151 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
152 | syslog(LOG_NOTICE, "Thread my_simulator_loop stopped"); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
153 | if (debug) |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
154 | fprintf(stdout, "Thread my_simulator_loop stopped\n"); |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
155 | return 0; |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
156 | } |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
157 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
158 | |
b7c967359771
Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents:
diff
changeset
|
159 | #endif |