-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hil_plot : hardware in the loop with plotting
needs numpy and matplotlib modified: awg_data.py new file: hil_plot.py
- Loading branch information
1 parent
e5be258
commit bf3158e
Showing
2 changed files
with
104 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#!/usr/bin/env python | ||
# Harware In Loop : load AO data,run a shot, get AI data, repeat. | ||
# upload to AWG and optionally run a capture. | ||
# data for upload is either File (host-local data file) or Rainbow, a test pattern. | ||
# assumes that clocking has been pre-assigned. | ||
|
||
import sys | ||
import acq400_hapi | ||
import awg_data | ||
import argparse | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
|
||
def store_file(it, rdata, nchan, nsam): | ||
fn = 'DATA/ai%04d.dat' % (it) | ||
print("store_file {}".format(fn)) | ||
|
||
with open(fn, 'w') as f: | ||
f.write(rdata) | ||
|
||
def plot(it, rdata, nchan, nsam): | ||
raw = np.fromstring(rdata, dtype=np.int16) | ||
chx = np.reshape(raw, (nsam, nchan)) | ||
for ch in range(0,nchan): | ||
plt.plot(chx[:,ch]) | ||
|
||
plt.show() | ||
plt.pause(0.0001) | ||
|
||
def run_shots(args): | ||
uut = acq400_hapi.Acq400(args.uuts[0]) | ||
acq400_hapi.cleanup.init() | ||
if args.plot: | ||
plt.ion() | ||
|
||
uut.s0.transient = 'POST=%d SOFT_TRIGGER=%d DEMUX=0' % \ | ||
(args.post, 1 if args.trg == 'int' else 0) | ||
|
||
for sx in uut.modules: | ||
uut.modules[sx].trg = '1,1,1' if args.trg == 'int' else '1,0,1' | ||
|
||
if args.files != "": | ||
work = awg_data.RunsFiles(uut, args.files.split(','), run_forever=True) | ||
else: | ||
work = awg_data.RainbowGen(uut, args.nchan, args.awglen, run_forever=True) | ||
|
||
store = store_file | ||
loader = work.load() | ||
for ii in range(0, args.loop): | ||
print("shot: %d" % (ii)) | ||
f = loader.next() | ||
print("Loaded %s" % (f)) | ||
uut.run_oneshot() | ||
print("read_chan %d" % (args.post*args.nchan)) | ||
rdata = uut.read_chan(0, args.post*args.nchan) | ||
store(ii, rdata, args.nchan, args.post) | ||
if args.plot > 0 : | ||
if args.plot == 1: | ||
plt.cla() | ||
plt.title("AI for shot %d %s" % (ii, "persistent plot" if args.plot > 1 else "")) | ||
plot(ii, rdata, args.nchan, args.post) | ||
|
||
raw_input("hit return when done") | ||
|
||
|
||
def run_main(): | ||
parser = argparse.ArgumentParser(description='acq1001 HIL demo') | ||
parser.add_argument('--files', default="", help="list of files to load") | ||
parser.add_argument('--loop', type=int, default=1, help="loop count") | ||
parser.add_argument('--nchan', type=int, default=32, help='channel count for pattern') | ||
parser.add_argument('--awglen', type=int, default=2048, help='samples in AWG waveform') | ||
parser.add_argument('--post', type=int, default=100000, help='samples in ADC waveform') | ||
parser.add_argument('--trg', default="int", help='trg "int|ext rising|falling"') | ||
parser.add_argument('--plot', type=int, default=1, help='--plot 1 : plot data, 2: persistent') | ||
parser.add_argument('uuts', nargs=1, help="uut ") | ||
run_shots(parser.parse_args()) | ||
|
||
# execution starts here | ||
|
||
if __name__ == '__main__': | ||
run_main() | ||
|