''' Author: Federica Lionetto Date: January 5th, 2015 Description: Automated measurement for focusing. After the measurement, the position of the laser along x and z is reset. Parameters: - <firstx>, the first x position; - <lastx>, the last x position; - <stepx>, the step size along x; - <firstz>, the first z position; - <lastz>, the last z position; - <stepz>, the step size along z. How to run it: python Focusing.py --fx <firstx> --lx <lastx> --sx <stepx> --fz <firstz> --lz <lastz> --sz <stepz> --date <yyyymmdd> For example: python Focusing.py --fx 0 --lx 50 --sx 2 --fz -400 --lz -380 --sz 20 --date 20150105 Arduino device ID: DEVICE ID 2341:0042 on Bus 001 Address 045, Communications Device (in hexadecimal) ''' import argparse import subprocess import os import usb.core import usb.util parser = argparse.ArgumentParser(description='Define the parameters of the automated measurement for focusing.') parser.add_argument('--fx',type=int,help='first x position') parser.add_argument('--lx',type=int,help='last x position') parser.add_argument('--sx',type=int,help='step size along x') parser.add_argument('--fz',type=int,help='first z position') parser.add_argument('--lz',type=int,help='last z position') parser.add_argument('--sz',type=int,help='step size along z') parser.add_argument('--date',type=int,help='date according to the yyyymmdd format') args = parser.parse_args() # Parameters and configuration. firstx = args.fx lastx = args.lx stepx = args.sx firstz = args.fz lastz = args.lz stepz = args.sz yyyymmdd = args.date nevents = 10000 folder = '/home/hep/flionett/TestStand/Data' filename = '' config = '/home/hep/flionett/TestStand/Repository/TestStandRepository/Software/AutomatedMeasurements/FocusingConfig' print 'First x position: %i steps' % firstx print 'Last x position: %i steps' % lastx print 'Step size along x: %i steps' % stepx print 'First z position: %i steps' % firstz print 'Last z position: %i steps' % lastz print 'Step size along z: %i steps' % stepz print 'Number of events per DAQ: %i' % nevents # Number of scanned x positions. stepsx = (lastx-firstx)/stepx+1 print 'Number of scanned x positions: %i' % stepsx # Number of scanned z positions. stepsz = (lastz-firstz)/stepz+1 print 'Number of scanned z positions: %i' % stepsz # Find Arduino. dev = usb.core.find(idVendor=0x2341) if dev is None : raise ValueError("Device not found.") # Perform the measurement. for posz in range(firstz,lastz+stepz,stepz) : for posx in range(firstx,lastx+stepx,stepx) : print 'Position along x: %i steps' % posx print 'Position along z: %i steps' % posz filename = folder+"/Hans410/Test/"+str(yyyymmdd)+"-216-"+str(posx)+"x-"+str(posz)+"z-las.ali" printcommand = "echo alibava-gui --no-gui --nevts="+str(nevents)+" --out="+filename+" --laser "+config command = "alibava-gui --no-gui --nevts="+str(nevents)+" --out="+filename+" --laser "+config print '***' subprocess.call(printcommand,shell=True) subprocess.call(command,shell=True) # Move the stepper motor along x. # Send +10 (forward step of 5 microns) stepx times. # Reset the position of the stepper motor along x, to make it ready for the DAQs at the following z position. # Send +20 (backward step of 5 microns) stepx*len(range(firstx,lastx+stepx,stepx)) times. # Move the stepper motor along z. # Send +01 (backward step of 5 microns) stepz times. # Reset the position of the stepper motor along z, to make it ready for the following measurement. # Send +02 (forward step of 5 microns) stepz*len(range(firstz,lastz+stepz,stepz)) times. print '***' print 'End of the measurement!'