artiq/artiq/frontend/pdq2_client.py

74 lines
2.5 KiB
Python
Raw Normal View History

2015-03-20 10:34:29 +08:00
#!/usr/bin/python
# Copyright (C) 2012-2015 Robert Jordens <jordens@gmail.com>
2014-10-14 16:38:02 +08:00
import argparse
from scipy import interpolate
import numpy as np
from artiq.protocols.pc_rpc import Client
2015-01-28 21:44:15 +08:00
from artiq.tools import verbosity_args, init_logger
2014-10-14 16:38:02 +08:00
2015-01-23 00:52:13 +08:00
def get_argparser():
2014-10-25 11:38:42 +08:00
parser = argparse.ArgumentParser(description="""PDQ2 client.
Evaluates times and voltages, interpolates and uploads
them to the controller.""")
parser.add_argument("-s", "--server", default="::1",
2014-10-27 20:34:33 +08:00
help="hostname or IP of the controller to connect to")
parser.add_argument("--port", default=3252, type=int,
2014-10-27 20:34:33 +08:00
help="TCP port to use to connect to the controller")
2014-10-14 16:38:02 +08:00
parser.add_argument("-c", "--channel", default=0, type=int,
2014-10-14 17:02:25 +08:00
help="channel: 3*board_num+dac_num [%(default)s]")
2014-10-14 16:38:02 +08:00
parser.add_argument("-f", "--frame", default=0, type=int,
2014-10-14 17:02:25 +08:00
help="frame [%(default)s]")
2015-03-20 10:34:29 +08:00
parser.add_argument("-t", "--times", default="np.arange(5)*1e-6",
2014-10-14 17:02:25 +08:00
help="sample times (s) [%(default)s]")
2015-03-20 12:26:12 +08:00
parser.add_argument("-u", "--voltages",
2014-10-14 17:02:25 +08:00
default="(1-np.cos(t/t[-1]*2*np.pi))/2",
help="sample voltages (V) [%(default)s]")
2014-10-14 16:38:02 +08:00
parser.add_argument("-o", "--order", default=3, type=int,
2015-03-20 10:34:29 +08:00
help="interpolation (0: const, 1: lin, 2: quad,"
" 3: cubic) [%(default)s]")
parser.add_argument("-e", "--free", default=False, action="store_true",
help="software trigger [%(default)s]")
2015-01-28 21:44:15 +08:00
verbosity_args(parser)
2015-01-23 00:52:13 +08:00
return parser
2014-10-14 16:38:02 +08:00
2015-01-22 10:38:47 +08:00
def main():
2015-01-23 00:52:13 +08:00
args = get_argparser().parse_args()
2015-01-28 21:44:15 +08:00
init_logger(args)
2014-10-28 15:45:56 +08:00
dev = Client(args.server, args.port, "pdq2")
2014-10-14 16:38:02 +08:00
freq = dev.get_freq()
times = np.around(eval(args.times, globals(), {})*freq)
voltages = eval(args.voltages, globals(), dict(t=times/freq))
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)
2014-10-14 16:38:02 +08:00
else:
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.park()
dev.program(program, [args.channel])
dev.unpark()
2015-03-20 10:34:29 +08:00
dev.cmd("TRIGGER", args.free)
2014-10-14 16:38:02 +08:00
2015-03-20 10:34:29 +08:00
2014-10-14 16:38:02 +08:00
if __name__ == "__main__":
2015-01-22 10:38:47 +08:00
main()