Ejemplo n.º 1
0
class Voltage:
    channelRoomMappings = {"up": {"wz1": 1, "wz2": 3, "sz": 5}, "down": {"wz1": 2, "wz2": 4, "sz": 6}}

    def __init__(self, room, direction):
	self.room = room
	self.direction = direction
	self.channel = self.channelRoomMappings[direction][room]
        
	i2c_helper = ABEHelpers()
	bus = i2c_helper.get_smbus()
	self.adc = DeltaSigma(bus, 0x68, 0x69, 18)

    def readVoltage(self, channel):
	#return 2
	return self.adc.read_voltage(channel)

    def canSwitch(self):
	if self.room in ("wz", "all"):
	    return True	

	voltage = self.readVoltage(self.channel)
	print('Channel ' + str(self.channel) + " carries " + str(voltage) + " Volts")
	
	if math.fabs(voltage) > 0.1:
	    return False
	else:
	    return True
Ejemplo n.º 2
0
 def __init__(self, datasocket=None):
     threading.Thread.__init__(self)
     if datasocket is not None:
         self.datasocket = datasocket
     else:
         self.datasocket = None    
     self.measured_voltage = 0
     self.filament = {}
     port = '/dev/serial/by-id/usb-TTI_CPX400_Series_PSU_C2F952E5-if00'
     self.filament['device'] = CPX.CPX400DPDriver(1, device=port)
     self.filament['voltage'] = 0
     self.filament['current'] = 0
     self.filament['idle_voltage'] = 3
     self.filament['device'].set_current_limit(4)
     self.filament['device'].output_status(True)
     self.bias = {}
     self.bias['device'] = CPX.CPX400DPDriver(2, device=port)
     self.bias['grid_voltage'] = 0
     self.bias['grid_current'] = 0
     self.bias['device'].output_status(True)
     self.looptime = 0
     self.update_setpoint(0.1)
     i2c_helper = ABEHelpers()
     bus = i2c_helper.get_smbus()
     self.adc = DeltaSigma(bus, 0x68, 0x69, 18)
     self.adc.set_pga(1)  # This shold be 8, but amplifier seems broken on the available device
     self.running = True
     self.wanted_voltage = 0
     self.emission_current = 999
     self.pid = pid.PID(2, 0.03, 0, 9)
     self.pid.update_setpoint(self.setpoint)
Ejemplo n.º 3
0
    def __init__(self, room, direction):
	self.room = room
	self.direction = direction
	self.channel = self.channelRoomMappings[direction][room]
        
	i2c_helper = ABEHelpers()
	bus = i2c_helper.get_smbus()
	self.adc = DeltaSigma(bus, 0x68, 0x69, 18)
Ejemplo n.º 4
0
def main():
    """ Main function """
    logging.basicConfig(filename="logger.txt", level=logging.ERROR)
    logging.basicConfig(level=logging.ERROR)

    i2c_helper = ABEHelpers()
    bus = i2c_helper.get_smbus()
    adc_instance = DeltaSigma(bus, 0x68, 0x69, 18)

    tempreader = TemperatureReader(adc_instance)
    tempreader.daemon = True
    tempreader.start()

    codenames = ['cooling_water_hot', 'cooling_water_cold']
    loggers = {}
    for i in range(0, 2):
        loggers[codenames[i]] = ValueLogger(tempreader,
                                            comp_val=0.5,
                                            channel=i)
        loggers[codenames[i]].start()
    socket = DateDataPullSocket('hall_cooling_water_temp',
                                codenames,
                                timeouts=2.0)
    socket.start()

    live_socket = LiveSocket('hall_waterpressure', codenames)
    live_socket.start()

    db_logger = ContinuousDataSaver(continuous_data_table='dateplots_hall',
                                    username=credentials.user,
                                    password=credentials.passwd,
                                    measurement_codenames=codenames)
    db_logger.start()

    time.sleep(5)

    while tempreader.is_alive():
        time.sleep(0.25)
        for name in codenames:
            value = loggers[name].read_value()
            socket.set_point_now(name, value)
            live_socket.set_point_now(name, value)
            if loggers[name].read_trigged():
                print(value)
                db_logger.save_point_now(name, value)
                loggers[name].clear_trigged()
Ejemplo n.º 5
0
def main():
    """ Main function """

    logging.basicConfig(filename="logger.txt", level=logging.ERROR)
    logging.basicConfig(level=logging.ERROR)

    i2c_helper = ABEHelpers()
    bus = i2c_helper.get_smbus()
    adc_instance = DeltaSigma(bus, 0x68, 0x69, 18)
    pressurereader = PressureReader(adc_instance)
    pressurereader.daemon = True
    pressurereader.start()

    codenames = ['mr_iongauge_pressure']

    logger = ValueLogger(pressurereader, comp_val=0.5)
    logger.start()

    socket = DateDataPullSocket('Microreactor Ion Gauge', codenames, timeouts=[1.0])
    socket.start()

    live_socket = LiveSocket('Microreactor Ion Gauge', codenames, 2)
    live_socket.start()

    db_logger = ContinuousDataSaver(continuous_data_table='dateplots_microreactor',
                                    username=credentials.user,
                                    password=credentials.passwd,
                                    measurement_codenames=codenames)
    db_logger.start()

    time.sleep(2)

    while True:
        time.sleep(0.25)
        value = logger.read_value()
        socket.set_point_now(codenames[0], value)
        live_socket.set_point_now(codenames[0], value)
        if logger.read_trigged():
            print(value)
            db_logger.save_point_now(codenames[0], value)
            logger.clear_trigged()
ABElectronics Delta-Sigma Pi 8-Channel ADC demo
Version 1.0 Created 09/05/2014
Version 1.1 16/11/2014 updated code and functions to PEP8 format

Requires python smbus to be installed
run with: python demo-read_voltage.py
================================================


Initialise the ADC device using the default addresses and sample rate, change this value if you have changed the address selection jumpers
Sample rate can be 12,14, 16 or 18
"""

i2c_helper = ABEHelpers()
bus = i2c_helper.get_smbus()
adc = DeltaSigma(bus, 0x68, 0x69, 18)

while (True):

    # clear the console
    os.system('clear')

    # read from adc channels and print to screen
    print("Channel 1: %02f" % adc.read_voltage(1))
    print("Channel 2: %02f" % adc.read_voltage(2))
    print("Channel 3: %02f" % adc.read_voltage(3))
    print("Channel 4: %02f" % adc.read_voltage(4))
    print("Channel 5: %02f" % adc.read_voltage(5))
    print("Channel 6: %02f" % adc.read_voltage(6))
    print("Channel 7: %02f" % adc.read_voltage(7))
    print("Channel 8: %02f" % adc.read_voltage(8))
================================================
ABElectronics Delta-Sigma Pi 8-Channel ADC demo
Version 1.0 Created 29/02/2015

Requires python 3 smbus to be installed
run with: python3 demo-read_voltage.py
================================================


Initialise the ADC device using the default addresses and sample rate, change this value if you have changed the address selection jumpers
Sample rate can be 12,14, 16 or 18
"""

i2c_helper = ABEHelpers()
bus = i2c_helper.get_smbus()
adc = DeltaSigma(bus, 0x68, 0x69, 18)

while True:

    # clear the console
    os.system("clear")

    # read from adc channels and print to screen
    print("Channel 1: %02f" % adc.read_voltage(1))
    print("Channel 2: %02f" % adc.read_voltage(2))
    print("Channel 3: %02f" % adc.read_voltage(3))
    print("Channel 4: %02f" % adc.read_voltage(4))
    print("Channel 5: %02f" % adc.read_voltage(5))
    print("Channel 6: %02f" % adc.read_voltage(6))
    print("Channel 7: %02f" % adc.read_voltage(7))
    print("Channel 8: %02f" % adc.read_voltage(8))
Ejemplo n.º 8
0
from ABE_DeltaSigmaPi import DeltaSigma
from ABE_helpers import ABEHelpers
    
i2c_helper = ABEHelpers()
bus = i2c_helper.get_smbus()
adc = DeltaSigma(bus, 0x68, 0x69, 18)

while True:
  voltage = adc.read_voltage(1)
  v = voltage * 1000
  print('')
  #print('Channel 1: ' + str(v) + " Volts")
  print('Channel 1: ' + str(1000 * adc.read_voltage(1)) + " V")
  print('Channel 2: ' + str(1000 *adc.read_voltage(2)) + " V")
  print('Channel 3: ' + str(1000 * adc.read_voltage(3)) + " V")
  print('Channel 4: ' + str(1000 * adc.read_voltage(4)) + " V")
  print('Channel 5: ' + str(1000 * adc.read_voltage(5)) + " V")
  print('Channel 6: ' + str(1000 * adc.read_voltage(6)) + " V")
  print('Channel 7: ' + str(1000 * adc.read_voltage(7)) + " V")
  print('Channel 8: ' + str(1000 * adc.read_voltage(8)) + " V")
Ejemplo n.º 9
0
class EmissionControl(threading.Thread):
    """ Control the emission of a filament. """
    def __init__(self, datasocket=None):
        threading.Thread.__init__(self)
        if datasocket is not None:
            self.datasocket = datasocket
        else:
            self.datasocket = None    
        self.measured_voltage = 0
        self.filament = {}
        port = '/dev/serial/by-id/usb-TTI_CPX400_Series_PSU_C2F952E5-if00'
        self.filament['device'] = CPX.CPX400DPDriver(1, device=port)
        self.filament['voltage'] = 0
        self.filament['current'] = 0
        self.filament['idle_voltage'] = 3
        self.filament['device'].set_current_limit(4)
        self.filament['device'].output_status(True)
        self.bias = {}
        self.bias['device'] = CPX.CPX400DPDriver(2, device=port)
        self.bias['grid_voltage'] = 0
        self.bias['grid_current'] = 0
        self.bias['device'].output_status(True)
        self.looptime = 0
        self.update_setpoint(0.1)
        i2c_helper = ABEHelpers()
        bus = i2c_helper.get_smbus()
        self.adc = DeltaSigma(bus, 0x68, 0x69, 18)
        self.adc.set_pga(1)  # This shold be 8, but amplifier seems broken on the available device
        self.running = True
        self.wanted_voltage = 0
        self.emission_current = 999
        self.pid = pid.PID(2, 0.03, 0, 9)
        self.pid.update_setpoint(self.setpoint)

    def set_bias(self, bias):
        """ Set the bias-voltage """
        if self.datasocket is not None:
            self.datasocket.set_point_now('ionenergy', bias)
        if bias > -1:
            self.bias['device'].set_voltage(bias)
        if bias < 5:
            pass  # TODO: Implement check to make sure not to melt the filament

    def update_setpoint(self, setpoint):
        """ Update the setpoint """
        self.setpoint = setpoint
        if self.datasocket is not None:
            self.datasocket.set_point_now('setpoint', setpoint)

    def set_filament_voltage(self, U):
        """ Set the filament voltage """
        return(self.filament['device'].set_voltage(U))

    def read_filament_voltage(self):
        """ Read the filament voltage """
        return(self.filament['device'].read_actual_voltage())

    def read_filament_current(self):
        """ Read the filament current """
        return(self.filament['device'].read_actual_current())

    def read_grid_voltage(self):
        """Read the actual grid voltage """
        return(self.bias['device'].read_actual_voltage())

    def read_grid_current(self):
        """ Read the grid current as measured by power supply """
        return(self.bias['device'].read_actual_current())

    def read_emission_current(self):
        """ Read the actual emission current """
        value = self.adc.read_voltage(5)
        self.measured_voltage = value
        current = 1000.0 * value / 3.4  # Resistance value read off component label
        return(current)

    def run(self):
        while self.running:
            #time.sleep(0.1)
            t = time.time()
            self.emission_current = self.read_emission_current()
            self.wanted_voltage = self.pid.wanted_power(self.emission_current) + self.filament['idle_voltage']
            self.pid.update_setpoint(self.setpoint)
            self.set_filament_voltage(self.wanted_voltage)
            self.filament['voltage'] = self.read_filament_voltage()
            self.filament['current'] = self.read_filament_current()
            self.bias['grid_voltage'] = self.read_grid_voltage()
            self.bias['grid_current'] = self.read_grid_current()
            if self.datasocket is not None:
                self.datasocket.set_point_now('emission', self.emission_current)
            self.looptime = time.time() - t
        self.setpoint = 0
        self.set_filament_voltage(0)
        self.set_bias(0)
Ejemplo n.º 10
0
        while not self.quit:
            temp_hot = 0
            temp_cold = 0
            for _ in range(0, 4):
                temp_hot += adc_instance.read_voltage(1)
                temp_cold += adc_instance.read_voltage(2)
            self.hot = (temp_hot / 4 - 0.4) / 0.0195
            self.cold = (temp_cold / 4 - 0.4) / 0.0195 - 3.5


logging.basicConfig(filename="logger.txt", level=logging.ERROR)
logging.basicConfig(level=logging.ERROR)

i2c_helper = ABEHelpers()
bus = i2c_helper.get_smbus()
adc_instance = DeltaSigma(bus, 0x68, 0x69, 18)

tempreader = TemperatureReader(adc_instance)
tempreader.daemon = True
tempreader.start()

codenames = ['cooling_water_hot', 'cooling_water_cold']
loggers = {}
for i in range(0, 2):
    loggers[codenames[i]] = ValueLogger(tempreader, comp_val=0.5, channel=i)
    loggers[codenames[i]].start()
socket = DateDataPullSocket('hall_cooling_water_temp',
                            codenames,
                            timeouts=[2.0, 2.0])
socket.start()