- added heater power

This commit is contained in:
jens
2020-12-20 13:27:52 +01:00
parent e75f322ad4
commit d3e61ab72f
3 changed files with 24 additions and 11 deletions
+1 -1
View File
@@ -50,7 +50,7 @@ if __name__ == '__main__':
taskmgr.add(stirrer_task) taskmgr.add(stirrer_task)
# Tracer # Tracer
taskmgr.add(TracerTask(sensor, tc, DT_CTRL, dispatcher.msgio_get("Tracer"))) taskmgr.add(TracerTask(sensor, heater, tc, DT_CTRL, dispatcher.msgio_get("Tracer")))
# Message dispatcher # Message dispatcher
h_dispatcher = taskmgr.start() h_dispatcher = taskmgr.start()
+6 -3
View File
@@ -25,12 +25,15 @@
function retval = results() function retval = results()
load test.mat load brewpi.mat
set(0, "defaultlinelinewidth", 1.5); set(0, "defaultlinelinewidth", 1.5);
subplot(2,1,1) subplot(3,1,1)
plot(time, tc_temp_soll, time, tc_temp_ist); grid plot(time, tc_temp_soll, time, tc_temp_ist); grid
legend("Temp_{soll}","Temp_{ist}") legend("Temp_{soll}","Temp_{ist}")
subplot(2,1,2) subplot(3,1,2)
plot(time, tc_dtemp_soll, time, tc_dtemp_ist, time, tc_dtemp_commanded); grid plot(time, tc_dtemp_soll, time, tc_dtemp_ist, time, tc_dtemp_commanded); grid
legend("dTemp_{soll}","dTemp_{ist}","dTemp_{cmd}") legend("dTemp_{soll}","dTemp_{ist}","dTemp_{cmd}")
subplot(3,1,3)
plot(time, heater_power); grid
legend("Power_{Heater}")
endfunction endfunction
+17 -7
View File
@@ -1,7 +1,9 @@
import time
import asyncio import asyncio
from tasks import ATask from tasks import ATask
from ws.message import MsgIo from ws.message import MsgIo
from components import ATemperatureSensor from components import ATemperatureSensor
from components import AHeater
from components.pid import TempController from components.pid import TempController
import numpy as np import numpy as np
@@ -9,13 +11,14 @@ import scipy.io
class TracerTask(ATask): class TracerTask(ATask):
def __init__(self, sensor: ATemperatureSensor, temp_ctrl: TempController, interval, msg_handler: MsgIo): def __init__(self, sensor: ATemperatureSensor, heater: AHeater, temp_ctrl: TempController, interval, msg_handler: MsgIo):
ATask.__init__(self, interval) ATask.__init__(self, interval)
self.msg_handler = msg_handler self.msg_handler = msg_handler
msg_handler.set_recv_handler(self.recv) msg_handler.set_recv_handler(self.recv)
self.sensor = sensor self.sensor = sensor
self.heater = heater
self.temp_ctrl = temp_ctrl self.temp_ctrl = temp_ctrl
async def recv(self, data): async def recv(self, data):
@@ -27,25 +30,32 @@ class TracerTask(ATask):
async def on_process(self): async def on_process(self):
print("{}: Started with interval {} s".format(self.msg_handler.get_key(), self.interval)) print("{}: Started with interval {} s".format(self.msg_handler.get_key(), self.interval))
time = 0 timestamp = 0
_time = np.empty(0) _timestamp = np.empty(0)
_sensor_temp = np.empty(0) _sensor_temp = np.empty(0)
_heater_power = np.empty(0)
_tc_temp_ist = np.empty(0) _tc_temp_ist = np.empty(0)
_tc_dtemp_ist = np.empty(0) _tc_dtemp_ist = np.empty(0)
_tc_temp_soll = np.empty(0) _tc_temp_soll = np.empty(0)
_tc_dtemp_soll = np.empty(0) _tc_dtemp_soll = np.empty(0)
_tc_dtemp_commanded = np.empty(0) _tc_dtemp_commanded = np.empty(0)
filename = "brewpi." + time.strftime("%Y%m%d%H%M%S", time.localtime()) + ".mat"
while True: while True:
_time = np.append(_time, time) _timestamp = np.append(_timestamp, timestamp)
_sensor_temp = np.append(_sensor_temp, self.sensor.temperature()) _sensor_temp = np.append(_sensor_temp, self.sensor.temperature())
_heater_power = np.append(_heater_power, self.heater.get_power())
_tc_temp_ist = np.append(_tc_temp_ist, self.temp_ctrl.theta_ist) _tc_temp_ist = np.append(_tc_temp_ist, self.temp_ctrl.theta_ist)
_tc_dtemp_ist = np.append(_tc_dtemp_ist, self.temp_ctrl.heatrate_ist) _tc_dtemp_ist = np.append(_tc_dtemp_ist, max(-1, self.temp_ctrl.heatrate_ist))
_tc_temp_soll = np.append(_tc_temp_soll, self.temp_ctrl.theta_soll_set) _tc_temp_soll = np.append(_tc_temp_soll, self.temp_ctrl.theta_soll_set)
_tc_dtemp_soll = np.append(_tc_dtemp_soll, self.temp_ctrl.heatrate_soll_set) _tc_dtemp_soll = np.append(_tc_dtemp_soll, self.temp_ctrl.heatrate_soll_set)
_tc_dtemp_commanded = np.append(_tc_dtemp_commanded, self.temp_ctrl.heatrate_soll) _tc_dtemp_commanded = np.append(_tc_dtemp_commanded, self.temp_ctrl.heatrate_soll)
scipy.io.savemat('test.mat', {'time': _time, 'sensor_temp': _sensor_temp, 'tc_temp_ist': _tc_temp_ist, 'tc_dtemp_ist': _tc_dtemp_ist, 'tc_temp_soll': _tc_temp_soll, 'tc_dtemp_soll': _tc_dtemp_soll, 'tc_dtemp_commanded': _tc_dtemp_commanded})
time += 1 data = {'time': _timestamp, 'sensor_temp': _sensor_temp, 'heater_power': _heater_power, 'tc_temp_ist': _tc_temp_ist, 'tc_dtemp_ist': _tc_dtemp_ist, 'tc_temp_soll': _tc_temp_soll, 'tc_dtemp_soll': _tc_dtemp_soll, 'tc_dtemp_commanded': _tc_dtemp_commanded}
scipy.io.savemat('brewpi.mat', data)
scipy.io.savemat(filename, data)
timestamp += 1
await asyncio.sleep(self.interval) await asyncio.sleep(self.interval)