- added generic tracer class

- create tracer for TC
- tracer task runs TC-Tracer
This commit is contained in:
jens
2021-10-18 17:57:40 +02:00
parent 236c33d8d6
commit 54f2322c07
5 changed files with 138 additions and 7 deletions
+10 -3
View File
@@ -5,6 +5,7 @@ from ws.message import MsgIo
from components import ATemperatureSensor
from components import AHeater
from components import APid
from tracer import Tracer
import numpy as np
import scipy.io
@@ -12,7 +13,7 @@ import os
class TracerTask(ATask):
def __init__(self, sensor: ATemperatureSensor, heater: AHeater, temp_ctrl: APid, interval, msg_handler: MsgIo, path= './logs'):
def __init__(self, sensor: ATemperatureSensor, heater: AHeater, temp_ctrl: APid, tracer: Tracer, interval, msg_handler: MsgIo, path= './logs'):
ATask.__init__(self, interval)
if not os.path.exists(path):
os.makedirs(path)
@@ -23,6 +24,7 @@ class TracerTask(ATask):
self.sensor = sensor
self.heater = heater
self.temp_ctrl = temp_ctrl
self.tracer = tracer
self.path = path
async def recv(self, data):
@@ -44,8 +46,13 @@ class TracerTask(ATask):
_tc_dtemp_soll = np.empty(0)
_tc_dtemp_commanded = np.empty(0)
filename = os.path.join(self.path, '') + "brewpi." + time.strftime("%Y%m%d%H%M%S", time.localtime()) + ".mat"
name = 'brewpi'
filename = os.path.join(self.path, '') + name + ".mat"
filename_full = os.path.join(self.path, '') + name + "." + time.strftime("%Y%m%d%H%M%S", time.localtime()) + ".mat"
while True:
self.tracer.process()
_timestamp = np.append(_timestamp, timestamp)
_sensor_temp = np.append(_sensor_temp, self.sensor.temperature())
_heater_power = np.append(_heater_power, self.heater.get_power())
@@ -57,8 +64,8 @@ class TracerTask(ATask):
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)
scipy.io.savemat(filename_full, data)
timestamp += 1
await asyncio.sleep(self.interval)