示例#1
0
def test_opt():
    from scipy.optimize import fmin_tnc
    x, y = a3200.xyposition()
    fmin_tnc(value_and_gradient, (x,y), None,
             [(lambda: abs(keyence.measure(1, blocking=True) -
                           keyence.measure(2, blocking=False))), 0.001],
             False, [(x-.008,x+.008), (y-.008,y+.008)],)
示例#2
0
def find_center(radius=4000):
    keyence.set_samples(4, 1)
    path = follow_edge(.04)
    a3200.xymove(numpy.average(path, 0))
    a3200.z.enable()
    a3200.z.relmove(-radius)
    a3200.z.disable()
    spiral_search((lambda: keyence.measure() is None), 0.005)
    spiral_search((lambda: abs(keyence.measure(1) - keyence.measure(2) < 10)), 0.001)
示例#3
0
 def step(self, pt):
     """Measure one point and return (time, z-value)."""
     a3200.xymove(pt, velocity=600, blocking=True)
     z = keyence.measure(blocking=True)
     if self.gantry and z:
         z -= self.gantry.error(pt)
     return (time.time(), z if z else numpy.nan)
示例#4
0
def follow_edge(step=1):
    a3200.x.freerun(1)
    while keyence.measure() is not None: time.sleep(.01)
    a3200.x.halt()
    a3200.x.relmove(-step/2)
    origin, xy = a3200.xyposition(), numpy.array([0, 0])
    heading, path, i, dark = 0, [], 0, False
    while tuple(xy) not in path[:-10]:
        ldark, dark = dark, (keyence.measure(blocking=True) is None)
        if dark != ldark: i = 0
        if i%2 or not i: heading = (heading + (-1 if dark else 1)) % 4
        xy += [(1,0),(0,1),(-1,0),(0,-1)][heading]
        a3200.xymove(origin + xy*step)
        path.append(tuple(xy))
        i += 1
    return origin + numpy.array(path, dtype='float')*step
示例#5
0
def script():
    print('\nWelcome to interactive object scanner')
    print('Direct questions to [email protected]\n')
    print('Please power on XYZ stage and Keyence sensor')
    raw_input('Press enter when finished\n')
    print('Initializing system...')
    initialize()
    print('Initialization finished.\n')
    if raw_input('Would you like to home the X & Y axes? (Y/n) ') in ['N','n']:
        print('XY coordinates may not be consistent.\n')
    else:
        print('Homing axes...')
        home()
        print('Axes homed.\n')
    print('Opening NView for you to set up the stage:')
    print('- determine XY location of object to be scanned')
    print('- move Z-axis in range')
    print('Press F3 for controls; exit when finished.')
    a3200.z.enable()
    os.system('NViewMMI')
    a3200.z.relmove(keyence.measure() or 0)
    a3200.z.disable()
    print('NView finished executing.\n')
    params = ['minimum x', 'maximum x', 'x increment',
              'minimum y', 'maximum y', 'y increment']
    read = lambda: [float(raw_input('{0: >12}: '.format(p))) for p in params]
    def to_points(raster):
        return dstack(meshgrid(arange(*raster[:3]),
                               arange(*raster[3:]))).reshape((-1,2))
    if raw_input('Is this to be a tiled scan? (y/N) ').lower() == 'y':
        print('Please enter these parameters to describe the tile origins:')
        tiles = to_points(read())
        print('Please enter these parameters for points relative to tiles:')
        points = to_points(read())
        setup_tiled(tiles, points)
    else:
        print('Please enter these parameters to describe point locations:')
        values = read()
        print('\nSetting up scan...')
        setup_raster(*values)
        print('Ready to scan.\n')
    raw_input('Press enter to scan.')
    print('Scanning... ')
    run_scan()
    print('Scan finished.\n')
    print('Closing hardware...')
    close()
    print('Hardware closed.\n')
    a = raw_input('Would you like to analyze the data now? (Y/n) ')
    if a.lower() != 'n':
        process_data()
        print('Plot is in background window.\n')
    path = raw_input('Path to save data: {0}\\'.format(os.getcwd()))
    print('Saving data...')
    save_results(path)
    print('Data saved.\n')