forked from M-Labs/artiq
pdq2 frontends: adapt to new program, cleanup
This commit is contained in:
parent
7c246b3559
commit
d713c62b50
|
@ -28,25 +28,17 @@ def get_argparser():
|
||||||
parser.add_argument("-u", "--voltages",
|
parser.add_argument("-u", "--voltages",
|
||||||
default="(1-np.cos(t/t[-1]*2*np.pi))/2",
|
default="(1-np.cos(t/t[-1]*2*np.pi))/2",
|
||||||
help="sample voltages (V) [%(default)s]")
|
help="sample voltages (V) [%(default)s]")
|
||||||
parser.add_argument("-a", "--aux", default=False, action="store_true",
|
|
||||||
help="axiliary digital output [%(default)%s]")
|
|
||||||
parser.add_argument("-o", "--order", default=3, type=int,
|
parser.add_argument("-o", "--order", default=3, type=int,
|
||||||
help="interpolation (0: const, 1: lin, 2: quad,"
|
help="interpolation (0: const, 1: lin, 2: quad,"
|
||||||
" 3: cubic) [%(default)s]")
|
" 3: cubic) [%(default)s]")
|
||||||
parser.add_argument("-p", "--plot", help="plot to file [%(default)s]")
|
|
||||||
parser.add_argument("-r", "--reset", default=False,
|
parser.add_argument("-r", "--reset", default=False,
|
||||||
action="store_true", help="do reset before")
|
action="store_true", help="do reset before")
|
||||||
parser.add_argument("-m", "--dcm", default=False, action="store_true",
|
parser.add_argument("-m", "--multiplier", default=False,
|
||||||
help="100MHz clock [%(default)s]")
|
action="store_true", help="100MHz clock [%(default)s]")
|
||||||
parser.add_argument("-n", "--disarm", default=False, action="store_true",
|
parser.add_argument("-n", "--disarm", default=False, action="store_true",
|
||||||
help="disarm group [%(default)s]")
|
help="disarm group [%(default)s]")
|
||||||
parser.add_argument("-e", "--free", default=False, action="store_true",
|
parser.add_argument("-e", "--free", default=False, action="store_true",
|
||||||
help="software trigger [%(default)s]")
|
help="software trigger [%(default)s]")
|
||||||
parser.add_argument("-x", "--demo", default=False, action="store_true",
|
|
||||||
help="demo mode: pulse and chirp, 1V*ch+0.1V*frame"
|
|
||||||
" [%(default)s]")
|
|
||||||
parser.add_argument("-b", "--bit", default=False,
|
|
||||||
action="store_true", help="do bit test")
|
|
||||||
verbosity_args(parser)
|
verbosity_args(parser)
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
|
@ -60,57 +52,44 @@ def main():
|
||||||
dev.write(b"\x00\x00") # flush any escape
|
dev.write(b"\x00\x00") # flush any escape
|
||||||
dev.cmd("RESET", True)
|
dev.cmd("RESET", True)
|
||||||
time.sleep(.1)
|
time.sleep(.1)
|
||||||
|
|
||||||
|
dev.cmd("DCM", args.multiplier)
|
||||||
|
freq = 50e6
|
||||||
|
if args.multiplier:
|
||||||
|
freq *= 2
|
||||||
|
|
||||||
|
times = np.around(eval(args.times, globals(), {})*freq)
|
||||||
|
voltages = eval(args.voltages, globals(), dict(t=times/freq))
|
||||||
|
|
||||||
dev.cmd("START", False)
|
dev.cmd("START", False)
|
||||||
dev.cmd("ARM", False)
|
dev.cmd("ARM", True)
|
||||||
dev.cmd("DCM", args.dcm)
|
dev.cmd("TRIGGER", True)
|
||||||
freq = 100e6 if args.dcm else 50e6
|
dev.flush()
|
||||||
dev.set_freq(freq)
|
|
||||||
times = eval(args.times, globals(), {})
|
|
||||||
voltages = eval(args.voltages, globals(), dict(t=times))
|
|
||||||
|
|
||||||
if args.demo:
|
dt = np.diff(times.astype(np.int))
|
||||||
for ch, channel in enumerate(dev.channels):
|
if args.order:
|
||||||
entry = []
|
tck = interpolate.splrep(times, voltages, k=args.order, s=0)
|
||||||
for fr in range(dev.channels[0].num_frames):
|
u = interpolate.spalde(times, tck)
|
||||||
vi = .1*fr + ch + voltages
|
|
||||||
entry.append(channel.segment(times, vi, order=args.order,
|
|
||||||
end=False, aux=args.aux))
|
|
||||||
pi = 2*np.pi*(-.5 + .01*fr + .1*ch + 0*voltages)
|
|
||||||
fi = 10e6*times/times[-1]
|
|
||||||
channel.segment(2*times, voltages, pi, fi, trigger=False,
|
|
||||||
silence=True, aux=args.aux)
|
|
||||||
dev.write_channel(channel, entry)
|
|
||||||
elif args.bit:
|
|
||||||
v = [-1, 0, -1]
|
|
||||||
# for i in range(15):
|
|
||||||
# v.extend([(1 << i) - 1, 1 << i])
|
|
||||||
v = np.array(v)*dev.channels[0].max_out/dev.channels[0].max_val
|
|
||||||
t = np.arange(len(v))
|
|
||||||
for channel in dev.channels:
|
|
||||||
s = channel.segment(t, v, order=0, shift=15, stop=False,
|
|
||||||
trigger=False)
|
|
||||||
dev.write_channel(channel, [s for i in range(channel.num_frames)])
|
|
||||||
else:
|
else:
|
||||||
c = dev.channels[args.channel]
|
u = voltages[:, None]
|
||||||
map = [None] * c.num_frames
|
segment = []
|
||||||
map[args.frame] = c.segment(times, voltages, order=args.order,
|
for dti, ui in zip(dt, u):
|
||||||
aux=args.aux)
|
segment.append({
|
||||||
dev.write_channel(c, map)
|
"duration": int(dti),
|
||||||
|
"channel_data": [{
|
||||||
|
"bias": {
|
||||||
|
"amplitude": [float(uij) for uij in ui]
|
||||||
|
}
|
||||||
|
}]
|
||||||
|
})
|
||||||
|
program = [[] for i in range(args.frame)]
|
||||||
|
program.append(segment)
|
||||||
|
dev.program(program, [args.channel])
|
||||||
|
|
||||||
dev.cmd("START", True)
|
|
||||||
dev.cmd("ARM", not args.disarm)
|
|
||||||
dev.cmd("TRIGGER", args.free)
|
dev.cmd("TRIGGER", args.free)
|
||||||
|
dev.cmd("ARM", not args.disarm)
|
||||||
if args.plot:
|
dev.cmd("START", True)
|
||||||
from matplotlib import pyplot as plt
|
dev.flush()
|
||||||
fig, ax = plt.subplots()
|
|
||||||
ax.plot(times, voltages, "xk", label="points")
|
|
||||||
if args.order > 0:
|
|
||||||
spline = interpolate.splrep(times, voltages, k=args.order)
|
|
||||||
ttimes = np.arange(0, times[-1], 1/freq)
|
|
||||||
vvoltages = interpolate.splev(ttimes, spline)
|
|
||||||
ax.plot(ttimes, vvoltages, ",b", label="interpolation")
|
|
||||||
fig.savefig(args.plot)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
@ -12,8 +12,7 @@ def get_argparser():
|
||||||
parser = argparse.ArgumentParser(description="PDQ2 controller")
|
parser = argparse.ArgumentParser(description="PDQ2 controller")
|
||||||
simple_network_args(parser, 3252)
|
simple_network_args(parser, 3252)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-d", "--device", default=None,
|
"-d", "--device", default=None, help="serial port.")
|
||||||
help="serial port.")
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--simulation", action="store_true",
|
"--simulation", action="store_true",
|
||||||
help="Put the driver in simulation mode, even if --device is used.")
|
help="Put the driver in simulation mode, even if --device is used.")
|
||||||
|
@ -38,8 +37,8 @@ def main():
|
||||||
port = open(args.dump, "wb")
|
port = open(args.dump, "wb")
|
||||||
dev = Pdq2(url=args.device, dev=port)
|
dev = Pdq2(url=args.device, dev=port)
|
||||||
try:
|
try:
|
||||||
simple_server_loop({"pdq2": dev}, bind_address_from_args(args), args.port,
|
simple_server_loop({"pdq2": dev}, bind_address_from_args(args),
|
||||||
description="device=" + str(args.device))
|
args.port, description="device=" + str(args.device))
|
||||||
finally:
|
finally:
|
||||||
dev.close()
|
dev.close()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue