def __init__(self, test, logging, regulator): """Initialize the NIDAQ extended Pneumatics test, with the supplied overall test and logger. Args: test (testRunner): The testrunner used to call the Pneumatics Test, allowing the use of test failing / passing / warnings. logging (logger): Allows whatever preconfigured logging module used in the main program to be accessed in this file.. """ self.g = test.g self.test = test logging.debug("Initialized NIDAQ Extend Pneumatics Test") self.pneumatics = Pneumatics_Test(test, logging) # Basic defines for running the test, used further on self.pressure_ramp_cycles = 1 # Total number cycles the test is run self.sample_rate = 1000 # Sampling rate (Hz) self.solenoid_toggle_cycles = 1 # Number of solenoid_toggle_cycles to toggle solenoid at each pressure self.wait_time_s = 1 # Wait for regulator to reach pressure in between solenoid toggles self.checkpoint = 5 # Save full data every _ solenoid solenoid_toggle_cycles, if 0 don't save self.ID = str( regulator) # Name of the file saved in the directory by the logger # Miscellanous setup self.outputdirectory = None # Allows us ot set the output directory later with the logger self.task = AnalogInputTask() # Used to read from the DAQ self.task.create_voltage_channel('Dev1/ai0', terminal='diff', min_val=-5.0, max_val=5.0) self.task.configure_timing_sample_clock(rate=self.sample_rate) with cd(path): self.daq = DAQ(self) # Sets the directory that the logger logs in
def runner(parser, options, args): task = AnalogInputTask() print('Created AnalogInputTask %s (task.value=%s)' % (task, task.value)) args, kws = get_method_arguments('create_voltage_channel', options) print('create_voltage_channel', kws) task.create_voltage_channel(**kws) channels = task.get_names_of_channels() if not channels: print('No channels specified') return args, kws = get_method_arguments('configure_timing_sample_clock', options) print('configure_timing_sample_clock', kws) clock_rate = kws.get('rate', 1000.0) task.configure_timing_sample_clock(**kws) print('task') task.start() args, read_kws = get_method_arguments('ai_read', options) kws = read_kws fill_mode = kws.get('fill_mode', 'group_by_scan_number') print('read', read_kws) if options.ai_task == 'show': from nidaqmx.wxagg_plot import animated_plot start_time = time.time() def func(task=task): current_time = time.time() data = task.read(**read_kws) if fill_mode == 'group_by_scan_number': data = data.T tm = np.arange(data.shape[-1], dtype=float) / clock_rate + ( current_time - start_time) return tm, data, channels try: animated_plot(func, 1000 * (task.samples_per_channel / clock_rate + 0.1)) finally: del task return elif options.ai_task == 'print': try: data = task.read(**kws) finally: del task print(data) else: del task raise NotImplementedError(repr(options.ai_task))
def read(self, context): task = AnalogInputTask(_task_name(context)) minimum = context.minimum if context.minimum is not None else -10 maximum = context.maximum if context.maximum is not None else 10 task.create_voltage_channel(_phys_channel(context), terminal="rse", min_val=minimum, max_val=maximum) task.start() raw = task.read(100) task.stop() return np.average(raw).item()
def __init__(self, test, logging, regulator): """Initialize the NIDAQ extended Pneumatics test, with the supplied overall test and logger. Args: test (testRunner): The testrunner used to call the Pneumatics Test, allowing the use of test failing / passing / warnings. logging (logger): Allows whatever preconfigured logging module used in the main program to be accessed in this file.. """ self.g = test.g self.test = test logging.debug("Initialized NIDAQ Extend Pneumatics Test") self.pneumatics = Pneumatics_Test(test, logging) # Basic defines for running the test, used further on self.pressure_ramp_cycles = 1 # Total number cycles the test is run self.sample_rate = 1000 # Sampling rate (Hz) self.solenoid_toggle_cycles = 1 # Number of solenoid_toggle_cycles to toggle solenoid at each pressure self.wait_time_s = 1 # Wait for regulator to reach pressure in between solenoid toggles self.checkpoint = 5 # Save full data every _ solenoid solenoid_toggle_cycles, if 0 don't save self.ID = str(regulator) # Name of the file saved in the directory by the logger # Miscellanous setup self.outputdirectory = None # Allows us ot set the output directory later with the logger self.task = AnalogInputTask() # Used to read from the DAQ self.task.create_voltage_channel('Dev1/ai0', terminal='diff', min_val=-5.0, max_val=5.0) self.task.configure_timing_sample_clock(rate=self.sample_rate) with cd(path): self.daq = DAQ(self) # Sets the directory that the logger logs in
def runner (parser, options, args): task = AnalogInputTask() print('Created AnalogInputTask %s (task.value=%s)' % (task, task.value)) args, kws = get_method_arguments('create_voltage_channel', options) print('create_voltage_channel', kws) task.create_voltage_channel (**kws) channels = task.get_names_of_channels() if not channels: print('No channels specified') return args, kws = get_method_arguments('configure_timing_sample_clock', options) print('configure_timing_sample_clock', kws) clock_rate = kws.get('rate', 1000.0) task.configure_timing_sample_clock(**kws) print('task') task.start() args, read_kws = get_method_arguments('ai_read', options) kws = read_kws fill_mode = kws.get ('fill_mode', 'group_by_scan_number') print('read', read_kws) if options.ai_task=='show': from nidaqmx.wxagg_plot import animated_plot start_time = time.time() def func(task=task): current_time = time.time() data = task.read(**read_kws) if fill_mode == 'group_by_scan_number': data = data.T tm = np.arange(data.shape[-1], dtype=float)/clock_rate + (current_time - start_time) return tm, data, channels try: animated_plot(func, 1000*(task.samples_per_channel/clock_rate+0.1)) finally: del task return elif options.ai_task=='print': try: data = task.read (**kws) finally: del task print(data) else: del task raise NotImplementedError (repr(options.ai_task))
class Pneumatics_Test_NIDAQ(object): """ Test module for the pneumatics system, e-regulator, and solenoid. This class is used to run tests on the pneumatics sled, and cartridge. """ def __init__(self, test, logging, regulator): """Initialize the NIDAQ extended Pneumatics test, with the supplied overall test and logger. Args: test (testRunner): The testrunner used to call the Pneumatics Test, allowing the use of test failing / passing / warnings. logging (logger): Allows whatever preconfigured logging module used in the main program to be accessed in this file.. """ self.g = test.g self.test = test logging.debug("Initialized NIDAQ Extend Pneumatics Test") self.pneumatics = Pneumatics_Test(test, logging) # Basic defines for running the test, used further on self.pressure_ramp_cycles = 1 # Total number cycles the test is run self.sample_rate = 1000 # Sampling rate (Hz) self.solenoid_toggle_cycles = 1 # Number of solenoid_toggle_cycles to toggle solenoid at each pressure self.wait_time_s = 1 # Wait for regulator to reach pressure in between solenoid toggles self.checkpoint = 5 # Save full data every _ solenoid solenoid_toggle_cycles, if 0 don't save self.ID = str(regulator) # Name of the file saved in the directory by the logger # Miscellanous setup self.outputdirectory = None # Allows us ot set the output directory later with the logger self.task = AnalogInputTask() # Used to read from the DAQ self.task.create_voltage_channel('Dev1/ai0', terminal='diff', min_val=-5.0, max_val=5.0) self.task.configure_timing_sample_clock(rate=self.sample_rate) with cd(path): self.daq = DAQ(self) # Sets the directory that the logger logs in def record_solenoid_pressure(self, pressure): # Set regulator pressure self.pneumatics.setRegulatorPressure(pressure) time.sleep(3) for cycle in range(0, self.solenoid_toggle_cycles): self.daq.record(int(self.sample_rate*self.wait_time_s), cycle, pressure) # Open recording thread self.open_solenoid() time.sleep(self.wait_time_s) self.close_solenoid() time.sleep(1) def test_Diagnostics_trial_pump(self): t = ResponseData() # Test Failure Criteria pump_to_pressure_time = 60 pump_pressure = 40 pump_pressure_acceptable_bound = 2 pressure_tank_start = 0 # Beginning pressure while testing for tank pressure pressure_tank_end = 30 # Highest pressure reached while testing on tank pressure pressure_interval = 5 # Interval in which the pressure increases between bounds global current_ramp_cycle with cd(path): g = self.g task = AnalogInputTask() self.close_house_air() for i in range(0, self.pressure_ramp_cycles): # Ensure solenoid is closed at start self.close_solenoid() # Set tank pressure to pump pressure self.pneumatics.setPumpPressure(pump_pressure) # Wait for pump to reach pressure for i in range(pump_to_pressure_time): p = self.pneumatics.readPumpPressure() if p > pump_pressure - pump_pressure_acceptable_bound: break if i is pump_to_pressure_time - 1: t.fail("Didn't reach pump pressure") return t sleep(1) logging.debug("Pump Pressure: {}".format(p)) logging.info("Testing Output Pressure (Source: Tank)") current_ramp_cycle = i # Interval added / subtracted to help make range function more # intuitive for p in range(pressure_tank_start, pressure_tank_end + pressure_interval, pressure_interval): logging.debug(p) self.record_solenoid_pressure(p) if self.daq.u.failed: self.close_house_air() self.pneumatics.setRegulatorPressure(0) self.pneumatics.setPumpPressure(0) if (p >= 10 or p <= 25): t = self.daq.u return t for p in range(pressure_tank_end, pressure_tank_start - pressure_interval, -pressure_interval): logging.debug(p) self.record_solenoid_pressure(p) if self.daq.u.failed: self.close_house_air() self.pneumatics.setRegulatorPressure(0) self.pneumatics.setPumpPressure(0) print(self.daq.u.data.split()) t = self.daq.u return t self.close_house_air() self.daq.display_test_results() t.success("Pressure test run successfully") return t def test_Diagnostics_trial_house(self): t = ResponseData() # Test Failure Criteria pressure_house_start = 30 # Beginning of house air pressure test pressure_house_end = 80 # Highest pressure reached while testing house air pressure_interval = 5 # Interval in which the pressure increases between bounds global current_ramp_cycle with cd(path): g = self.g task = AnalogInputTask() self.close_house_air() for i in range(0, self.pressure_ramp_cycles): # Ensure solenoid is closed at start # Ensure Solenoid is closed self.close_solenoid() # Set tank pressure to 40psi self.pneumatics.setPumpPressure(40) logging.info("Testing Output Pressure (Source: House Air)") self.open_house_air() for i in range(0, self.pressure_ramp_cycles): # Ensure solenoid is closed at start # Ensure Solenoid is closed self.close_solenoid() # Set tank pressure to 40psi self.pneumatics.setPumpPressure(40) current_ramp_cycle = i # Interval added / subtracted to help make range function more # intuitive for p in range(pressure_house_start, pressure_house_end + pressure_interval, pressure_interval): logging.debug(p) self.record_solenoid_pressure(p) if self.daq.u.failed: self.close_house_air() self.pneumatics.setRegulatorPressure(0) self.pneumatics.setPumpPressure(0) for p in range(pressure_house_end, pressure_house_start - pressure_interval, -pressure_interval): logging.debug(p) self.record_solenoid_pressure(p) if self.daq.u.failed: self.close_house_air() self.pneumatics.setRegulatorPressure(0) self.pneumatics.setPumpPressure(0) self.close_house_air() self.daq.display_test_results() t.success("Pressure test run successfully") return t def open_solenoid(self): self.g.write('M42 P8 S255') # Open solenoid (Fan 0) def close_solenoid(self): self.g.write('M42 P8 S0') # Close solenoid (Fan 0) def open_house_air(self): self.g.write('M42 P6 S255') # Open solenoid (Fan 1) def close_house_air(self): self.g.write('M42 P6 S0') # Close solenoid (Fan 1)
from nidaqmx import AnalogInputTask import numpy as np from __future__ import print_function from six.moves import input task = AnalogInputTask() task.create_voltage_channel('Dev1/ai16', terminal='rse', min_val=-10.0, max_val=10.0) task.configure_timing_sample_clock(rate=1000.0) def callback(task, event_type, samples, callback_data): print() data = task.read(samples, samples_per_channel=samples, fill_mode='group_by_scan_number') print('Acquired %s samples' % (len(data))) print(data[:10]) return 0 def callback_done(task, status, callback_data): print('callback_done, status=', status) return 0 #task.register_every_n_samples_event(callback, samples = 100) #task.register_done_event(callback_done)
from nidaqmx import AnalogInputTask import numpy as np from __future__ import print_function from six.moves import input task = AnalogInputTask() task.create_voltage_channel('Dev1/ai16', terminal = 'rse', min_val=-10.0, max_val=10.0) task.configure_timing_sample_clock(rate = 1000.0) def callback (task, event_type, samples, callback_data): print() data = task.read(samples, samples_per_channel=samples, fill_mode='group_by_scan_number') print('Acquired %s samples' % (len (data))) print(data[:10]) return 0 def callback_done(task, status, callback_data): print('callback_done, status=',status) return 0 #task.register_every_n_samples_event(callback, samples = 100) #task.register_done_event(callback_done) task.start() if 1: from pylab import plot, show data = task.read(3000, fill_mode='group_by_channel')
def __init__(self, channels, minv=-10.0, maxv=10.0, srate=1000, snum=1000): self._sensor = AnalogInputTask() self._sensor.create_voltage_channel(channels, min_val=minv, max_val=maxv) self._sensor.configure_timing_sample_clock(rate=srate, sample_mode='finite', samples_per_channel=snum)
class Sensors: def __init__(self, channels, minv=-10.0, maxv=10.0, srate=1000, snum=1000): self._sensor = AnalogInputTask() self._sensor.create_voltage_channel(channels, min_val=minv, max_val=maxv) self._sensor.configure_timing_sample_clock(rate=srate, sample_mode='finite', samples_per_channel=snum) def start(self): self._sensor.start() def stop(self): self._sensor.stop() def wait_until_done(self, timeout = 10): self._sensor.wait_until_done(timeout) def read(self): return self._sensor.read()
def test_Diagnostics_trial_pump(self): t = ResponseData() # Test Failure Criteria pump_to_pressure_time = 60 pump_pressure = 40 pump_pressure_acceptable_bound = 2 pressure_tank_start = 0 # Beginning pressure while testing for tank pressure pressure_tank_end = 30 # Highest pressure reached while testing on tank pressure pressure_interval = 5 # Interval in which the pressure increases between bounds global current_ramp_cycle with cd(path): g = self.g task = AnalogInputTask() self.close_house_air() for i in range(0, self.pressure_ramp_cycles): # Ensure solenoid is closed at start self.close_solenoid() # Set tank pressure to pump pressure self.pneumatics.setPumpPressure(pump_pressure) # Wait for pump to reach pressure for i in range(pump_to_pressure_time): p = self.pneumatics.readPumpPressure() if p > pump_pressure - pump_pressure_acceptable_bound: break if i is pump_to_pressure_time - 1: t.fail("Didn't reach pump pressure") return t sleep(1) logging.debug("Pump Pressure: {}".format(p)) logging.info("Testing Output Pressure (Source: Tank)") current_ramp_cycle = i # Interval added / subtracted to help make range function more # intuitive for p in range(pressure_tank_start, pressure_tank_end + pressure_interval, pressure_interval): logging.debug(p) self.record_solenoid_pressure(p) if self.daq.u.failed: self.close_house_air() self.pneumatics.setRegulatorPressure(0) self.pneumatics.setPumpPressure(0) if (p >= 10 or p <= 25): t = self.daq.u return t for p in range(pressure_tank_end, pressure_tank_start - pressure_interval, -pressure_interval): logging.debug(p) self.record_solenoid_pressure(p) if self.daq.u.failed: self.close_house_air() self.pneumatics.setRegulatorPressure(0) self.pneumatics.setPumpPressure(0) print(self.daq.u.data.split()) t = self.daq.u return t self.close_house_air() self.daq.display_test_results() t.success("Pressure test run successfully") return t
class Pneumatics_Test_NIDAQ(object): """ Test module for the pneumatics system, e-regulator, and solenoid. This class is used to run tests on the pneumatics sled, and cartridge. """ def __init__(self, test, logging, regulator): """Initialize the NIDAQ extended Pneumatics test, with the supplied overall test and logger. Args: test (testRunner): The testrunner used to call the Pneumatics Test, allowing the use of test failing / passing / warnings. logging (logger): Allows whatever preconfigured logging module used in the main program to be accessed in this file.. """ self.g = test.g self.test = test logging.debug("Initialized NIDAQ Extend Pneumatics Test") self.pneumatics = Pneumatics_Test(test, logging) # Basic defines for running the test, used further on self.pressure_ramp_cycles = 1 # Total number cycles the test is run self.sample_rate = 1000 # Sampling rate (Hz) self.solenoid_toggle_cycles = 1 # Number of solenoid_toggle_cycles to toggle solenoid at each pressure self.wait_time_s = 1 # Wait for regulator to reach pressure in between solenoid toggles self.checkpoint = 5 # Save full data every _ solenoid solenoid_toggle_cycles, if 0 don't save self.ID = str( regulator) # Name of the file saved in the directory by the logger # Miscellanous setup self.outputdirectory = None # Allows us ot set the output directory later with the logger self.task = AnalogInputTask() # Used to read from the DAQ self.task.create_voltage_channel('Dev1/ai0', terminal='diff', min_val=-5.0, max_val=5.0) self.task.configure_timing_sample_clock(rate=self.sample_rate) with cd(path): self.daq = DAQ(self) # Sets the directory that the logger logs in def record_solenoid_pressure(self, pressure): # Set regulator pressure self.pneumatics.setRegulatorPressure(pressure) time.sleep(3) for cycle in range(0, self.solenoid_toggle_cycles): self.daq.record(int(self.sample_rate * self.wait_time_s), cycle, pressure) # Open recording thread self.open_solenoid() time.sleep(self.wait_time_s) self.close_solenoid() time.sleep(1) def test_Diagnostics_trial_pump(self): t = ResponseData() # Test Failure Criteria pump_to_pressure_time = 60 pump_pressure = 40 pump_pressure_acceptable_bound = 2 pressure_tank_start = 0 # Beginning pressure while testing for tank pressure pressure_tank_end = 30 # Highest pressure reached while testing on tank pressure pressure_interval = 5 # Interval in which the pressure increases between bounds global current_ramp_cycle with cd(path): g = self.g task = AnalogInputTask() self.close_house_air() for i in range(0, self.pressure_ramp_cycles): # Ensure solenoid is closed at start self.close_solenoid() # Set tank pressure to pump pressure self.pneumatics.setPumpPressure(pump_pressure) # Wait for pump to reach pressure for i in range(pump_to_pressure_time): p = self.pneumatics.readPumpPressure() if p > pump_pressure - pump_pressure_acceptable_bound: break if i is pump_to_pressure_time - 1: t.fail("Didn't reach pump pressure") return t sleep(1) logging.debug("Pump Pressure: {}".format(p)) logging.info("Testing Output Pressure (Source: Tank)") current_ramp_cycle = i # Interval added / subtracted to help make range function more # intuitive for p in range(pressure_tank_start, pressure_tank_end + pressure_interval, pressure_interval): logging.debug(p) self.record_solenoid_pressure(p) if self.daq.u.failed: self.close_house_air() self.pneumatics.setRegulatorPressure(0) self.pneumatics.setPumpPressure(0) if (p >= 10 or p <= 25): t = self.daq.u return t for p in range(pressure_tank_end, pressure_tank_start - pressure_interval, -pressure_interval): logging.debug(p) self.record_solenoid_pressure(p) if self.daq.u.failed: self.close_house_air() self.pneumatics.setRegulatorPressure(0) self.pneumatics.setPumpPressure(0) print(self.daq.u.data.split()) t = self.daq.u return t self.close_house_air() self.daq.display_test_results() t.success("Pressure test run successfully") return t def test_Diagnostics_trial_house(self): t = ResponseData() # Test Failure Criteria pressure_house_start = 30 # Beginning of house air pressure test pressure_house_end = 80 # Highest pressure reached while testing house air pressure_interval = 5 # Interval in which the pressure increases between bounds global current_ramp_cycle with cd(path): g = self.g task = AnalogInputTask() self.close_house_air() for i in range(0, self.pressure_ramp_cycles): # Ensure solenoid is closed at start # Ensure Solenoid is closed self.close_solenoid() # Set tank pressure to 40psi self.pneumatics.setPumpPressure(40) logging.info("Testing Output Pressure (Source: House Air)") self.open_house_air() for i in range(0, self.pressure_ramp_cycles): # Ensure solenoid is closed at start # Ensure Solenoid is closed self.close_solenoid() # Set tank pressure to 40psi self.pneumatics.setPumpPressure(40) current_ramp_cycle = i # Interval added / subtracted to help make range function more # intuitive for p in range(pressure_house_start, pressure_house_end + pressure_interval, pressure_interval): logging.debug(p) self.record_solenoid_pressure(p) if self.daq.u.failed: self.close_house_air() self.pneumatics.setRegulatorPressure(0) self.pneumatics.setPumpPressure(0) for p in range(pressure_house_end, pressure_house_start - pressure_interval, -pressure_interval): logging.debug(p) self.record_solenoid_pressure(p) if self.daq.u.failed: self.close_house_air() self.pneumatics.setRegulatorPressure(0) self.pneumatics.setPumpPressure(0) self.close_house_air() self.daq.display_test_results() t.success("Pressure test run successfully") return t def open_solenoid(self): self.g.write('M42 P8 S255') # Open solenoid (Fan 0) def close_solenoid(self): self.g.write('M42 P8 S0') # Close solenoid (Fan 0) def open_house_air(self): self.g.write('M42 P6 S255') # Open solenoid (Fan 1) def close_house_air(self): self.g.write('M42 P6 S0') # Close solenoid (Fan 1)
def test_Diagnostics_trial_house(self): t = ResponseData() # Test Failure Criteria pressure_house_start = 30 # Beginning of house air pressure test pressure_house_end = 80 # Highest pressure reached while testing house air pressure_interval = 5 # Interval in which the pressure increases between bounds global current_ramp_cycle with cd(path): g = self.g task = AnalogInputTask() self.close_house_air() for i in range(0, self.pressure_ramp_cycles): # Ensure solenoid is closed at start # Ensure Solenoid is closed self.close_solenoid() # Set tank pressure to 40psi self.pneumatics.setPumpPressure(40) logging.info("Testing Output Pressure (Source: House Air)") self.open_house_air() for i in range(0, self.pressure_ramp_cycles): # Ensure solenoid is closed at start # Ensure Solenoid is closed self.close_solenoid() # Set tank pressure to 40psi self.pneumatics.setPumpPressure(40) current_ramp_cycle = i # Interval added / subtracted to help make range function more # intuitive for p in range(pressure_house_start, pressure_house_end + pressure_interval, pressure_interval): logging.debug(p) self.record_solenoid_pressure(p) if self.daq.u.failed: self.close_house_air() self.pneumatics.setRegulatorPressure(0) self.pneumatics.setPumpPressure(0) for p in range(pressure_house_end, pressure_house_start - pressure_interval, -pressure_interval): logging.debug(p) self.record_solenoid_pressure(p) if self.daq.u.failed: self.close_house_air() self.pneumatics.setRegulatorPressure(0) self.pneumatics.setPumpPressure(0) self.close_house_air() self.daq.display_test_results() t.success("Pressure test run successfully") return t
def readPressureAndTemperature(plot=False): RATE = 250.0 DURATION = 5.0 NUMBER_OF_SAMPLES = (int)(math.ceil(DURATION*RATE)) task = AnalogInputTask() #Ion pump task.create_voltage_channel('Dev2/ai2', terminal = 'rse', min_val=-1.0, max_val=1.0) #Turbo temperature task.create_voltage_channel('Dev2/ai4', terminal = 'rse', min_val=0, max_val=1.0) task.configure_timing_sample_clock(rate = RATE) #print task.get_convert_clock_rate() task.set_convert_clock_rate(1000) #print task.get_convert_clock_rate() task.start() #print task.get_ai_convert_max_rate() data = task.read(NUMBER_OF_SAMPLES, fill_mode='group_by_channel') del task if plot: from pylab import plot, show x = np.arange(0,DURATION,1.0/RATE) plot (x,data[0],'ro') plot (x,data[1],'bo') show () a = np.sum(data[0])/NUMBER_OF_SAMPLES ionpump = math.exp(a * 1000 * 0.124) * 2.9741e-9 a = np.sum(data[1])/NUMBER_OF_SAMPLES turbo_temp = (a-0.4)/0.0195 return(ionpump,turbo_temp)