From b7f93698e8e5f80d395dd8fa4aefb5f8b33da8ac Mon Sep 17 00:00:00 2001 From: Dan White Date: Mon, 27 Aug 2012 13:56:10 -0500 Subject: [PATCH] add plotting to calibration --- python-lib/calibrate.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/python-lib/calibrate.py b/python-lib/calibrate.py index 31ac82c..c64d220 100644 --- a/python-lib/calibrate.py +++ b/python-lib/calibrate.py @@ -1,5 +1,9 @@ +from termplotter import TermPlotter + +tplot = TermPlotter([-2**11, 2**11]) + def bisect(fset, limits=[0.0, 1.0], dgmin=None, up='uk', down='dj'): """Given a one-input function fset and list of limits, interactively bisect @@ -64,6 +68,7 @@ def mux_a_offset(x): sleep(DELAY) mv = mean(values) print xi, mv + print tplot(mv) return mv def mux_b_offset(x): @@ -77,6 +82,7 @@ def mux_b_offset(x): sleep(DELAY) mv = mean(values) print xi, mv + print tplot(mv) return mv def chain_a_offset(x, n, mux_offset): @@ -95,6 +101,7 @@ def chain_a_offset(x, n, mux_offset): sleep(DELAY) mv = mean(values) print xi, mv + print tplot(mv) return mv - mux_offset dac.vina(1.25) @@ -116,15 +123,16 @@ mux.write() adc.triggerMode(adc.MODE_MANUAL_MANUAL) -from scipy.optimize import brentq +#from scipy.optimize import brentq as fopt +from scipy.optimize import bisect as fopt N_SAMPLES = 10 -DELAY = 0.01 +DELAY = 0.05 print print 'Calibrating mux otaA' adc.mux(4) -resA = brentq(mux_a_offset, -128, 127, xtol=0.01, disp=True) +resA = fopt(mux_a_offset, -128, 127, xtol=0.01, disp=True) print resA muxA_offset = mean([offset2signed(adc.read(), 16) for i in range(1000)]) print '*** mux.otaA.offset =', int(round(resA)) @@ -134,7 +142,7 @@ if 0: print print 'Calibrating mux otaB' adc.mux(5) - resB = brentq(mux_b_offset, -128, 127, xtol=0.01, disp=True) + resB = fopt(mux_b_offset, -128, 127, xtol=0.01, disp=True) print resB muxB_offset = mean([offset2signed(adc.read(), 16) for i in range(1000)]) print '*** mux.otaB.offset =', int(round(resB)) @@ -150,7 +158,7 @@ for n in range(48): mux.otaA.mode = mux.otaA.MUX_BUF mux.otaB.mode = mux.otaB.MUX_BUF mux.write() - nos = brentq(lambda x: chain_a_offset(x, n, muxA_offset), + nos = fopt(lambda x: chain_a_offset(x, n, muxA_offset), -128, 127, xtol=0.01, disp=True) -- 2.25.1