def case_4_experiment(pidevice, app, info, rangemin, rangemax, curpos): # Shutter not connected and not continuous print("The experiment is running4") if (info.total_distance > rangemax["1"] - curpos["1"]): info.total_distance = rangemax["1"] if (info.step_size < 0.00001): info.step_size = 0.00001 # move to the minimum of the stage (-13) pidevice.MOV("1", rangemin["1"]) pitools.waitontarget(pidevice, axes="1") print('current position of axis {} is {:.4f}'.format( "1", pidevice.qPOS("1")["1"])) for axis in pidevice.axes: for target in numpy.arange( rangemin[axis] + info.step_size, rangemin[axis] + info.total_distance + info.step_size, info.step_size): if (app.begin_experiment): time.sleep(info.exposure_time) pidevice.MOV(axis, target) pitools.waitontarget(pidevice, axes=axis) position = pidevice.qPOS(axis)[axis] print('current position of axis {} is {:.4f}'.format( axis, position)) else: break print('done')
def case_1_experiment(pidevice, app, info, rangemin, rangemax, curpos): # Shutter and continuous info.port_shut = "COM%s" % info.port_shut shutter = ShutterControl.Shutter(info.port_shut) shutter.startup() print("The experiment is running1") if (info.total_distance > rangemax["1"] - curpos["1"]): info.total_distance = rangemax["1"] # move to the minimum of the stage (-13) pidevice.MOV("1", rangemin["1"]) pitools.waitontarget(pidevice, axes="1") print('current position of axis {} is {:.4f}'.format( "1", pidevice.qPOS("1")["1"])) pidevice.VEL("1", info.velocity) for axis in pidevice.axes: target = rangemin[axis] + info.total_distance shutter.toggle_pause(info.exposure_time) time.sleep(info.motor_delay) pidevice.MOV(axis, target) pitools.waitontarget(pidevice, axes=axis) position = pidevice.qPOS(axis)[axis] print('current position of axis {} is {:.4f}'.format( "1", pidevice.qPOS("1")["1"])) shutter.ser.close() print('done')
def case_5_experiment(pidevice, app, info, rangemin, rangemax, curpos): # Shutter not connected and continuous print("The experiment is running5") if (info.total_distance > rangemax["1"] - curpos["1"]): info.total_distance = rangemax["1"] # move to the minimum of the stage (-13) pidevice.MOV("1", rangemin["1"]) pitools.waitontarget(pidevice, axes="1") print('current position of axis {} is {:.4f}'.format( "1", pidevice.qPOS("1")["1"])) pidevice.VEL("1", info.velocity) for axis in pidevice.axes: target = rangemin[axis] + info.total_distance pidevice.MOV(axis, target) pitools.waitontarget(pidevice, axes=axis) position = pidevice.qPOS(axis)[axis] print('current position of axis {} is {:.4f}'.format( "1", pidevice.qPOS("1")["1"])) print('done')
def increment_move(self, position=None, increment=None, direction=None): """ This is a function to move by incrementation from the GUI it is based on the actual position and the increment given by the GUI. Parameters: position: This is the current position of the device. increment: This is the increment that is sent everytime you click on one of the arrow. direction: This is either positive or negative depending on the side of the arrow you are clicking. """ if self.dev_name == 'SMC100': if not self.device or not position: return if direction == 'left': increment = -increment self.device.move_relative_mm(increment) else: if not self.device or not position: return # The orientation of the device is based on positive and negative of # the 891 stage. Maybe definition is different for other stage. import pipython.pitools as pitools position2 = position.get() increment = increment.get() if direction == 'left': increment = -increment else: pass position2 += increment position.set(position2) self.device.MOV(self.axes, position2) pitools.waitontarget(self.device)
def start_stages(targetZ=10, targetX=26, vel_Z=15, vel_X=15, wait=5): motorZ.OpenUSBDaisyChain(description='019550102') daisychainid = motorZ.dcid motorZ.ConnectDaisyChainDevice(1, daisychainid) motorX.ConnectDaisyChainDevice(2, daisychainid) pitools.startup(motorZ, stages=STAGES, refmode=REFMODE) print('Z-axis current position: ', float(str(motorZ.qPOS(motorZ.axes))[18:-3])) pitools.startup(motorX, stages=STAGES, refmode=REFMODE) print('X-axis current position: ', float(str(motorX.qPOS(motorX.axes))[18:-3])) time.sleep(wait) motorX.VEL(motorX.axes, vel_X) motorX.MOV(motorX.axes, targetX) pitools.waitontarget(motorX) print('Position X: ', float(str(motorX.qPOS(motorX.axes))[18:-3])) motorZ.VEL(motorZ.axes, vel_Z) motorZ.MOV(motorZ.axes, targetZ) pitools.waitontarget(motorZ) print('Position Z: ', float(str(motorZ.qPOS(motorZ.axes))[18:-3])) time.sleep(wait)
def move(self, targets, timeout=60): with self._lock: if len(targets) != self._info['numaxes']: raise TypeError( 'The number of axes set is not equal to the' 'number of axes of the device.') try: self._moveState = True if not self.device: raise SystemError('No available device.') for i in self.device.axes: i = int(i) - 1 _range = self._info['range'][i] if (targets[i] > _range[1]) or (targets[i] < _range[0]): raise OutOfRange( 'Sorry, out of range in axis {}'.format( str(i))) print('{} targets: {}'.format(str(self.name), str(targets))) self.device.MOV(self.device.axes, targets) pitools.waitontarget(self.device, timeout=timeout) self._moveState = False except SystemError: self._moveState = None self.close() raise except: self._moveState = False raise
def runwavegen(pidevice): """Configure two wave forms, move to start position and start the wave generators. @type pidevice : pipython.gcscommands.GCSCommands """ assert 2 == len(pidevice.axes[:2]), 'this sample requires two connected axes' wavegens = (1, 2) wavetables = (1, 2) print('define sine and cosine waveforms for wave tables {}'.format(wavetables)) pidevice.WAV_SIN_P(table=wavetables[0], firstpoint=0, numpoints=NUMPOINTS, append='X', center=NUMPOINTS / 2, amplitude=AMPLITUDE[0], offset=STARTPOS[0], seglength=NUMPOINTS) pidevice.WAV_SIN_P(table=wavetables[1], firstpoint=NUMPOINTS / 4, numpoints=NUMPOINTS, append='X', center=NUMPOINTS / 2, amplitude=AMPLITUDE[1], offset=STARTPOS[1], seglength=NUMPOINTS) pitools.waitonready(pidevice) if pidevice.HasWSL(): # you can remove this code block if your controller does not support WSL() print('connect wave generators {} to wave tables {}'.format(wavegens, wavetables)) pidevice.WSL(wavegens, wavetables) if pidevice.HasWGC(): # you can remove this code block if your controller does not support WGC() print('set wave generators {} to run for {} cycles'.format(wavegens, NUMCYLES)) pidevice.WGC(wavegens, [NUMCYLES] * len(wavegens)) if pidevice.HasWTR(): # you can remove this code block if your controller does not support WTR() print('set wave table rate to {} for wave generators {}'.format(TABLERATE, wavegens)) pidevice.WTR(wavegens, [TABLERATE] * len(wavegens), interpol=[0] * len(wavegens)) startpos = (STARTPOS[0], STARTPOS[1] + AMPLITUDE[1] / 2.0) print('move axes {} to their start positions {}'.format(pidevice.axes[:2], startpos)) pidevice.MOV(pidevice.axes[:2], startpos) pitools.waitontarget(pidevice, pidevice.axes[:2]) print('start wave generators {}'.format(wavegens)) pidevice.WGO(wavegens, mode=[1] * len(wavegens)) while any(list(pidevice.IsGeneratorRunning(wavegens).values())): print('.', end='') sleep(1.0) print('\nreset wave generators {}'.format(wavegens)) pidevice.WGO(wavegens, mode=[0] * len(wavegens)) print('done')
def config_pi(self): CONTROLLERNAME = 'C-863.11' # 'C-863' will also work STAGES = ['M-111.1VG'] REFMODES = ['FNL', 'FRF'] self.pi = GCSDevice(CONTROLLERNAME) self.pi.ConnectUSB(serialnum='0165500259') pitools.startup(self.pi, stages=STAGES, refmodes=REFMODES) self.pi.VEL(1, self.velocity) self.pi.MOV(1, self.pos_max) pitools.waitontarget(self.pi, axes=1)
def next_load(next_l=forces_list[j]): #j+1 z_load_i = take_force_normal() print('Current load is: {} N'.format(z_load_i)) print('Moving to next load {} N'.format(forces_list[j])) #j+1 current_z_load = float(take_force_normal()) while (float(current_z_load)) < float(next_l): position = float(str(motorZ.qPOS(motorZ.axes))[18:-3]) # get position print('Current motor position: ', position) if float(current_z_load) < (next_l * 0.40): ztarget = position + 0.01 elif float(current_z_load) >= ( next_l * 0.40) and float(current_z_load) <= (next_l * 0.90): ztarget = position + 0.001 else: ztarget = position + 0.0001 print('Target: ', ztarget) motorZ.MOV(motorZ.axes, ztarget) pitools.waitontarget(motorZ) position = float(str(motorZ.qPOS(motorZ.axes))[18:-3]) print('New motor position: ', position) time.sleep(0.5) # wait for 0.2 s before taking new force measurement current_z_load = float(take_force_normal()) print('current load: ', current_z_load, ' N') while (float(current_z_load)) > float(next_l): position = float(str(motorZ.qPOS(motorZ.axes))[18:-3]) # get position print('Current motor position: ', position) if float(current_z_load) > float((next_l * 0.90) + next_l): ztarget = position - 0.01 elif float(current_z_load) <= float( (next_l * 0.90) + next_l) and float(current_z_load) >= float( (next_l * 0.4) + next_l): ztarget = position - 0.001 else: ztarget = position - 0.0001 print('Target: ', ztarget) motorZ.MOV(motorZ.axes, ztarget) pitools.waitontarget(motorZ) position = float(str(motorZ.qPOS(motorZ.axes))[18:-3]) print('New motor position: ', position) time.sleep(0.5) # wait for 0.2 s before taking new force measurement current_z_load = float(take_force_normal()) print('current load: ', current_z_load, ' N') print('\n Target force reached: {}'.format(current_z_load))
def home_motor(self): if self.is_connected: try: self.print_text_signal.emit("...homing building plate...") self.gcs.GOH() pitools.waitontarget(self.gcs) self.print_text_signal.emit("building plate homed!") self.homed_signal.emit(True) return True except Exception as e: self.print_text_signal.emit("Problems homing building plate!") self.homed_signal.emit(False) raise e
def moveAbs(self, z): """ Moves the objective motor to a target position, 'z' is the position on the z-axis in millimeters. Example: z = 3.45 moves the objective 3.45 millimeters above zero. """ self.objective.MOV(self.objective.axes, z) pitools.waitontarget(self.objective) # below this line is not really necessary positions = self.objective.qPOS(self.objective.axes) for axis in self.objective.axes: print('position of axis {} = {:.5f}'.format(axis, positions[axis]))
def wait_for_idle(self): """ first draft for a wait for idle function checks if on target problem: seems to return too fast, so that the position is not yet the right one.. although this function is actually meant to not wait until the target position is reached.. it works when the two log entries are activated. this seems to take some additional time, allowing the stage to reach the target """ # self.log.info('old position: {}'.format(self.get_pos())) pitools.waitontarget(self.pidevice) # self.log.info('new position: {}'.format(self.get_pos())) return
def movetotargets(pidevice): """Move all axes to targets read from CSV file 'DATAFILE'. Add further columns if there are more than 6 axes connected. @type pidevice : pipython.gcscommands.GCSCommands """ with open(DATAFILE, 'rb') as fobj: for line in fobj: targets = line.split(SEPARATOR)[:pidevice.numaxes] print 'targets: {}'.format(', '.join(targets)) targets = [float(x) for x in targets] pidevice.MOV(pidevice.axes, targets) sleep(RELAXTIME / 1000.) if not RELAXTIME: pitools.waitontarget(pidevice) print('done')
def approach_X_stage(approach_X=1): print('Position X: ',float(str(motorX.qPOS(motorX.axes))[18:-3])) while approach_X == 1: print('\n##############################################################') moveX = float(input('Enter how many mm the X-axis should move: ')) print('You chose to move: ', moveX, ' mm\n') motorX.MVR(motorX.axes, moveX) # MVR moves relative, MOV moves absolute pitools.waitontarget(motorX) print('Position X: ',float(str(motorX.qPOS(motorX.axes))[18:-3])) approach_X = int(input('Do you want to keep moving the X stage? (enter 1 to continue approaching, enter 0 if you DO NOT want to continue approaching: ')) if approach_X == 1: print('You chose to continue approaching the X stage.\n') # MAKE SURE YOU INPUT CORRECTLY else: print('You are done approaching the X stage.\n')
def approach_Z_stage(approach_Z=1): print('Position Z: ',float(str(motorZ.qPOS(motorZ.axes))[18:-3])) while approach_Z == 1: print('\n##############################################################') moveZ = float(input('Enter how many mm the Z-axis should move: ')) print('You chose to move: ', moveZ, ' mm\n') motorZ.MVR(motorZ.axes, moveZ) pitools.waitontarget(motorZ) print('Position Z: ',float(str(motorZ.qPOS(motorZ.axes))[18:-3])) approach_Z = int(input('Do you want to keep moving the Z stage? (enter 1 to continue approaching, enter 0 if you DO NOT want to continue approaching: ')) if approach_Z == 1 : print('You chose to continue approaching the Z stage.\n') # MAKE SURE YOU INPUT CORRECTLY else: print('You are done approaching the Z stage.\n')
def move_and_wait(self,position, tol=0.001): # move the stage if not self.move(position): return False # wait for it to stop if not self.simulate: pitools.waitontarget(self.calstage, axes=['1']) # make sure it moved where we wanted (within tolerance) if abs(position - self.get_position()) > tol: self.logger.error("Error moving to requested position") return False # success! return True
def take_point(self): if self.repeat >= self.n_iter: if self.index_pos == self.n_scan - 1: self.stop_measure() self.pi.close() return 0 else: with open(self.fname, 'a') as f: for val in self.y: f.write('%f \t' % val) f.write('\n') self.index_pos += 1 self.labelscan.setText("scan # %i" % self.index_pos) newpos = self.list_pos[self.index_pos] self.pi.MOV(1, newpos) pitools.waitontarget(self.pi, axes=1) self.stop_measure() self.start_ESR() lecture = self.apd.read(self.n_points) # PL=np.array([(lecture[i+1]-lecture[i])*self.sampling_rate for i in range(len(lecture)-1)]) lecture = np.array(lecture) PL = lecture[1:] - lecture[:-1] if self.normalize_cb.isChecked(): PL = PL / max(PL) else: PL = PL * self.sampling_rate if min(PL) >= 0: #Pour éviter les reset de compteur self.y = self.y * (1 - 1 / self.repeat) + PL * (1 / self.repeat) self.repeat += 1 self.dynamic_line.set_ydata(self.y) ymin = min(self.y) ymax = max(self.y) self.dynamic_ax.set_ylim([ymin, ymax]) # print(len(self.dynamic_line.get_xdata())) # print(len(self.dynamic_line.get_ydata())) self.dynamic_ax.figure.canvas.draw() self.labelIter.setText("iter # %i" % self.repeat)
def runprofile(pidevice): """Configure two trajectories, move to start position and start and feed the profile generators. @type pidevice : pipython.gcscommands.GCSCommands """ assert 2 == len( pidevice.axes[:2]), 'this sample requires two connected axes' trajectories = (1, 2) xvals = [2 * pi * float(i) / float(NUMPOINTS) for i in range(NUMPOINTS)] xtrajectory = [ STARTPOS[0] + AMPLITUDE[0] / 2.0 * sin(xval) for xval in xvals ] ytrajectory = [ STARTPOS[0] + AMPLITUDE[0] / 2.0 * cos(xval) for xval in xvals ] print('move axes {} to their start positions {}'.format( pidevice.axes[:2], (xtrajectory[0], ytrajectory[0]))) pidevice.MOV(pidevice.axes[:2], (xtrajectory[0], ytrajectory[0])) pitools.waitontarget(pidevice, pidevice.axes[:2]) servotime = getservotime(pidevice) tgtvalue = int(float(PERIOD) / float(NUMPOINTS) / servotime) print('set %d servo cycles per point -> period of %.2f seconds' % (tgtvalue, tgtvalue * servotime * NUMPOINTS)) pidevice.TGT(tgtvalue) print('clear existing trajectories') pidevice.TGC(trajectories) for cyclenum in range(1, NUMCYLES + 1): pointnum = 0 print('\r%s' % (' ' * 40)), while pointnum < NUMPOINTS: if pidevice.qTGL(1)[1] < BUFFERSIZE: pidevice.TGA(trajectories, (xtrajectory[pointnum], ytrajectory[pointnum])) pointnum += 1 print('\rappend cycle {}/{}, point {}/{}'.format( cyclenum, NUMCYLES, pointnum, NUMPOINTS)), if BUFFERSIZE == NUMPOINTS * (cyclenum - 1) + pointnum: print('\nstarting trajectories') pidevice.TGS(trajectories) if NUMCYLES == cyclenum and NUMPOINTS == pointnum: print('\nfinishing trajectories') pidevice.TGF(trajectories) pitools.waitontrajectory(pidevice, trajectories) print('done')
def go_home(app, info): CONTROLLERNAME = 'E-873' STAGES = ['Q-545.240'] REFMODES = ['FNL', 'FRF'] comport = str(app.gui.entry_port_mot.get()) with GCSDevice(CONTROLLERNAME) as pidevice: pidevice.ConnectRS232(comport=1, baudrate=115200) pitools.startup(pidevice, stages=STAGES, refmodes=REFMODES) rangemin = pidevice.qTMN() rangemax = pidevice.qTMX() curpos = pidevice.qPOS() pidevice.VEL("1", info.max_velocity) pidevice.MOV("1", rangemin["1"]) pitools.waitontarget(pidevice, axes="1") print('current position of axis {} is {:.4f}'.format( "1", pidevice.qPOS("1")["1"]))
def fine_approach(target_load=1): z_load_i = take_force_normal() print('Initial normal load measurement: ', z_load_i, ' N') if start == 1: print('\nStarting fine approach') print('Current force: ', float(z_load_i), ' N') # first measurement from force sensor current_z_load = take_force_normal() # current sensor value print('Current load: ', current_z_load, ' N') while (float(current_z_load) < float(target_load)): position = float(str(motorZ.qPOS( motorZ.axes))[18:-3]) # get position print('Current motor position: ', position) print('\nApproaching...') # starts moving if float(current_z_load) < (target_load * 0.40): ztarget = position + 0.01 elif float(current_z_load) >= (target_load * 0.40) and float( current_z_load) <= (target_load * 0.90): ztarget = position + 0.001 else: ztarget = position + 0.0001 print('Target: ', ztarget) motorZ.MOV(motorZ.axes, ztarget) pitools.waitontarget(motorZ) position = float(str(motorZ.qPOS(motorZ.axes))[18:-3]) print('New motor position: ', position) time.sleep( 0.5) # wait for 0.2 s before taking new force measurement current_z_load = take_force_normal( ) # take force sensor measurement print('current load: ', current_z_load, ' N') print('Target force reached: {}'.format(current_z_load)) time.sleep(1)
def move(self, target_pos): #pidevice.StopAll() #pidevice.SVO(pidevice.axes, [True] * len(pidevice.axes)) #pitools.waitontarget(pidevice, axes=pidevice.axes) # pitools.startup(pidevice, stages=STAGES, refmode=REFMODE) # Now we query the allowed motion range of all connected stages. # GCS commands often return an (ordered) dictionary with axes/channels # as "keys" and the according values as "values". # rangemin = list(pidevice.qTMN().values()) # rangemax = list(pidevice.qTMX().values()) # ranges = zip(rangemin, rangemax) targets = [target_pos] self.pidevice.MOV(self.pidevice.axes, targets) pitools.waitontarget(self.pidevice) time.sleep(0.3) positions = self.pidevice.qPOS(self.pidevice.axes) for axis in self.pidevice.axes: print('position of axis {} = {:.5f}'.format(axis, positions[axis]))
def runwavegen(pidevice): """Read wave data, set up wave generator and run them. @type pidevice : pipython.gcscommands.GCSCommands """ wavedata = readwavedata() axes = pidevice.axes[:len(wavedata)] assert len(wavedata) == len(axes), 'this sample requires {} connected axes'.format(len(wavedata)) wavetables = range(1, len(wavedata) + 1) wavegens = range(1, len(wavedata) + 1) #pitools.writewavepoints(pidevice, 1, wavedata[0], bunchsize=1) for i in range(0, len(wavedata)): print(wavedata[0,i]) pidevice.WAV_PNT(table=1, firstpoint= 1, numpoints=1, append='&', wavepoint=wavedata[0,i]) # print('write wave points of wave table {} and axis {}'.format(wavetable, axes[i])) #pidevice.WAV() # if pidevice.HasWSL(): # you can remove this code block if your controller does not support WSL() print('connect wave tables {} to wave generators {}'.format(wavetables, wavegens)) pidevice.WSL(wavegens, wavetables) if pidevice.HasWGC(): # you can remove this code block if your controller does not support WGC() print('set wave generators {} to run for {} cycles'.format(wavegens, NUMCYLES)) pidevice.WGC(wavegens, [NUMCYLES] * len(wavegens)) if pidevice.HasWTR(): # you can remove this code block if your controller does not support WTR() print('set wave table rate to {} for wave generators {}'.format(TABLERATE, wavegens)) pidevice.WTR(wavegens, [TABLERATE] * len(wavegens), interpol=[0] * len(wavegens)) startpos = [wavedata[i][0] for i in range(len(wavedata))] print('move axes {} to start positions {}'.format(axes, startpos)) pidevice.MOV(axes, startpos) pitools.waitontarget(pidevice, axes) print('start wave generators {}'.format(wavegens)) pidevice.WGO(wavegens, mode=[1] * len(wavegens)) while any(list(pidevice.IsGeneratorRunning(wavegens).values())): print('.', end='') sleep(1.0) print('\nreset wave generators {}'.format(wavegens)) pidevice.WGO(wavegens, mode=[0] * len(wavegens)) print('done')
def case_0_experiment(pidevice, app, info, rangemin, rangemax, curpos): # Shutter and not continuous info.port_shut = "COM%s" % info.port_shut shutter = ShutterControl.Shutter(info.port_shut) shutter.startup() print("The experiment is running0") if (info.total_distance > rangemax["1"] - curpos["1"]): info.total_distance = rangemax["1"] if (info.step_size < 0.00001): info.step_size = 0.00001 # move to the minimum of the stage (-13) pidevice.MOV("1", rangemin["1"]) pitools.waitontarget(pidevice, axes="1") print('current position of axis {} is {:.4f}'.format( "1", pidevice.qPOS("1")["1"])) for axis in pidevice.axes: for target in numpy.arange( rangemin[axis] + info.step_size, rangemin[axis] + info.total_distance + info.step_size, info.step_size): if (app.begin_experiment): shutter.toggle_pause(info.exposure_time) time.sleep(info.motor_delay) pidevice.MOV(axis, target) pitools.waitontarget(pidevice, axes=axis) position = pidevice.qPOS(axis)[axis] print('current position of axis {} is {:.4f}'.format( axis, position)) else: break print('done') shutter.ser.close()
def go_2position(self, position=None): """ This function allows the user to move the stage that is connected to you computer on the axis taken of self.axis. Parameters: position: This is the position you want to order your stage to go to. """ if self.dev_name == 'SMC100': if (not self.device) or (position is None): return self.device.move_absolute_mm(position) else: import pipython.pitools as pitools if (not self.device) or (position is None): return import pipython.pitools as pitools try: position = position.get() except: pass if self.dev_name == 'E-816': # Convert [-250,250] um input position to MOV() units for piezo position = (position + 250) / 5 # -> Convert to [0,100] range correctedMax = 15.1608 position = position * correctedMax / 100 # -> Convert to effective values for damaged piezo self.device.MOV(self.axes, position) pitools.waitontarget(self.device)
def on_deactivate(self): """ Required deactivation steps """ # set position (0, 0, 0) # first move z to default position and wait until reached self.pidevice_3rd_axis.MOV(self.third_axis_ID, 0.0) pitools.waitontarget(self.pidevice_3rd_axis, axes=self.third_axis_ID) # when z is at safety position, xy move can be done self.pidevice_1st_axis.MOV(self.first_axis_ID, 0.0) self.pidevice_2nd_axis.MOV(self.second_axis_ID, 0.0) pitools.waitontarget(self.pidevice_1st_axis, axes=self.first_axis_ID) pitools.waitontarget(self.pidevice_2nd_axis, axes=self.second_axis_ID) self.pidevice_1st_axis.CloseDaisyChain( ) # check if connection always done with controller corresponing to 1st axis self.pidevice_1st_axis.CloseConnection()
def retreat_stages(targetZ=10,targetX=26,vel_Z=15,vel_X=15,wait=2): time.sleep(2) retreat = int(input('Return stages to starting position? Enter 1 for yes, enter 0 for no: ')) if retreat == 1: targetZ0 = -5 motorZ.MVR(motorZ.axes, targetZ0) pitools.waitontarget(motorZ) time.sleep(1) motorX.VEL(motorX.axes, vel_X) motorX.MOV(motorX.axes, targetX) pitools.waitontarget(motorX) print('Position X: ',float(str(motorX.qPOS(motorX.axes))[18:-3])) motorZ.VEL(motorZ.axes, vel_Z) motorZ.MOV(motorZ.axes, targetZ) pitools.waitontarget(motorZ) print('Position Z: ',float(str(motorZ.qPOS(motorZ.axes))[18:-3])) time.sleep(wait)
def compute(self): #Move the number of steps equal to the difference between the initial position #and the desired final position self.pidevice.MOV(self.pidevice.axes, int(self.input_angle)) print('stage moves to target position') pitools.waitontarget(self.pidevice)
# Trig_line = Trig_conf[2] # Trig_mode = Trig_conf[3] # # print(Trig_conf) # print('Trigger step = ', float(Trig_step)) # print('Trigger line = ', Trig_line) # print('Trigger mode = ', Trig_mode) # print('Data recorder options: ', pidevice.qHDR()) # pitools.waitonready(pidevice) # Table_rate = pidevice.qSPA(items=1, params=0x13000109)[1][318767369] ###0x13000109 # print(Table_rate) # print(pidevice.qWTR(wavegens=1)) pitools.waitontarget(pidevice, '%s'%moving_axis) print('Servo Status: ', pidevice.qSVO()) ''' Notice the Axis No.2!!!! ''' pidevice.WGO(wavegens[moving_axis-1], mode=[1]) while any(list(pidevice.IsGeneratorRunning(wavegens[moving_axis-1]).values())): print ('.') time.sleep(1.0) print('done') pidevice.WGO(wavegens[moving_axis-1], mode=[0]) # time.sleep(2.0) # pidevice.WGO(wavegens=1, mode=0)
def main(): """Connect, setup system and move stages and display the positions in a loop.""" # We recommend to use GCSDevice as context manager with "with". # The CONTROLLERNAME decides which PI GCS DLL is loaded. If your controller works # with the PI_GCS2_DLL (as most controllers actually do) you can leave this empty. with GCSDevice(CONTROLLERNAME) as pidevice: # InterfaceSetupDlg() is an interactive dialog. There are other methods to # connect to an interface without user interaction. pidevice.InterfaceSetupDlg(key='sample') # pidevice.ConnectRS232(comport=1, baudrate=115200) # pidevice.ConnectUSB(serialnum='123456789') # pidevice.ConnectTCPIP(ipaddress='192.168.178.42') # Controllers like C-843 and E-761 are connected via PCI. # pidevice.ConnectPciBoard(board=1) # Each PI controller supports the qIDN() command which returns an # identification string with a trailing line feed character which # we "strip" away. print('connected: {}'.format(pidevice.qIDN().strip())) # Show the version info which is helpful for PI support when there # are any issues. if pidevice.HasqVER(): print('version info: {}'.format(pidevice.qVER().strip())) # In pipython.pitools - here imported as "pi" - there are some helper # functions to make using a PI device more convenient. The "startup" # function will initialize your system. There are controllers that # cannot discover the connected stages hence we set them with the # "stages" argument. The desired referencing method (see controller # user manual) is passed as "refmode" argument print('initialize connected stages...') pitools.startup(pidevice, stages=STAGES, refmode=REFMODE) # Now we query the allowed motion range of all connected stages. # GCS commands often return an (ordered) dictionary with axes/channels # as "keys" and the according values as "values". rangemin = list(pidevice.qTMN().values()) rangemax = list(pidevice.qTMX().values()) ranges = zip(rangemin, rangemax) # To make this sample a bit more vital we will move to five different # random targets in a loop. for _ in range(5): targets = [uniform(rmin, rmax) for (rmin, rmax) in ranges] print(targets[0], targets[1]) print('move stages...') # The GCS commands qTMN() and qTMX() used above are query commands. # They don't need an argument and will then return all availabe # information, e.g. the limits for _all_ axes. With setter commands # however you have to specify the axes/channels. GCSDevice provides # a property "axes" which returns the names of all connected axes. # So lets move our stages... pidevice.MOV(pidevice.axes, targets) # To check the on target state of an axis there is the GCS command # qONT(). But it is more convenient to just call "waitontarget". pitools.waitontarget(pidevice) # GCS commands usually can be called with single arguments, with # lists as arguments or with a dictionary. # If a query command is called with an argument the keys in the # returned dictionary resemble the arguments. If it is called # without an argument the keys are always strings. positions = pidevice.qPOS(pidevice.axes) for axis in pidevice.axes: print('position of axis {} = {:.2f}'.format( axis, positions[axis])) # positions = pidevice.qPOS() # for axis in positions: # print('position of axis {} = {.2f}'.format(axis, positions[axis])) print('done')
): # you can remove this code block if your controller does not support WSL() print('connect wave generators {} to wave tables {}'.format( wavegens, wavetables)) pidevice.WSL(wavegens, wavetables) if pidevice.HasWGC( ): # you can remove this code block if your controller does not support WGC() print('set wave generators {} to run for {} cycles'.format( wavegens, NUMCYLES)) pidevice.WGC(wavegens, [NUMCYLES] * len(wavegens)) # if pidevice.HasWTR(): # you can remove this code block if your controller does not support WTR() # print('set wave table rate to {} for wave generators {}'.format(TABLERATE, wavegens)) # pidevice.WTR(wavegens, [TABLERATE] * len(wavegens), interpol=[0] * len(wavegens)) # startpos = (STARTPOS[0], STARTPOS[1] + AMPLITUDE[1] / 2.0) # print('move axes {} to their start positions {}'.format(pidevice.axes[:2], startpos)) # pidevice.MOV(pidevice.axes[:2], startpos) pitools.waitontarget(pidevice, '2') print('start wave generators {}'.format(wavegens)) pidevice.WGO(wavegens, mode=[1] * len(wavegens)) while any(list(pidevice.IsGeneratorRunning(wavegens).values())): print('.') sleep(1.0) print('done') pidevice.WGO(wavegens, mode=[0] * len(wavegens)) # pidevice.MVR('2', 0.01) ### y = 2 # header, data = drec.getdata() y_pos, z_rot, x_rot = data[0], data[1], data[2] samp_time = NUMVALUES / RECRATE