pdq2 frontends: adapt to new program, cleanup

This commit is contained in:
Robert Jördens 2016-02-21 17:35:10 +01:00
parent 7c246b3559
commit d713c62b50
2 changed files with 38 additions and 60 deletions

View File

@ -28,25 +28,17 @@ def get_argparser():
parser.add_argument("-u", "--voltages",
default="(1-np.cos(t/t[-1]*2*np.pi))/2",
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,
help="interpolation (0: const, 1: lin, 2: quad,"
" 3: cubic) [%(default)s]")
parser.add_argument("-p", "--plot", help="plot to file [%(default)s]")
parser.add_argument("-r", "--reset", default=False,
action="store_true", help="do reset before")
parser.add_argument("-m", "--dcm", default=False, action="store_true",
help="100MHz clock [%(default)s]")
parser.add_argument("-m", "--multiplier", default=False,
action="store_true", help="100MHz clock [%(default)s]")
parser.add_argument("-n", "--disarm", default=False, action="store_true",
help="disarm group [%(default)s]")
parser.add_argument("-e", "--free", default=False, action="store_true",
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)
return parser
@ -60,57 +52,44 @@ def main():
dev.write(b"\x00\x00") # flush any escape
dev.cmd("RESET", True)
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("ARM", False)
dev.cmd("DCM", args.dcm)
freq = 100e6 if args.dcm else 50e6
dev.set_freq(freq)
times = eval(args.times, globals(), {})
voltages = eval(args.voltages, globals(), dict(t=times))
dev.cmd("ARM", True)
dev.cmd("TRIGGER", True)
dev.flush()
if args.demo:
for ch, channel in enumerate(dev.channels):
entry = []
for fr in range(dev.channels[0].num_frames):
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)])
dt = np.diff(times.astype(np.int))
if args.order:
tck = interpolate.splrep(times, voltages, k=args.order, s=0)
u = interpolate.spalde(times, tck)
else:
c = dev.channels[args.channel]
map = [None] * c.num_frames
map[args.frame] = c.segment(times, voltages, order=args.order,
aux=args.aux)
dev.write_channel(c, map)
u = voltages[:, None]
segment = []
for dti, ui in zip(dt, u):
segment.append({
"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)
if args.plot:
from matplotlib import pyplot as plt
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)
dev.cmd("ARM", not args.disarm)
dev.cmd("START", True)
dev.flush()
if __name__ == "__main__":

View File

@ -12,8 +12,7 @@ def get_argparser():
parser = argparse.ArgumentParser(description="PDQ2 controller")
simple_network_args(parser, 3252)
parser.add_argument(
"-d", "--device", default=None,
help="serial port.")
"-d", "--device", default=None, help="serial port.")
parser.add_argument(
"--simulation", action="store_true",
help="Put the driver in simulation mode, even if --device is used.")
@ -38,8 +37,8 @@ def main():
port = open(args.dump, "wb")
dev = Pdq2(url=args.device, dev=port)
try:
simple_server_loop({"pdq2": dev}, bind_address_from_args(args), args.port,
description="device=" + str(args.device))
simple_server_loop({"pdq2": dev}, bind_address_from_args(args),
args.port, description="device=" + str(args.device))
finally:
dev.close()