initial import
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
import numpy as np
|
||||
import json
|
||||
from components.aplant import APlant
|
||||
|
||||
|
||||
class Pot(APlant):
|
||||
def __init__(self, params):
|
||||
print(json.dumps({'Pot': params}, indent=4, sort_keys=True))
|
||||
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)
|
||||
Reference in New Issue
Block a user