def __init__(self, chan_info) :
self.chan_info = chan_info
self.reserved = False
- if USE_COMEDI :
- self.AI = comedi_single_aio.ai_obj(chan=self.chan_info.inChan)
- self.AI.close()
- self.AO = comedi_single_aio.ao_obj(chan=self.chan_info.outChan)
- self.AO.close()
- else :
- self.AI = sngAI.sngAIobj(self.chan_info.inChan, -10, 10)
- self.AO = sngAO.sngAOobj(self.chan_info.outChan, -10, 10)
+ self.AI = single_aio.AI(chan=self.chan_info.inChan)
+ self.AI.close()
+ self.AO = single_aio.AO(chan=self.chan_info.outChan)
+ self.AO.close()
def reserve(self) :
- if USE_COMEDI :
- self.AI.open()
- self.AO.open()
- else :
- self.AI.reserve()
- self.AO.reserve()
+ self.AI.open()
+ self.AO.open()
self.reserved = True
def release(self) :
- if USE_COMEDI :
- self.AI.close()
- self.AO.close()
- else :
- self.AI.unreserve()
- self.AO.unreserve()
+ self.AI.close()
+ self.AO.close()
self.reserved = False
def updateInputs(self) :
if self.reserved == False :
self.AI.open()
#self.reserve()
self.reserved = False
- if USE_COMEDI :
- In = self.AI.read()
- else :
- (er, In) = self.AI.read()
+ In = self.AI.read()
if self.reserved == False :
self.AI.close()
#self.release()
self.release()
return self.updateInputs()
def out_to_phys(self, output) :
- if USE_COMEDI :
- return self.AO.comedi_to_phys(0, output)
+ return self.AO.comedi_to_phys(0, output)
def phys_to_out(self, physical) :
- if USE_COMEDI :
- return self.AO.phys_to_comedi(0, physical)
+ return self.AO.phys_to_comedi(0, physical)
class _z_piezo_ramp :
def __init__(self, chan_info) :
self.chan_info = chan_info
- self.verbose = True
self.attempts=0
self.failures=0
+ self.verbose = True
def ramp(self, outArray, freq) :
# allocate and run the task
npoints = int(len(outArray)/self.chan_info.numOut)
out_data[i] = outArray[i]
else :
out_data = outArray
+ if simult_aio.DONT_OUTPUT_LAST_SAMPLE_HACK == True:
+ # duplicate the last output point
+ npoints += 1
+ out_hack = array([0]*npoints*self.chan_info.numOut, dtype=uint16)
+ for i in range(npoints-1) :
+ out_hack[i] = out_data[i]
+ out_hack[-1] = out_data[-1]
+ out_data = out_hack
+ in_data = array([0]*npoints*self.chan_info.numIn, dtype=uint16)
correlated = False
ramp={}
while not correlated :
- if USE_COMEDI :
- AIO = comedi_simult_aio.aio_obj(in_chan=self.chan_info.inChan,
- out_chan=self.chan_info.outChan)
- if self.verbose :
- print "setup AIO"
- AIO.setup(freq, out_data)
- if self.verbose :
- print "arm AIO"
- AIO.arm()
- if self.verbose :
- print "read AIO"
- AIO.start_read(in_data)
- if self.verbose :
- print "close AIO"
- AIO.close()
- if self.verbose :
- print "finished AIO"
+ AIO = simult_aio.AIO(in_chan=self.chan_info.inChan,
+ out_chan=self.chan_info.outChan)
+ if self.verbose :
+ print "setup AIO"
+ AIO.setup(freq=freq, out_buffer=out_data)
+ if self.verbose :
+ print "arm AIO"
+ AIO.arm()
+ if self.verbose :
+ print "read AIO"
+ AIO.start_read(in_data)
+ if self.verbose :
+ print "close AIO"
+ AIO.close()
+ if self.verbose :
+ print "finished AIO"
self.attempts += 1
ramp["Z piezo output"] = out_data[self.chan_info.zp_ind::self.chan_info.numOut]
ramp["Z piezo input"] = in_data[self.chan_info.zp_mon_ind::self.chan_info.numIn]
+ ramp["Deflection input"] = in_data[self.chan_info.def_ind::self.chan_info.numIn]
failed = False
gradient, intercept, r_value, p_value, std_err = linregress(ramp["Z piezo output"],
ramp["Z piezo input"])
rnge = ramp["Z piezo output"].max()-ramp["Z piezo output"].min()
if gradient < .8 and rnge > 100 :
+ if PYLAB_INTERACTIVE_VERBOSE :
+ figure(BASE_FIG_NUM+3)
+ subplot(211)
+ title('ramp (def_in vs zp_out)')
+ timestamp = time.strftime('%H%M%S')
+ plot(ramp["Z piezo output"], ramp["Deflection input"], '.', label=timestamp)
+ subplot(212)
+ title('zp_in vs zp_out')
+ plot(ramp["Z piezo output"], ramp["Z piezo input"], '.', label=timestamp)
+ legend(loc='best')
print "ramp failed slope (%g, %g), try again" % (gradient, rnge)
failed = True
if not failed :
+ if simult_aio.DONT_OUTPUT_LAST_SAMPLE_HACK == True:
+ # remove the duplicated last output point
+ out_data = out_data[:-self.chan_info.numOut]
+ in_data = in_data[:-self.chan_info.numIn]
+ ramp["Z piezo output"] = out_data[self.chan_info.zp_ind::self.chan_info.numOut]
+ ramp["Z piezo input"] = in_data[self.chan_info.zp_mon_ind::self.chan_info.numIn]
+ ramp["Deflection input"] = in_data[self.chan_info.def_ind::self.chan_info.numIn]
+
if USE_ABCD_DEFLECTION :
ramp["Deflection segment"] = []
for c_ind in self.chan_info.def_ind :
C = ramp["Deflection segment"][2].astype(float)
D = ramp["Deflection segment"][3].astype(float)
ramp["Deflection input"] = (((A+B)-(C+D))/(A+B+C+D) * 2**15).astype(uint16)
- if USE_COMEDI :
- ramp["Deflection input"] += 2**15 # HACK, comedi uses unsigned ints...
+ ramp["Deflection input"] += 2**15 # HACK, comedi uses unsigned ints...
else :
ramp["Deflection input"] = in_data[self.chan_info.def_ind::self.chan_info.numIn]
correlated = True