def main3(hal, dmm): # 10x reduced SPOT = 0.005 hal.mv_abs({'x': -SPOT, 'y': -SPOT}) if not args.dry: cwf = open(args.fout, 'wb') # full chip #cols = int(2.3 / SPOT) #rows = int(2.1 / SPOT) cols = int(1.0 / SPOT) rows = int(1.0 / SPOT) dwellt = 0.5 tpic = dwellt + 0.1 npic = cols * rows print 'Taking %dc x %dr => %d pics => ETA %s' % (cols, rows, npic, time_str(tpic * npic)) tstart = time.time() for row in xrange(rows): hal.mv_abs({'x': -SPOT, 'y': row * SPOT}) for col in xrange(cols): hal.mv_abs({'x': col * SPOT}) if args.dry: continue print '%s %dc, %dr: ' % (datetime.datetime.utcnow(), col, row) mas = [] ts = time.time() while time.time() - ts < dwellt: t = time.time() curr = dmm.curr_dc() mas.append((t, 1000 * curr)) ma_avg = [ma for t, ma in mas] ma_avg = sum(ma_avg) / len(ma_avg) print ' %0.5f mA, Samples: %d' % (ma_avg, len(mas)) cwf.write(repr({'col': col, 'row': row, 'mA': mas}) + '\n') cwf.flush() print 'Ret home' hal.mv_abs({'x': 0, 'y': 0}) print 'Movement done' # Convenient to be open at end to retarget tend = time.time() print 'Took %s' % time_str(tend - tstart)
def do_run(hal, bp, width, height, dry, fout, xstep, ystep, samples=1, cont=True): # Use focus to adjust verbose = False x0 = 0.0 y0 = 0.0 if 0: x0 = 2.0 y0 = 2.0 backlash = 0.1 hal.mv_abs({'x': x0 - backlash, 'y': y0 - backlash}) jf = fout cols = int(width / xstep) rows = int(height / ystep) tstart = time.time() device = devices.get(bp, args.device, verbose=verbose) def my_md5(devcfg): data_md5 = None if 'data' in devcfg: data_md5 = binascii.hexlify(md5.new(devcfg['data']).digest()) code_md5 = binascii.hexlify(md5.new(devcfg['code']).digest()) config_md5 = binascii.hexlify(md5.new(str(devcfg['config'])).digest()) return data_md5, code_md5, config_md5 print 'Dummy firmware read' trstart = time.time() devcfg, e = read_fw(device, cont) if not devcfg: #raise Exception("Failed to get baseline!") print 'WARNING: failed to get baseline!' base_data_md5, base_code_md5, base_config_md5 = None, None, None else: base_data_md5, base_code_md5, base_config_md5 = my_md5(devcfg) print 'Baseline: %s %s %s' % (md5str(base_data_md5), md5str(base_code_md5), md5str(base_config_md5)) trend = time.time() tread = trend - trstart print 'Read time: %0.1f' % tread # FIXME: estimate tmove = 0.1 tsample = tread + tmove print 'Sample time: %0.1f' % tsample nsamples = cols * rows print 'Taking %dc x %dr x %ds => %d net samples => ETA %s' % ( cols, rows, samples, nsamples, time_str(tsample * nsamples)) if jf: j = { 'type': 'params', 'x0': x0, 'y0': y0, 'ystep': ystep, 'ystep': ystep, 'cols': cols, 'rows': rows, 'samples': samples, 'nsamples': nsamples, } jf.write(json.dumps(j) + '\n') jf.flush() posi = 0 for row in xrange(rows): y = y0 + row * ystep hal.mv_abs({'x': x0 - backlash, 'y': y}) for col in xrange(cols): posi += 1 x = x0 + col * xstep hal.mv_abs({'x': x}) print '%s taking %d / %d @ %dc, %dr (G0 X%0.1f Y%0.1f)' % ( datetime.datetime.utcnow(), posi, nsamples, col, row, x, y) # Hit it a bunch of times in case we got unlucky for dumpi in xrange(samples): # Some evidence suggests overcurrent isn't getting cleared, causing failed captured # Try re-initializing # TODO: figure out the proper check # this slows things down, although its not too bad # maybe 4.5 => 7 seconds per position #if not dry: # startup.replay(bp.dev) j = { 'type': 'sample', 'row': row, 'col': col, 'x': x, 'y': y, 'dumpi': dumpi, } if dry: devcfg, e = None, None else: devcfg, e = read_fw(device, cont) if devcfg: # Some crude monitoring # Top histogram counts would be better though data_md5, code_md5, config_md5 = my_md5(devcfg) print ' %d %s %s %s' % (dumpi, md5str(data_md5), md5str(code_md5), md5str(config_md5)) if code_md5 != base_code_md5: print ' code...: %s' % binascii.hexlify( devcfg['code'][0:16]) if data_md5 and data_md5 != base_data_md5: print ' data...: %s' % binascii.hexlify( devcfg['data'][0:16]) if config_md5 != base_config_md5: print ' config: %s' % str(devcfg['config'], ) j['devcfg'] = { 'code': base64.b64encode(devcfg['code']), 'config': devcfg['config'], } if 'data' in devcfg: j['data'] = base64.b64encode(devcfg['data']) if e: j['e'] = (str(type(e).__name__), str(e)), if jf: jf.write(json.dumps(j) + '\n') jf.flush() print 'Ret home' hal.mv_abs({'x': x0, 'y': y0}) print 'Movement done' tend = time.time() print 'Took %s' % time_str(tend - tstart)
def main2(hal, dmm, el): # 50x max ap size # Very approx #SPOT = 0.06 shut_open = el.shut_open if 0: # 10x SPOT = 0.3 el.shut_square(args.square) if 1: # 10x reduced SPOT = 0.05 # From trial and error def shut_open(): el.shut_square(30) hal.mv_abs({'x': -SPOT, 'y': -SPOT}) if not args.dry: cwf = open(args.fout, 'wb') cols = int(4.6 / SPOT) rows = int(3.8 / SPOT) tpic = 2.3 npic = cols * rows print 'Taking %dc x %dr => %d pics => ETA %s' % (cols, rows, npic, time_str(tpic * npic)) tstart = time.time() # Takes some time to settle # Close early el.shut_close() for row in xrange(rows): hal.mv_abs({'x': -SPOT, 'y': row * SPOT}) for col in xrange(cols): hal.mv_abs({'x': col * SPOT}) if args.dry: continue print '%s %dc, %dr: ' % (datetime.datetime.utcnow(), col, row), closed = [] for i in xrange(1): t = time.time() closed.append((t, dmm.curr_dc())) shut_open() opened = [] for i in xrange(4): time.sleep(0.5) t = time.time() curr = dmm.curr_dc() opened.append((t, curr)) delta = curr - closed[0][1] print ' %0.9f A' % delta, cwf.write(repr({'col': col, 'row': row, 'open': opened, 'close': closed}) + '\n') print el.shut_close() cwf.flush() print 'Ret home' hal.mv_abs({'x': 0, 'y': 0}) print 'Movement done' # Convenient to be open at end to retarget shut_open() tend = time.time() print 'Took %s' % time_str(tend - tstart)
def run(hal, prog, el, elt, fout, dry=False, square=False): # 50x max ap size # Very approx #SPOT = 0.06 if 0: # 10x SPOT = 0.3 el.shut_square(square) if 1: # 10x reduced SPOT = 0.05 # From trial and error el.shut_square(30) hal.mv_abs({'x': -SPOT, 'y': -SPOT}) if not dry: jf = open(fout, 'wb') cols = int(4.6 / SPOT) rows = int(3.8 / SPOT) SAMPLES = 4 tpic = SAMPLES npic = cols * rows print 'Taking %dc x %dr => %d pics => ETA %s' % (cols, rows, npic, time_str(tpic * npic)) tstart = time.time() posi = 0 for row in xrange(rows): y = row * SPOT hal.mv_abs({'x': -SPOT, 'y': y}) for col in xrange(cols): posi += 1 x = col * SPOT hal.mv_abs({'x': x}) if dry: continue print '%s taking %d / %d @ %dc, %dr' % (datetime.datetime.utcnow(), posi, npic, col, row) # Hit it a bunch of times in case we got unlucky for dumpi in xrange(SAMPLES): elt.fire() step_ms = 0.2 / SAMPLES * 1000 sleep_sec = (dumpi * step_ms + random.randint(0, step_ms)) / 1000. time.sleep(sleep_sec) fw = prog.read() # Some crude monitoring # Top histogram counts would be better though print ' %d: %s' % (dumpi, binascii.hexlify(md5.new(fw).digest())) j = { 'row': row, 'col': col, 'x': x, 'y': y, 'dumpi': dumpi, 'sleep': sleep_sec, 'bin': base64.b64encode(fw) } jf.write(json.dump(j)) jf.flush() # Make sure fires start cleanly elt.idle.wait(1) print 'Ret home' hal.mv_abs({'x': 0, 'y': 0}) print 'Movement done' tend = time.time() print 'Took %s' % time_str(tend - tstart)
def main1(hal, dmm, el): # 50x max ap size # Very approx #SPOT = 0.06 shut_open = el.shut_open if 0: # 10x SPOT = 0.3 el.shut_square(args.square) if 1: # 10x reduced SPOT = 0.05 # From trial and error def shut_open(): el.shut_square(30) hal.mv_abs({'x': -SPOT, 'y': -SPOT}) if not args.dry: cwf = open(args.fout, 'wb') cw = csv.writer(cwf) cw.writerow(["t", "col", "row", "close", "open", "delta"]) cols = int(4.6 / SPOT) rows = int(3.8 / SPOT) tpic = 2.3 npic = cols * rows print 'Taking %dc x %dr => %d pics => ETA %s' % (cols, rows, npic, time_str(tpic * npic)) tstart = time.time() # Takes some time to settle # Close early el.shut_close() posi = 0 for row in xrange(rows): hal.mv_abs({'x': -SPOT, 'y': row * SPOT}) for col in xrange(cols): posi += 1 hal.mv_abs({'x': col * SPOT}) if args.dry: continue print 'Taking %d / %d' % (posi, npic) for i in xrange(8): curr_close = dmm.curr_dc() # Time to open shutter? Time to have effect? # Seems to power drift quick so think quicker => generally better shut_open() time.sleep(0.2) curr_open = dmm.curr_dc() el.shut_close() curr_delta = curr_open - curr_close cw.writerow([time.time(), col, row, curr_close, curr_open, curr_delta]) cwf.flush() print '%s %dc, %dr: %0.9f A' % (datetime.datetime.utcnow(), col, row, curr_delta) print 'Ret home' hal.mv_abs({'x': 0, 'y': 0}) print 'Movement done' # Convenient to be open at end to retarget shut_open() tend = time.time() print 'Took %s' % time_str(tend - tstart)