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 connect_motor(self, serial_port, *args): if serial_port == '': self.print_text_signal.emit( "A valid port was NOT selected! Select a valid port.") return False try: serialnum = args[0] self.gcs.ConnectUSB(serialnum=serialnum) pitools.startup(self.gcs, refmode=self.ref_mode) self.print_text_signal.emit("Connecting to " + serial_port + "...") # if self.gcs.IsConnected(): self.is_connected = True range_min = list(self.gcs.qTMN().values()) range_max = list(self.gcs.qTMX().values()) ranges = list(zip(range_min, range_max)) print(ranges) self.print_text_signal.emit( "Connection to Nanostage ESTABLISHED!") self.connected_signal.emit(True) return True else: self.print_text_signal.emit( "Connection to printer NOT established!") return False except Exception as e: print(e) self.gcs.close() self.print_text_signal.emit( "Connection to Nanostage NOT established!") return False
def initStage(self): # TODO put this in thread and show egg clock if self.stage is not None: ## Create and display the splash screen #splash_pix = QPixmap('icons/piController.png') #splash = QSplashScreen(splash_pix, Qt.WindowStaysOnTopHint) #splash.setMask(splash_pix.mask()) #splash.show() # TODO: give choice to select stage pitools.startup(self.stage, stages='M-112.1DG-NEW', refmode='FNL') #splash.close() # TODO: show dialog for waiting self.velocityLabel.setText('Velocity: {:f}mm/s'.format( self.stage.qVEL()['1'])) self.velocity.setValue(int(1000 * self.stage.qVEL()['1'])) self.stageConnected.emit() self._xAxeChanged() self.currentPos.setText('{:.7f}'.format(self.stage.qPOS()['1'])) self.__startCurrPosThr() self.stageRange = (self.stage.qTMN()['1'], self.stage.qTMX()['1']) self.scanStep.validator().setBottom(0) self.initStageBtn.setEnabled(False) else: msg = QMessageBox() msg.setIcon(QMessageBox.Critical) msg.setText('No stage connected') msg.exec_()
def connect(self): # if simulating, just wait a second and return if self.simulate: time.sleep(1.0) return usbdevices = self.calstage.EnumerateUSB() found = False if len(usbdevices) == 0: self.logger.error("No PI devices found") sys.exit() for device in usbdevices: if self.sn_controller in device: found = True if not found: self.logger.error('Serial number in ' + self.config_file + ' (' + self.sn_controller + ') does not match any of the connected USB devices; check power and USB') for device in usbdevices: self.logger.info(str(device) + ' is connected') sys.exit() self.calstage.ConnectUSB(serialnum=self.sn_controller) if not self.calstage.IsConnected(): self.logger.error('Error connecting to device') # enable servo and home to negative limit if necessary pitools.startup(self.calstage, refmodes=('FNL'))
def __init__(self, serialnum1='0109029920', serialnum2='0109029922' ): # should become a parameter, see other stages print(" " + str(serialnum1), " " + str(serialnum2), sep='\n') pidevice1 = GCSDevice(CONTROLLERNAME) pidevice1.ConnectUSB(serialnum1) pidevice2 = GCSDevice(CONTROLLERNAME) pidevice2.ConnectUSB(serialnum2) print(' ' + 'connected: {}'.format(pidevice1.qIDN().strip()), ' ' + 'connected: {}'.format(pidevice2.qIDN().strip()), sep='\n') # Show the version info which is helpful for PI support when there # are any issues. #if pidevice1.HasqVER(): # print(' '+'version info:\n{}'.format(pidevice1.qVER().strip())) #if pidevice2.HasqVEL(): # print('version info:\n{}'.format(pidevice2.qVER().strip())) # In the module pipython.pitools 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. All connected axes # will be stopped if they are moving and their servo will be enabled. print(' ' + 'initialize connected stages...') pitools.startup(pidevice1, stages=STAGES, refmodes=REFMODES) pitools.startup(pidevice2, stages=STAGES, refmodes=REFMODES) # Now we query the allowed motion range and current position of all # connected stages. GCS commands often return an (ordered) dictionary # with axes/channels as "keys" and the according values as "values". self.pidevice1 = pidevice1 self.pidevice2 = pidevice2 self.pidevice = pidevice2 self.wait = 1 # move commands wait for motion to stop self.unit_to_um = 1000.0 # PI stage's unit is in millimeters self.um_to_unit = 1.0 / self.unit_to_um # Connect to the stage. self.good = 1 # get min and max range for X controller self.rangemin_x = pidevice1.qTMN() self.rangemax_x = pidevice1.qTMX() self.curpos_x = pidevice1.qPOS() # get min and max range for Y controller self.rangemin_y = pidevice2.qTMN() self.rangemax_y = pidevice2.qTMX() self.curpos_y = pidevice2.qPOS()
def main(): """Connect controller, setup stages and start wave generator.""" with GCSDevice(CONTROLLERNAME) as pidevice: pidevice.InterfaceSetupDlg(key='sample') print('connected: {}'.format(pidevice.qIDN().strip())) print('initialize connected stages...') pitools.startup(pidevice, stages=STAGES, refmode=REFMODE) runwavegen(pidevice)
def main(): """Connect controller, setup stages and move all axes to targets read from CSV file 'DATAFILE'.""" with GCSDevice(CONTROLLERNAME) as pidevice: pidevice.InterfaceSetupDlg(key='sample') print('connected: {}'.format(pidevice.qIDN().strip())) print('initialize connected stages...') pitools.startup(pidevice, stages=STAGES, refmode=REFMODE) movetotargets(pidevice)
def startup(self): with self._lock: if not self.device: return print('initialize connected stages...') pitools.startup(self.device, stages=self._device_info['stages'], refmode=self._device_info['refmode'])
def main(): """Connect device, set up stage and read and display datarecorder data.""" with GCSDevice(CONTROLLERNAME) as pidevice: pidevice.InterfaceSetupDlg(key='sample') print('connected: {}'.format(pidevice.qIDN().strip())) print('initialize connected stages...') pitools.startup(pidevice, STAGES, REFMODE) header, data = readdatarecorder(pidevice) showdata(header, data)
def main(): """Connect controller, setup stages and start wave generator.""" with GCSDevice(CONTROLLERNAME) as pidevice: pidevice.ConnectTCPIP(ipaddress='192.168.178.42') # pidevice.ConnectUSB(serialnum='123456789') # pidevice.ConnectRS232(comport=1, baudrate=115200) print('connected: {}'.format(pidevice.qIDN().strip())) print('initialize connected stages...') pitools.startup(pidevice, stages=STAGES, refmodes=REFMODES) runwavegen(pidevice)
def main(): """Connect controller, setup stages and move all axes to targets read from CSV file 'DATAFILE'.""" with GCSDevice(CONTROLLERNAME) as pidevice: pidevice.ConnectTCPIP(ipaddress='192.168.178.42') # pidevice.ConnectUSB(serialnum='123456789') # pidevice.ConnectRS232(comport=1, baudrate=115200) print('connected: {}'.format(pidevice.qIDN().strip())) print('initialize connected stages...') pitools.startup(pidevice, stages=STAGES, refmodes=REFMODES) movetotargets(pidevice)
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 main(): """Connect controller, setup wave generator, move axes to startpoint and start wave generator.""" with GCSDevice(CONTROLLERNAME) as pidevice: pidevice.ConnectUSB(serialnum='0119024343') # pidevice.ConnectUSB(serialnum='123456789') # pidevice.ConnectRS232(comport=1, baudrate=115200) print('connected: %s' % pidevice.qIDN().strip()) print('initialize connected stages...') pitools.startup(pidevice, stages=STAGES, refmodes=REFMODES) runwavegen(pidevice)
def __init__(self, t0): self.t0 = t0 self.stage = GCSDevice('E-873') self.stage.ConnectUSB(serialnum=119040925) self.axis = '1' self.timeout = 5000 self.pos_max = 13.0 self.pos_min = -13.0 self.set_max_min_times() self.stage.VEL(self.axis, 3.0) # set the velocity to some low value to avoid crashes! pitools.startup(self.stage)
def __init__(self, t0): self.t0 = t0 self.stage = GCSDevice('HYDRA') # alternatively self.stage = GCSDevice(gcsdll='PI_HydraPollux_GCS2_DLL_x64.dll') for a fail safe option self.stage.ConnectTCPIP(ipaddress='192.168.0.2', ipport=400) self.axis = '1' self.timeout = 5000 self.pos_max = 610.0 self.pos_min = 0.0 self.set_max_min_times() self.stage.VEL(self.axis, 30.0) # set the velocity to some low value to avoid crashes! pitools.startup(self.stage)
def initialize(self): """ | The external core.Motor object is already initialized by executing super().__init__(self.serial). | So this function is just so that higher layers dont give errors. """ pidevice = GCSDevice('C-863.10') pidevice.InterfaceSetupDlg(key='sample') print('connected: {}'.format(pidevice.qIDN().strip())) print('initialize connected stages...') pitools.startup(pidevice, stages=self.STAGES, refmode=self.REFMODE) return pidevice self.logger.info('initialized PI motorcontroller')
def main(): """Connect device, set up stage and read and display datarecorder data.""" with GCSDevice(CONTROLLERNAME) as pidevice: pidevice.ConnectTCPIP(ipaddress='192.168.90.207') # pidevice.ConnectUSB(serialnum='123456789') # pidevice.ConnectRS232(comport=1, baudrate=115200) print('connected: {}'.format(pidevice.qIDN().strip())) print('initialize connected stages...') pitools.startup(pidevice, STAGES, REFMODES) drec = datarectools.Datarecorder(pidevice) recorddata(drec) print('move stage on axis {}...'.format(pidevice.axes[0])) pidevice.MVR(pidevice.axes[0], 0.1) processdata(drec)
def on_activate(self): """ Initialise and activate the hardware module. @return: error code (0:OK, -1:error) """ try: self.pidevice = GCSDevice(self._controllername) self.pidevice.ConnectTCPIP(self._ipaddress, self._ipport) device_name = self.pidevice.qIDN().strip() self.log.info('PI controller {} connected'.format(device_name)) pitools.startup(self.pidevice, stages=self._stages) return 0 except GCSError as error: self.log.error(error) return -1
def connect(self): if self.simulate: self.get_allowed_ranges() return if self.tiptilt.IsConnected(): self.logger.info('Already connected') usbdevices = self.tiptilt.EnumerateUSB() #"*** GCSError: There is no interface or DLL handle with the given ID (-9)" That error requires a power cycle found = False if len(usbdevices) == 0: self.logger.error("No PI devices found") sys.exit() for device in usbdevices: if self.sn_controller in device: found = True if not found: self.logger.error( 'Serial number in ' + self.config_file + ' (' + self.sn_controller + ') does not match any of the connected USB devices; check power and USB' ) for device in usbdevices: self.logger.info(str(device) + ' is connected') sys.exit() self.tiptilt.ConnectUSB(serialnum=self.sn_controller) #self.tiptilt.ConnectUSB(serialnum=self.sntiptilt) if not self.tiptilt.IsConnected(): self.logger.error('Error connecting to device') pitools.startup( self.tiptilt ) #, stages=['S-340'], servostates=[True])#, refmodes=('FNL')) # get the allowed ranges self.get_allowed_ranges() # move to the middle of the range self.move_tip_tilt(1.0, 1.0)
def __init__(self, serialnum='119006811' ): # should become a parameter, see other stages print(serialnum) # Connect to the PI E873 stage. # with GCSDevice(CONTROLLERNAME) as pidevice: pidevice = GCSDevice(CONTROLLERNAME) pidevice.ConnectUSB( serialnum) # pidevice.ConnectUSB(serialnum='119006811') 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:\n{}'.format(pidevice.qVER().strip())) # In the module pipython.pitools 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. All connected axes # will be stopped if they are moving and their servo will be enabled. print('initialize connected stages...') pitools.startup(pidevice, stages=STAGES, refmodes=REFMODES) # Now we query the allowed motion range and current position of all # connected stages. GCS commands often return an (ordered) dictionary # with axes/channels as "keys" and the according values as "values". self.pidevice = pidevice self.wait = 1 # move commands wait for motion to stop self.unit_to_um = 100.0 # needs calibration self.um_to_unit = 1.0 / self.unit_to_um # Connect to the stage. self.good = 1 # get min and max range self.rangemin = pidevice.qTMN() self.rangemax = pidevice.qTMX() self.curpos = pidevice.qPOS()
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 on_activate(self): """ Initialization """ try: # initalize the dll self.pidevice = GCSDevice(self._controllername) # open the connection self.pidevice.ConnectUSB(serialnum=self._serialnum) self.log.info('connected: {}'.format(self.pidevice.qIDN().strip())) # Initialize the axis label and axis ID (single axis controller) self.axes = self.pidevice.axes # this returns a list self._axis_label = self.axes[0] # axes is actuallly a list of length 1 self._axis_ID = self.pidevice.GetID() self.log.info(f'available axis: {self._axis_label}, ID: {self._axis_ID}') pitools.startup(self.pidevice) except Exception as e: self.log.error(f'Physik Instrumente PIFOC: Connection failed: {e}.')
def connect(self): """Connect, setup system and move stages and display the positions in a loop.""" self.pidevice = GCSDevice(CONTROLLERNAME) self.pidevice.ConnectUSB(serialnum='0145500270') #Serial number is not identical, check your connection. print('connected: {}'.format(self.pidevice.qIDN().strip())) if self.pidevice.HasqVER(): #Checking the version of PI controller. print('version info: {}'.format(self.pidevice.qVER().strip())) print('initialize connected stages...') pitools.startup(self.pidevice, stages=STAGES) self.pidevice.SVO(self.pidevice.axes,1) #SVO is servo ON for a controller self.pidevice.VEL(self.pidevice.axes,3) #VEL is a velocity of a motor self.pidevice.RON(self.pidevice.axes,0) #RON is a reference mode, 0 means off. self.pidevice.POS(self.pidevice.axes,0) #POS is abolute position, when the stage is connected, the positions = self.pidevice.qPOS(self.pidevice.axes) for axis in self.pidevice.axes: print('position of axis {} = {:.2f}'.format(axis, positions[axis])) print('stage connected') return self.pidevice
def __init__(self, parent=None): super().__init__(parent) ''' PI-specific code ''' from pipython import GCSDevice, pitools self.pitools = pitools ''' Setting up the PI stages ''' self.pi = self.cfg.pi_parameters self.controllername = self.cfg.pi_parameters['controllername'] self.pi_stages = self.cfg.pi_parameters['stages'] # ('M-112K033','L-406.40DG10','M-112K033','M-116.DG','M-406.4PD','NOSTAGE') self.refmode = self.cfg.pi_parameters['refmode'] # self.serialnum = ('118015439') # Wyss Geneva self.serialnum = self.cfg.pi_parameters['serialnum'] # UZH Irchel H45 self.pidevice = GCSDevice(self.controllername) self.pidevice.ConnectUSB(serialnum=self.serialnum) ''' PI startup ''' ''' with refmode enabled: pretty dangerous pitools.startup(self.pidevice, stages=self.pi_stages, refmode=self.refmode) ''' pitools.startup(self.pidevice, stages=self.pi_stages) ''' Stage 5 referencing hack ''' # print('Referencing status 3: ', self.pidevice.qFRF(3)) # print('Referencing status 5: ', self.pidevice.qFRF(5)) self.pidevice.FRF(5) print('M-406 Emergency referencing hack: Waiting for referencing move') self.block_till_controller_is_ready() print('M-406 Emergency referencing hack done') # print('Again: Referencing status 3: ', self.pidevice.qFRF(3)) # print('Again: Referencing status 5: ', self.pidevice.qFRF(5)) ''' Stage 5 close to good focus''' self.startfocus = self.cfg.stage_parameters['startfocus'] self.pidevice.MOV(5, self.startfocus / 1000)
#La librairie PI se trouve sur https://github.com/git-anonymous/PIPython J'en ai télécargé une version dans le dossier python_clément (à installer avec le setup.py). Pour les exemples j'utilise SimpleMove.py dans sample from pipython import GCSDevice, pitools CONTROLLERNAME = 'C-863.11' # 'C-863' will also work STAGES = ['M-111.1VG'] REFMODES = ['FNL', 'FRF'] with GCSDevice(CONTROLLERNAME) as pidevice: pidevice.ConnectUSB( serialnum='0165500259' ) #Le serial number il faut aller le chercher dans le logiciel PiMikromove, Quand tu connectes un controller dans USB daisy chain tu devrais voir "PI C-863 Mercury SN 'serial number'" print('connected: {}'.format(pidevice.qIDN().strip())) pitools.startup(pidevice, stages=STAGES, refmodes=REFMODES) rangemin = pidevice.qTMN() rangemax = pidevice.qTMX() curpos = pidevice.qPOS() print(rangemin, rangemax, curpos) axis = 1 target = 15 #en mm min=0 max=15 velocity = 0.6 #en mm/s max=0.65 pidevice.VEL(axis, velocity) print(pidevice.qVEL(axes=axis)) pidevice.MOV(axis, target) while not pidevice.qONT(axes=axis)[1]: pass
### 1=x,2=y,3=z_rot,4=z,5=x_rot,6=y_rot moving_axis = 2 wavegens = (1, 2, 3, 4, 5, 6) wavetables = (1, 2, 3, 4, 5, 6) with GCSDevice(CONTROLLERNAME) as pidevice: ''' Initialization ''' pidevice.InterfaceSetupDlg() print('connected: {}'.format(pidevice.qIDN().strip())) print('initialize connected stages...') pitools.startup(pidevice, STAGES, REFMODE) IDN = pidevice.qIDN() print('IDN: ', IDN) print('Servo Status: ', pidevice.qSVO()) pidevice.WGO(wavegens, mode=[0]*len(wavegens)) ''' Auto-Zero ''' # pidevice.ATZ({1:0, 2:0, 4:0}) # time.sleep(5) ''' Turn on control loop ''' pidevice.SVO({'1':1,'2':1,'3':1,'4':1,'5':1,'6':1}) # print('Servo Status: ', pidevice.qSVO()) '''
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')
def connect(self): S = self.settings self.gcs = GCSDevice(S.controller.val) self.gcs.ConnectRS232(comport=8, baudrate=38400) #self.gcs.ConnectUSB(serialnum='0135500849') print(self.gcs.qPOS(self.gcs.axes)['1']) if S.initial_ref_mode.val != 'None': pitools.startup(self.gcs, stages=S.stage.val, refmode=S.ref_mode.val) else: pitools.startup(self.gcs, stages=S.stage.val, refmode=None) self.gcs.RON(self.gcs.axes, False) self.gcs.POS(self.gcs.axes, self.gcs.qPOS(self.gcs.axes)['1']) #self.gcs.MVR(self.gcs.axes, 0.1) #print(self.gcs.IsMoving(self.gcs.axes)['1']) self.rangemin.hardware_read_func = self.GetRangeMN self.rangemax.hardware_read_func = self.GetRangeMX self.rangemin.read_from_hardware() self.rangemax.read_from_hardware() for ax_num, ax_name in self.axes.items(): lq = S.get_lq(ax_name + "_position") lq.connect_to_hardware( read_func=lambda n=ax_num: self.gcs.qPOS()[str(n)]) lq.read_from_hardware() lq = S.get_lq(ax_name + "_target") lq.connect_to_hardware( read_func=lambda n=ax_num: self.gcs.qMOV()[str(n)], write_func=lambda new_target, n=ax_num: self.gcs.MOV( n, new_target)) lq.read_from_hardware() lq = S.get_lq(ax_name + "_servo") lq.connect_to_hardware( read_func=lambda n=ax_num: self.gcs.qSVO()[str(n)], write_func=lambda enable, n=ax_num: self.gcs.SVO(n, enable)) lq.read_from_hardware() lq = S.get_lq(ax_name + "_on_target") lq.connect_to_hardware( read_func=lambda n=ax_num: self.gcs.qONT()[str(n)], ) lq.read_from_hardware() lq = S.get_lq(ax_name + "_velocity") lq.connect_to_hardware( read_func=lambda n=ax_num: self.gcs.qVEL()[str(n)], write_func=lambda new_vel, n=ax_num: self.gcs.VEL(n, new_vel)) lq.read_from_hardware() self.update_thread_interrupted = False self.update_thread = threading.Thread(target=self.update_thread_run) self.update_thread.start()
def on_activate(self): try: self.first_axis_label = self._first_axis_label self.second_axis_label = self._second_axis_label self.third_axis_label = self._third_axis_label # open the daisy chain connection self.pidevice_1st_axis = GCSDevice( self._first_axis_controllername ) # 1st axis controller # master device self.pidevice_2nd_axis = GCSDevice( self._second_axis_controllername) # 2nd axis controller self.pidevice_3rd_axis = GCSDevice( self._third_axis_controllername) # 3rd axis controller self.pidevice_1st_axis.OpenUSBDaisyChain( description=self._serialnum_master) self.daisychainid = self.pidevice_1st_axis.dcid print(f'Daisychainid: {self.daisychainid}') # controllers are ordered with increasing serial number in the daisy chain # this is why z is connected as first # do we need to programmatically sort by nth_axis_daisychain id ?? self.pidevice_3rd_axis.ConnectDaisyChainDevice( self._third_axis_daisychain_id, self.daisychainid) # SN 019550119 self.pidevice_1st_axis.ConnectDaisyChainDevice( self._first_axis_daisychain_id, self.daisychainid) # SN 019550121 self.pidevice_2nd_axis.ConnectDaisyChainDevice( self._second_axis_daisychain_id, self.daisychainid) # SN 019550124 print('\n{}:\n{}'.format( self.pidevice_1st_axis.GetInterfaceDescription(), self.pidevice_1st_axis.qIDN())) print('\n{}:\n{}'.format( self.pidevice_2nd_axis.GetInterfaceDescription(), self.pidevice_2nd_axis.qIDN())) print('\n{}:\n{}'.format( self.pidevice_3rd_axis.GetInterfaceDescription(), self.pidevice_3rd_axis.qIDN())) # initialization of all axes print('Initializing PI stage ...') # servo on pitools.startup(self.pidevice_1st_axis) pitools.startup(self.pidevice_2nd_axis) pitools.startup(self.pidevice_3rd_axis) print('Please wait ... ') # the IDs are needed to address the axes in the dll functions self.first_axis_ID = self.pidevice_1st_axis.axes[ 0] # each controller is connected to one stage; so just take the first element # print(self.first_axis_ID) self.second_axis_ID = self.pidevice_2nd_axis.axes[0] # print(self.second_axis_ID) self.third_axis_ID = self.pidevice_3rd_axis.axes[0] # print(self.third_axis_ID) self.calibrate() # RON: # FNL: fast move to negative limit # self.pidevice_1st_axis.RON(self.first_axis_ID, values=1) # self.pidevice_1st_axis.FNL(self.first_axis_ID) # self.pidevice_2nd_axis.RON(self.second_axis_ID, values=1) # self.pidevice_2nd_axis.FNL(self.second_axis_ID) # self.pidevice_3rd_axis.RON(self.third_axis_ID, values=1) # self.pidevice_3rd_axis.FNL(self.third_axis_ID) # pitools.waitontarget(self.pidevice_1st_axis, axes=self.first_axis_ID) # pitools.waitontarget(self.pidevice_2nd_axis, axes=self.second_axis_ID) # pitools.waitontarget(self.pidevice_3rd_axis, axes=self.third_axis_ID) except Exception as e: self.log.error( f'Physik Instrumente 3-axes stage: Connection failed: {e}. Check if device is switched on.' )
def run_experiment(app, info): try: #perform experiment CONTROLLERNAME = 'E-873' STAGES = ['Q-545.240'] REFMODES = ['FNL', 'FRF'] comport = info.port_mot with GCSDevice(CONTROLLERNAME) as pidevice: # Choose the interface according to your cabling. pidevice.ConnectRS232(comport=1, baudrate=115200) # 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:\n{}'.format(pidevice.qVER().strip())) # In the module pipython.pitools 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. All connected axes # will be stopped if they are moving and their servo will be enabled. print('initialize connected stages...') pitools.startup(pidevice, stages=STAGES, refmodes=REFMODES) # Now we query the allowed motion range and current position of all # connected stages. GCS commands often return an (ordered) dictionary # with axes/channels as "keys" and the according values as "values". rangemin = pidevice.qTMN() rangemax = pidevice.qTMX() curpos = pidevice.qPOS() info.finished = False pidevice.VEL("1", info.max_velocity) stop_thread = threading.Thread(target=check, args=(app, pidevice)) stop_thread.daemon = True stop_thread.start() # 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... if (info.shut_status and not info.continuous and info.shut_connected): # Shutter and not continuous case_0_experiment(pidevice, app, info, rangemin, rangemax, curpos) elif (info.shut_status and info.continuous and info.shut_connected): # Shutter and continuous case_1_experiment(pidevice, app, info, rangemin, rangemax, curpos) elif (not info.shut_status and not info.continuous and info.shut_connected): # No shutter and not continuous case_2_experiment(pidevice, app, info, rangemin, rangemax, curpos) elif (not info.shut_status and info.continuous and info.shut_connected): # No shutter and continuous case_3_experiment(pidevice, app, info, rangemin, rangemax, curpos) elif (not info.continuous and not info.shut_connected ): # Shutter not connected and not continuous case_4_experiment(pidevice, app, info, rangemin, rangemax, curpos) elif (info.continuous and not info.shut_connected ): # Shutter not connected and continuous case_5_experiment(pidevice, app, info, rangemin, rangemax, curpos) except: print('An error has occured:') finally: app.info.finished = True print('Processes finished')