Files
HendiControlFirmware/Control/brewpi/brewpi.py
T
2019-04-15 21:06:24 +00:00

91 lines
2.1 KiB
Python
Executable File

#!/usr/bin/python3
import signal
import json
from controller import Controller
from mass import Mass
from stirrer import Stirrer
from pololu1376 import Pololu1376
from matplotlib.pyplot import figure, clf, plot, xlabel, ylabel, xlim, ylim, title, grid, axes, show, subplot
def results_plot(self):
fp = open("results.dat", 'w')
for n in range(0, len(self.time_v)):
d = self.time_v[n]
v1 = self.theta_raw_v[n]
v2 = self.theta_k_v[n]
v3 = self.power_v[n]
v4 = self.error_v[n]
v5 = self.heatrate_k_v[n]
fp.write("{:6.3f} {:6.3f} {:6.3f} {:6.3f} {:6.3f} {:6.3f}\n".format(d, v1, v2, v3, v4, v5))
fp.close()
figure(1)
subplot(4, 1, 1)
plot(self.time_v, self.theta_raw_v, 'g-', self.time_v, self.theta_k_v, 'r-', linewidth=1)
title('Temperature')
grid(True)
ylabel('°C')
subplot(4, 1, 2)
plot(self.time_v, self.power_v, 'b-', linewidth=1)
title('Power')
grid(True)
ylabel('W')
subplot(4, 1, 3)
plot(self.time_v, self.error_v, 'b-', linewidth=1)
title('Error')
grid(True)
ylabel('°C')
subplot(4, 1, 4)
plot(self.time_v, self.heatrate_k_v, 'r-', linewidth=1)
title('Heatrate')
grid(True)
ylabel('°C/min')
xlabel('t/min')
show()
if __name__ == '__main__':
def handler(signum, frame):
print('Signal handler called with signal', signum)
if signum == signal.SIGINT:
ablauf.stop()
if signum == signal.SIGSTOP:
ablauf.pause()
if signum == signal.SIGCONT:
ablauf.cont()
if signum == signal.SIGHUP:
ablauf.restart()
# Set the signal handler and a 5-second alarm
signal.signal(signal.SIGABRT, handler)
signal.signal(signal.SIGINT, handler)
signal.signal(signal.SIGCONT, handler)
signal.signal(signal.SIGHUP, handler)
fp = open("brewpi.json")
configJson = json.load(fp)
plant_class = globals()[configJson["Controller"]['plant_name']]
plant = plant_class(configJson["WaterSim"])
ruehrer_class = globals()[configJson["Controller"]['stirrer_name']]
ruehrer = ruehrer_class(configJson["Stirrer"])
ablauf = Controller(configJson["Controller"], plant, ruehrer)
fp = open("Rezept-001.json")
recipeJson = json.load(fp)
ablauf.start(recipeJson)
ablauf.wait_finished()
results_plot(ablauf)
print ("End of program.")