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 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 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))
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)
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