Heating and Ventilation Control
/HvcRaw2phys
Keine Erläuterungen gefunden.
import os from HvcTables import * class HvcRaw2phys: """ Convert electronic raw values to physical units. """ def __init__(self): pass def ADCverbose(self,raw,weight,HvcTables): """ The verbose mode is good to understand, what is going on, used at initializations. """ phys = {} message = "HvcRaw2phys.ADC \n" #initialize LowPass not set yet for val in raw: value = float(raw[val]) try: foo = HvcRaw2phys.LowPass[val] except: HvcRaw2phys.LowPass[val] = value #check validity of signals for val in raw: value = raw[val] if value<=1 or value>=4095: message = message + "WARNING: check electrical connection of port: "+val+"\n" elif value<0.9*HvcRaw2phys.LowPass[val] or value>1.1*HvcRaw2phys.LowPass[val]: message = message + "WARNING: check connection of floating port: "+val+"\n" #reduce noise by low pass filter for val in raw: value = float(raw[val]) # last = HvcRaw2phys.LowPass[val] #arne HvcRaw2phys.LowPass[val] = (1.0-weight)*HvcRaw2phys.LowPass[val] + weight * value # if val=="haus": # print("LowPass",last,value,HvcRaw2phys.LowPass[val],weight) #arne #convert raw to physical value for val in raw: if val=="TLow": phys[val] = HvcTables.interpol( HvcRaw2phys.LowPass[val], "KTY", "saturate" ) elif val=="THot": phys[val] = HvcTables.interpol( HvcRaw2phys.LowPass[val], "KTY", "saturate" ) elif val=="ret": phys[val] = HvcTables.interpol( HvcRaw2phys.LowPass[val], "KTY", "saturate" ) elif val=="flow": phys[val] = HvcTables.interpol( HvcRaw2phys.LowPass[val], "KTY", "saturate" ) elif val=="coll": phys[val] = HvcTables.interpol( HvcRaw2phys.LowPass[val], "Pt1000", "no-saturate" ) elif val=="fire": phys[val] = HvcTables.interpol( HvcRaw2phys.LowPass[val], "NTCoven", "saturate" ) elif val=="haus": phys[val] = HvcTables.interpol( HvcRaw2phys.LowPass[val], "NTCoven", "saturate" ) elif val=="erde": phys[val] = HvcTables.interpol( HvcRaw2phys.LowPass[val], "Thermos200a", "saturate" ) elif val=="zulu": phys[val] = HvcTables.interpol( HvcRaw2phys.LowPass[val], "Thermos200a", "saturate" ) elif val=="ablu": phys[val] = HvcTables.interpol( HvcRaw2phys.LowPass[val], "Thermos200a", "saturate" ) elif val=="folu": phys[val] = HvcTables.interpol( HvcRaw2phys.LowPass[val], "Thermos200a", "saturate" ) # phys["folu"] = phys["ablu"] - (phys["zulu"]-phys["erde"]) else: message = message + "WARNING: for "+val+" there is no conversion! \n" phys[val] = HvcRaw2phys.LowPass[val] message = message+"\t\t" for val in raw: message = message+('\t{}'.format(val)) message = message + "\n" message = message + "lowPass \t" for val in raw: message = message+('\t{:.2f}'.format(HvcRaw2phys.LowPass[val])) message = message + "\n" message = message + "physical \t" for val in raw: message = message+('\t{:.2f}'.format(phys[val])) message = message + "\n" return phys, message def ADC(self,raw,weight,HvcTables): """ For regular calls, drop the messages. """ phys, message = HvcRaw2phys.ADCverbose(self,raw,weight,HvcTables) return phys #persistant values: LowPass={} if __name__ == "__main__": #first init tables HvcTables = HvcTables() r2p = HvcRaw2phys() myRaw = {'coll': 1936, 'TLow': 2128, 'THot': 2016, 'flow': 2160, 'ret': 2164, 'fire': 682, 'haus': 707, 'erde': 1735, 'zulu': 2412, 'ablu': 1768, 'posBp': 401} weight=0.5 phys, message = r2p.ADCverbose(myRaw,weight,HvcTables) print(message) print("============================") print("second call, all LowPass +1 ?") for val in myRaw: myRaw[val] = myRaw[val]+2 weight=0.5 phys, message = r2p.ADCverbose(myRaw,weight,HvcTables) print(message) print("============================") print("execute short function") phys = r2p.ADC(myRaw,weight,HvcTables) print(phys)
python
php
Der gesamte Sourcecode darf gemäß GNU General Public License weiterverbreitet werden.