Пример #1
0
    def __init__(self, name):
        adc = ADC("Analog input",0)
        self.pressure = Strain_PressureSensor("Pressure (kPa)",adc)
        print "Pressure is %s kPa" % self.pressure.get_pressure_kpa()

        # put Port 8 Pin 3&4 into mode 7 (GPIO_1_6 & GPIO_1_7)
        open('/sys/kernel/debug/omap_mux/gpmc_ad6', 'wb').write("%X" % 7)
        open('/sys/kernel/debug/omap_mux/gpmc_ad7', 'wb').write("%X" % 7)
        gpio1_6 = GPIO(38,GPIO.OUTPUT) #p8_3
        gpio1_7 = GPIO(39,GPIO.OUTPUT) #p8_4
        self.vi = Valve("Inlet",gpio1_6)
        self.vo = Valve("Outlet",gpio1_7)

        # put Port 8 Pin 5 into mode 7 (GPIO_1_2)
        open('/sys/kernel/debug/omap_mux/gpmc_ad2', 'wb').write("%X" % 7)
        gpio1_2 = GPIO(34,GPIO.OUTPUT) #p8_5
        self.pump = Pump("Water cooling pump", gpio1_2)

        # put Port 9 Pin 12 into mode 7 (GPIO_1_28)
        gpio1_28 = GPIO(60,GPIO.INPUT) #p9_12
        self.waterlevel = WaterLevel("Waterlevel sensor", gpio1_28)

        sck=GPIO(49,GPIO.OUTPUT) #p9_23
        s0=GPIO(115,GPIO.INPUT)  #p9_27
        cs_t1=GPIO(48,GPIO.OUTPUT) #p9_15 GPIO1_16 48
        cs_t2=GPIO(117,GPIO.OUTPUT) #p9_25
        self.max1 = MAX31855(cs_t1, sck, s0)  #Maxim IC No 1, connected to the cartidge heater TC
        self.max2 = MAX31855(cs_t2, sck, s0)  #Maxim IC No 2, connected to the TC at the bottom of the vessel

        # PWMHeater
        self.h = PWMHeater("Cartridge heater (%)", "ehrpwm1a")
        self.h.setfrequency(3)
        
        # DS18B20
        T1="28-000003f5b1c9"
        T2="28-000003f5baa4"
        T3="28-000003f5be11"
        
        self.ds1=DS18B20("T in (C)",T1)
        self.ds2=DS18B20("T out (C)",T2)
        self.ds3=DS18B20("T Env (C)",T3)
        
        print "ds1: ",self.ds1.get_temperature()
        print "ds2: ",self.ds2.get_temperature()
        print "ds3: ",self.ds3.get_temperature()
        
        # CS5490 power meter
        self.cs=CS5490("Power In (W)")

        print "start DataLogger"
        self.log = DataLogger("my datalogger",500)
        self.log.add_sensor(("T Vessel bottom (C)","Maxim 2 Cld jnct (C)"),self.max2.get_celsius)
        self.log.add_sensor(("T Cartridge (C)","Maxim 1 Cld jnct (C)"),self.max1.get_celsius)
        self.log.add_sensor(self.ds1.get_name(),self.ds1.get_temperature)
        self.log.add_sensor(self.ds2.get_name(),self.ds2.get_temperature)
        self.log.add_sensor(self.ds3.get_name(),self.ds3.get_temperature)
        self.log.add_sensor(self.pressure.get_name(),self.pressure.get_pressure_kpa)
        self.log.add_sensor(self.cs.get_name(),self.cs.get_average_power)
Пример #2
0
class PeerPressure(object):
    def __init__(self, name):
        adc = ADC("Analog input",0)
        self.pressure = Strain_PressureSensor("Pressure (kPa)",adc)
        print "Pressure is %s kPa" % self.pressure.get_pressure_kpa()

        # put Port 8 Pin 3&4 into mode 7 (GPIO_1_6 & GPIO_1_7)
        open('/sys/kernel/debug/omap_mux/gpmc_ad6', 'wb').write("%X" % 7)
        open('/sys/kernel/debug/omap_mux/gpmc_ad7', 'wb').write("%X" % 7)
        gpio1_6 = GPIO(38,GPIO.OUTPUT) #p8_3
        gpio1_7 = GPIO(39,GPIO.OUTPUT) #p8_4
        self.vi = Valve("Inlet",gpio1_6)
        self.vo = Valve("Outlet",gpio1_7)

        # put Port 8 Pin 5 into mode 7 (GPIO_1_2)
        open('/sys/kernel/debug/omap_mux/gpmc_ad2', 'wb').write("%X" % 7)
        gpio1_2 = GPIO(34,GPIO.OUTPUT) #p8_5
        self.pump = Pump("Water cooling pump", gpio1_2)

        # put Port 9 Pin 12 into mode 7 (GPIO_1_28)
        gpio1_28 = GPIO(60,GPIO.INPUT) #p9_12
        self.waterlevel = WaterLevel("Waterlevel sensor", gpio1_28)

        sck=GPIO(49,GPIO.OUTPUT) #p9_23
        s0=GPIO(115,GPIO.INPUT)  #p9_27
        cs_t1=GPIO(48,GPIO.OUTPUT) #p9_15 GPIO1_16 48
        cs_t2=GPIO(117,GPIO.OUTPUT) #p9_25
        self.max1 = MAX31855(cs_t1, sck, s0)  #Maxim IC No 1, connected to the cartidge heater TC
        self.max2 = MAX31855(cs_t2, sck, s0)  #Maxim IC No 2, connected to the TC at the bottom of the vessel

        # PWMHeater
        self.h = PWMHeater("Cartridge heater (%)", "ehrpwm1a")
        self.h.setfrequency(3)
        
        # DS18B20
        T1="28-000003f5b1c9"
        T2="28-000003f5baa4"
        T3="28-000003f5be11"
        
        self.ds1=DS18B20("T in (C)",T1)
        self.ds2=DS18B20("T out (C)",T2)
        self.ds3=DS18B20("T Env (C)",T3)
        
        print "ds1: ",self.ds1.get_temperature()
        print "ds2: ",self.ds2.get_temperature()
        print "ds3: ",self.ds3.get_temperature()
        
        # CS5490 power meter
        self.cs=CS5490("Power In (W)")

        print "start DataLogger"
        self.log = DataLogger("my datalogger",500)
        self.log.add_sensor(("T Vessel bottom (C)","Maxim 2 Cld jnct (C)"),self.max2.get_celsius)
        self.log.add_sensor(("T Cartridge (C)","Maxim 1 Cld jnct (C)"),self.max1.get_celsius)
        self.log.add_sensor(self.ds1.get_name(),self.ds1.get_temperature)
        self.log.add_sensor(self.ds2.get_name(),self.ds2.get_temperature)
        self.log.add_sensor(self.ds3.get_name(),self.ds3.get_temperature)
        self.log.add_sensor(self.pressure.get_name(),self.pressure.get_pressure_kpa)
        self.log.add_sensor(self.cs.get_name(),self.cs.get_average_power)

    def check(self):
        '''
        # Setup the Tool Watch Dog
        '''
        return self.waterlevel.is_water()

    def shutdown(self):
        print "Emergency shutdown at: ", time.ctime()
        self.pomp.emergency_shutdown() # do not try to restart, pump is not self priming
        self.h.emergency_shutdown()   # Use the NON-logged version of heater
        #log.record_flag("Emergency shutoff")  # Logger not thread safe yet
        # ToDo: gracefulle stop running script & prevent any new jobs to start

    def heater_set_power(self,power):
        self.h.setpower(power)
        self.log.record_control(self.h.get_name(), power)
    
    def v_in_open(self):
        self.vi.open()
        self.log.record_control(self.vi.get_name(),1)
    def v_in_close(self):
        self.vi.close()
        self.log.record_control(self.vi.get_name(),0)
    def v_out_open(self):
        self.vo.open()
        self.log.record_control(self.vo.get_name(),1)
    def v_out_close(self):
        self.vo.close()
        self.log.record_control(self.vo.get_name(),0)
            
    def l_wait(self, sec):  # wait sec seconds but keep loggin
        t_s = time.time()
        dt = sec
        interval = 10 # seconds
        while dt > interval:
            self.log.record_sensors()
            time.sleep(interval)
            dt = sec - (time.time() - t_s)
        if dt > 0: time.sleep(dt)
    
    def close(self):
        self.heater_set_power(0)
        self.h.off()
        self.v_in_close()
        self.v_out_close()
        self.log.flush_measurement_buffer()
        self.log.finish()