52 lines
1.7 KiB
Python
52 lines
1.7 KiB
Python
import asyncio
|
|
from tasks import ATask
|
|
from ws.message import MsgIo
|
|
from components import ATemperatureSensor
|
|
from components.pid import TempController
|
|
|
|
import numpy as np
|
|
import scipy.io
|
|
|
|
|
|
class TracerTask(ATask):
|
|
def __init__(self, sensor: ATemperatureSensor, temp_ctrl: TempController, interval, msg_handler: MsgIo):
|
|
ATask.__init__(self, interval)
|
|
|
|
self.msg_handler = msg_handler
|
|
msg_handler.set_recv_handler(self.recv)
|
|
|
|
self.sensor = sensor
|
|
self.temp_ctrl = temp_ctrl
|
|
|
|
async def recv(self, data):
|
|
pass
|
|
|
|
async def send(self, data):
|
|
await self.msg_handler.send(data)
|
|
|
|
async def on_process(self):
|
|
print("{}: Started with interval {} s".format(self.msg_handler.get_key(), self.interval))
|
|
|
|
time = 0
|
|
_time = np.empty(0)
|
|
_sensor_temp = np.empty(0)
|
|
_tc_temp_ist = np.empty(0)
|
|
_tc_dtemp_ist = np.empty(0)
|
|
_tc_temp_soll = np.empty(0)
|
|
_tc_dtemp_soll = np.empty(0)
|
|
_tc_dtemp_commanded = np.empty(0)
|
|
|
|
while True:
|
|
_time = np.append(_time, time)
|
|
_sensor_temp = np.append(_sensor_temp, self.sensor.temperature())
|
|
_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_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_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
|
|
await asyncio.sleep(self.interval)
|
|
|
|
|