Files
brewpi/components/plant/pot.py
T
2020-11-26 20:33:56 +01:00

59 lines
1.3 KiB
Python

import numpy as np
import json
from components.aplant import APlant
class Pot(APlant):
def __init__(self, params):
self.dt = params['dt']
self.alpha = 1.0
self.e = 0
self.x = 0
self.gain = 0.999
self.C = params['C']
self.M = params['M']
self.L = params['L']
self.Td = params['Td']
self.kn = params['kn']
self.theta_amb = params['theta_amb']
self.theta = 0
self.alpha = self.dt / 1
self.alpha_delay = self.dt/self.Td
self.theta_changed_callback = None
self.power_set = 0
self.power_actual = 0
def connect_theta_changed(self, func):
self.theta_changed_callback = func
def activate(self, enable):
pass
def process(self):
# Delay
self.power_actual = (1-self.alpha_delay) * self.power_actual + self.alpha_delay * self.power_set
self.e = self.e * (1 - ((self.L * self.theta) * self.dt) / (self.M * self.C))
self.x = (1 - self.alpha) * self.x + self.gain * self.alpha * self.power_actual
self.e += self.x
theta = self.e / (self.M * self.C)
if self.theta_changed_callback is not None:
self.theta_changed_callback(self.getTemperature())
self.theta = theta
def setPower(self, power):
self.power_set = power
def getPower(self):
return round(self.power_actual, 1)
def getTemperature(self):
return round(self.theta + self.theta_amb + self.kn * np.random.normal(0, 1) / np.sqrt(12.0), 1)