Esempio n. 1
0
name = 'Multichannel_Settling_Time'

# Other parameters
duration = periods_to_measure / signal_frequency
samples_to_measure = int(samplerate * duration / 1000)

number_of_channels = 3
channels_to_test = [
    #                    "Dev20/ao0",
    "Dev20/ao1",
    #                    "Dev20/ao2",
]

signal_slope = signal_pk_amplitude * signal_frequency

filename = sav.savefile_helper(name, 'NChannels_{}.txt')

header = 'Time [s]\tData [V]'

# ACTIVE CODE
seno = wm.Wave('sine', 100)
'''
class nidaqmx.stream_writers.AnalogMultiChannelWriter
write_many_sample(data, timeout=10.0)
data (numpy.ndarray) – Contains a 2D NumPy array of floating-point samples to
write to the task.
Each row corresponds to a channel in the task. Each column corresponds to a sample to
write to each channel. The order of the channels in the array corresponds to the order in
which you add the channels to the task.

'''
Esempio n. 2
0
# Calculate some stuff
velocity = calculate_velocity(signal)
time = np.arange(0, nsamples / samplerate, 1 / samplerate)
print(velocity)

# Configure saving
header = ['Time (s)', 'Voltage (V)']
footer = dict(ai_conf=ai_conf,
              pwm_frequency=pwm_frequency,
              pwm_duty_cycle=pwm_duty_cycle,
              pwm_supply=pwm_supply,
              samplerate=samplerate,
              velocity=velocity)

# Save
function = savefile_helper('Velocity', 'Duty_{:.2f}.txt')
savetxt(function(pwm_duty_cycle),
        np.array([time, signal]).T,
        header=header,
        footer=footer)

#%% Velocity_With_DAQ_PWM
"""Measures velocity for a given duty cycle on the DAQ's PWM"""

# PARAMETERS

device = daq.devices()[0]

ai_pin = 15  # Literally the number of the DAQ pin
ai_conf = 'Ref'  # Referenced mode (measure against GND)
Esempio n. 3
0
# Signal's Configuration
signal_frequency = 10
signal_pk_amplitude = 2
periods_to_measure = 50

# PID's Configuration
pidvalue=1
pidconstant=0.1

# ACTIVE CODE

# Other configuration
duration = periods_to_measure/signal_frequency
samples_to_measure = int(samplerate * duration/1000)
filename = sav.savefile_helper(dirname = name, 
                               filename_template = 'NChannels_{}.txt')
header = 'Time [s]\tData [V]'

# First I make a ramp
waveform= wm.Wave('triangular', frequency=10, amplitude=1)
output_array = waveform.evaluate_sr(sr=samplerate, duration=duration)

# Now I define a callback function
def callback(task_handle, every_n_samples_event_type,
             number_of_samples, callback_data):
    
    print('Every N Samples callback invoked.')

    samples = reader.read_many_sample(
            values_read, 
            number_of_samples_per_channel=number_of_samples,
Esempio n. 4
0
periods_to_measure = 10
signal_config = dict(
    frequency=100000,  #Hz
    amplitude=2,  #Vpp
    waveform='ram100')

gen = ins.Gen('USB::0x0699::0x0346::C034167::INSTR', nchannels=1)

name = 'Interbuffer_Time'

# Other parameters
duration = periods_to_measure / signal_frequency
samples_to_measure = int(samplerate * duration)

filename = sav.savefile_helper(name, 'signal_{}Hz_{}Vpp.txt')
header = 'Time [s]\tData [V]'
footer = 'Signal: {frequency:.0f}Hz, {amplitude}Vpp, {waveform}'.format(
    **signal_config)

# ACTIVE CODE

#gen.output(True, waveform='ramp',
#           frequency=signal_frequency,
#           amplitude=2)
with nid.Task() as task:

    # Configure channel

    task.ai_channels.add_ai_voltage_chan("Dev20/ai1", terminal_config=mode)
Esempio n. 5
0
########################## DATA MANAGEMENT ##########################

# Configure data log
header = [
    'Time (s)', 'Velocity (cm/s)', 'Duty cycle (%)',
    'Proportional term (u.a.)', 'Integral term (u.a.)',
    'Derivative term (u.a.)'
]
footer = dict(ai_conf=ai_conf,
              pwm_frequency=pwm_frequency,
              samplerate=samplerate,
              nsamples_each=nsamples_each,
              pwm_min_duty_cycle=pwm_min_duty_cycle * 100,
              pwm_initial_duty_cycle=pwm_initial_duty_cycle * 100,
              **pid.params)
filename_generator = sav.savefile_helper(filename_folder, filename_mask)

# Get data
v = virtual_to_real(np.array(pid.log.feedback_value))
dc = np.array(pid.log.new_value) * 100  # User's DC is % but DAQ's is 0-1
t = np.linspace(0, len(v) * dT, len(v))
p = np.array(pid.log.p_term)
i = np.array(pid.log.i_term)
d = np.array(pid.log.d_term)
e = virtual_to_real(p)

# Calculate PID data to plot
pterm = p * pid.kp / dc
iterm = i * pid.ki / dc
dterm = d * pid.kd / dc
Esempio n. 6
0
#    dt = 1 / samplerate
#    photogate_frequency = photogate_frequency / dt
#    velocity = circunference * photogate_frequency / chopper_sections
#    return velocity

foldernames = ['PID_15_setpoint', 'PID_1.5_setpoint',
              'PID_1_setpoint', 'PID_4_setpoint']

for foldername in foldernames:#['PID_1_setpoint']:

    # Get filenames and footers
    folder = os.path.join(os.getcwd(), 'Measurements',foldername)
    files = [os.path.join(folder, f)
             for f in os.listdir(folder) if f.startswith('Log')]
    saveplot_mask = '{:.0f}_setpoint_{:.2f}_kp_{:.2f}_ki_{:.2f}_kd_{:.2f}.pdf'
    saveplot_filename = sav.savefile_helper(foldername+' figs', saveplot_mask)
                 
    for z in range(len(files)):#range(1):
        num=z
        fileinuse=files[num]
        footers=sav.retrieve_footer(fileinuse)
        t, v, dc, pantes, iantes, dantes = np.loadtxt(fileinuse, unpack=True)
        i = np.array(iantes) * footers['ki'] / dc
        p = np.array(pantes) * footers['kp'] / dc
        d = np.array(dantes) * footers['kd'] / dc
        sp = footers['setpoint']
#        sp = virtual_to_real(footers['setpoint'], footers['samplerate'])
        #t=np.linspace(0, len(v)*footers['dt'], len(v))
        # Get data hidden on the footer
        """If I wanted them all...
        parameter_names = [n for n in footers[0].keys()]