Beispiel #1
0
 def initServer( self ):
     #setting up necessary objects
     self.daq = Communicator()
     self.channels = self.daq.channels
     self.channelDict = self.daq.channelDict
     self.averager = RunningAverage(self.channels, averageNumber = 12)
     self.emailer = self.client.emailer
     yield self.emailer.set_recipients(['*****@*****.**']) #### set this later
     self.alarmChecker = AlarmChecker(self.emailer, self.channelDict)
     #stting up constants
     self.PIDparams =([0,0,0],..)####get from registry
     self.daqErrors = 0
     #
     self.responseCalc = ResponseCalculator()
     #begin control
     self.inControl = LoopingCall(self.control)
     self.inControl.start(self.updateRate)
Beispiel #2
0
class AC_Server( LabradServer ):
    name = 'AC Server'
    updateRate = 1.0 #seconds
    maxDaqErrors = 10
        
    @inlineCallbacks
    def initServer( self ):
        #setting up necessary objects
        self.daq = Communicator()
        self.channels = self.daq.channels
        self.channelDict = self.daq.channelDict
        self.averager = RunningAverage(self.channels, averageNumber = 12)
        self.emailer = self.client.emailer
        yield self.emailer.set_recipients(['*****@*****.**']) #### set this later
        self.alarmChecker = AlarmChecker(self.emailer, self.channelDict)
        #stting up constants
        self.PIDparams =([0,0,0],..)####get from registry
        self.daqErrors = 0
        #
        self.responseCalc = ResponseCalculator()
        #begin control
        self.inControl = LoopingCall(self.control)
        self.inControl.start(self.updateRate)


    @setting(0, 'Manual Override', enable = 'b', valvePositions = '*v')
    def manualOverride(self, c, enable, valvePositions = None):
        """If enabled, allows to manual specify the positions of the valves, ignoring feedback"""
        if enable:
            if valvePositions is None: raise Exception("Please specify valve positions")
            if self.inControl.running:
                yield self.inControl.stop()
            raise NotImplementedError
            #### set valve positions through valve class (with error checking there)
            #### make sure still record and save temperatures while in manual mode
        else: #resume automated control
            self.inControl.start(self.updateRate)
            
    @setting(1, 'PID Parameters', PID = '*3v')
    def PID(self, c, PID = None):
        """Allows to view or to set the PID parameters"""
        if PID is None: return self.PID
        self.PIDparams = PID
        ####
        
    @setting(2, 'Reset Integrator')
    def resetIntegrator(self, c):
        pass
    
    @inlineCallbacks
    def control(self):
        try:
            temps = yield self.daq.getTemperatures()
        except: #put error type
            self.daqErros += 1
            yield self.checkMaxErrors()
        else:
            self.averager.add(temps)
            temps = self.averager.getAverage()
            yield self.alarmChecker.check(temps)
            PIDresponse,valveResponse =  self.responseCalc.getResponse(temps)
            toValves = self.Valves.valveSignal(valveResponse)
            yield self.daq.setValves(toValves)
            
            
    @inlineCallbacks
    def checkMaxErrors(self):
        """checks how many errors have occured in sends out a notification email"""
        if self.daqErrors >  self.maxDaqErrors:
            print "TOO MANY DAQ ERRORS"
            yield self.emailer.send('AC ALARM: TOO MANY DAQ ERRORS', '')
            self.daqErrors = 0
            yield self.inControl.stop()