def __init__(self, sn_motor1=94832870, sn_motor2=94832869, **kwds): """ Connect to the thorlabs stage at the specified port. """ self.live = True self.unit_to_um = 1000.0 # units are mm self.um_to_unit = 1.0 / self.unit_to_um self.x = 0.0 self.y = 0.0 # sn_motor1 = 94832870 # sn_motor2 = 94832869 self.Motor1 = APTMotor(sn_motor1, HWTYPE=44) # initialize motor 1 "x" self.Motor2 = APTMotor(sn_motor2, HWTYPE=44) # initizalize motor 2 "y"
def connect_motor(serial_no): print("**** CONNECTING TO MOTOR", serial_no, "****") try: motor = APTMotor(SerialNum = serial_no, dllname=dll_location) except Exception as e: print("**** CONNECTION FAILED ****") raise try: pass #motor.go_home() except ValueError: pass # always gives a ValueError for some reason motor.identify() # blink to show connection clearly print(serial_no, "\n**** CONNECTED ****") return motor
def __init__(self, parent=None, serial=00000000, verbose=False): ##, verbose=False super(widgetAPT, self).__init__(parent) self.resize(1300, 650) self.setWindowTitle('FROG') self.setWindowIcon(QIcon('iiserb.png')) layout = QGridLayout() ## self.setLayout(layout) self.data = np.genfromtxt('N1648.txt', skip_header=12, skip_footer=7308) # Layout objects sStag = QLabel("Stage", self) sStag.setStyleSheet("font: 22pt;") layout.addWidget(sStag, 2, 2) sAuthor = QLabel("Frequency Resolved Optical Gating", self) sAuthor.setStyleSheet("font: 40pt; color:green") layout.addWidget(sAuthor, 1, 3, 1, 15) # Motor Serial Number sSer = QLabel("Serial:", self) sSer.setStyleSheet("font: 16pt;") layout.addWidget(sSer, 3, 1) self.txtSerial = QSpinBox(self) self.txtSerial.setRange(0, 99999999) self.txtSerial.setSingleStep(1) self.txtSerial.setValue(27503288) layout.addWidget(self.txtSerial, 3, 2) self._Motor_ = APTMotor(verbose=verbose) # Motor Connect button self.btnConnect = QPushButton("Connect", self) self.btnConnect.setStyleSheet("background-color: grey") self.btnConnect.setText("Connect") self.btnConnect.setCheckable(True) self.btnConnect.setToolTip("Connect to Motor") self.btnConnect.clicked[bool].connect(self.connectAPT) layout.addWidget(self.btnConnect, 3, 3) sPos = QLabel("Pos:", self) sPos.setStyleSheet("font: 16pt;") self.txtPos = QDoubleSpinBox(self) self.txtPos.setRange(-5, 13) self.txtPos.setSingleStep(.1) self.txtPos.setDecimals(5) self.txtPos.setValue(0.0000000) self.txtPos.setToolTip("Current Motor Position") self.txtPos.setEnabled(False) layout.addWidget(sPos, 4, 1) layout.addWidget(self.txtPos, 4, 2) # Go to position self.btnGOp = QPushButton("Go", self) self.btnGOp.clicked.connect( lambda: self.motAbs(float(self.txtPos.text()))) layout.addWidget(self.btnGOp, 4, 3) #Home button self.btnHome = QPushButton("Home", self) self.btnHome.setToolTip("This will take the stage to 6.50") layout.addWidget(self.btnHome, 5, 1, 1, 1.5) self.btnHome.clicked.connect(lambda: self.motAbs(6.50000)) #go to zero self.btnZero = QPushButton("Go to Zero", self) self.btnZero.setToolTip("This will take the stage to absolute 0") layout.addWidget(self.btnZero, 5, 2, 1, 1.5) self.btnZero.clicked[bool].connect(lambda: self._Motor_.go_home()) #Velocity buttons sVel = QLabel("Velocity:", self) sVel.setStyleSheet("font: 14pt;") self.txtVel = QDoubleSpinBox(self) self.txtVel.setRange(0, 2.2) self.txtVel.setSingleStep(.1) self.txtVel.setValue(1.5) self.txtVel.setToolTip("set the velocity here") self.txtVel.setEnabled(False) layout.addWidget(sVel, 6, 1) layout.addWidget(self.txtVel, 6, 2) self.btnGOv = QPushButton("Set", self) self.btnGOv.clicked.connect( lambda: self._Motor_.setVel(float(self.txtVel.text()))) layout.addWidget(self.btnGOv, 6, 3) sBack = QLabel("Backlash:", self) sBack.setStyleSheet("font: 14pt;") self.cbBacklash = QCheckBox(self) layout.addWidget(sBack, 7, 1) layout.addWidget(self.cbBacklash, 7, 2) sSpect = QLabel("Spectrometer", self) sSpect.setStyleSheet("font: 22pt;") sSpect.setFont(QFont('Arial', 20)) layout.addWidget(sSpect, 8, 2) texp = QLabel("Time of Exp.:", self) texp.setStyleSheet("font: 14pt;") layout.addWidget(texp, 9, 1) self.timexp = QDoubleSpinBox(self) self.timexp.setRange(0, 100000) self.timexp.setSingleStep(1) self.timexp.setDecimals(0) self.timexp.setValue(10) layout.addWidget(self.timexp, 9, 2) self.btnCh = QPushButton("Set", self) layout.addWidget(self.btnCh, 9, 3) nscan = QLabel("Num. of scan:", self) nscan.setStyleSheet("font: 14pt;") layout.addWidget(nscan, 10, 1) self.nscantxt = QDoubleSpinBox(self) self.nscantxt.setRange(0, 137) self.nscantxt.setSingleStep(1) self.nscantxt.setDecimals(0) self.nscantxt.setValue(10) layout.addWidget(self.nscantxt, 10, 2) self.nscan = QPushButton("Set", self) layout.addWidget(self.nscan, 10, 3) #self.timexp.setEnabled(False) ## self.timeofexposure = c_uint32(1000) self.btnCh.clicked[bool].connect(self.assignexp) self.nscan.clicked[bool].connect(self.assignnscan) sSpos = QLabel("Signal pos.(mm):") sSpos.setStyleSheet("font: 14pt;") self.txtSpos = QDoubleSpinBox(self) self.txtSpos.setRange(0, 12.0000) self.txtSpos.setDecimals(5) self.txtSpos.setSingleStep(0.00001) self.txtSpos.setValue(6.50000) layout.addWidget(sSpos, 12, 1) layout.addWidget(self.txtSpos, 12, 2) self.btnSpos = QPushButton("Set", self) layout.addWidget(self.btnSpos, 12, 3) self.btnSpos.clicked[bool].connect( lambda: self.txtSpos.setValue(float(self.txtSpos.text()))) sSpectra = QLabel("Spectrum", self) sSpectra.setStyleSheet("font: 14pt;") sSpectra.setFont(QFont('Arial', 20)) layout.addWidget(sSpectra, 13, 1) #----------------------------Spectromter Plot---------------------------------------------------------------------------------------------------- #time of exposure box self.spectra = create_string_buffer(7500) pg.setConfigOption('background', 'w') self.plot1 = pg.PlotWidget() layout.addWidget(self.plot1, 3, 7, 8, 8) self.timer = pg.QtCore.QTimer() self.liveb = QPushButton('Live', self) layout.addWidget(self.liveb, 13, 2) self.liveb.setCheckable(True) self.liveb.clicked[bool].connect(self.live) self.lbox = QCheckBox(self) ## self.timer.timeout.connect(self.updater) ## self.static = QCheckBox(self) layout.addWidget(self.lbox, 13, 3) self.fname = QLineEdit(self) self.fname.setToolTip("ENTER FILENAME.TXT") layout.addWidget(self.fname, 14, 1, 1, 2) self.sScan = QPushButton("Start Scan", self) layout.addWidget(self.sScan, 14, 3, 1, 1) self.sScan.clicked[bool].connect(self.scan) self.pbar = QProgressBar(self) layout.addWidget(self.pbar, 15, 1, 1, 2) ## self.spectra = create_string_buffer(7500) ## cam.sptdll.getFrame(byref(self.spectra),0xFFFF) ## self.b = np.frombuffer(self.spectra, dtype=np.uint16) ## self.plot1.plot(self.data,self.b[0:3653],pen='b', clear=True) ## pg.QtGui.QApplication.processEvents() ##----------------------------------------------------------------------------------------- self.figure = Figure() self.canvas = FigureCanvas(self.figure) # this is the Navigation widget # it takes the Canvas widget and a parent self.toolbar = NavigationToolbar(self.canvas, self) # Just some button connected to `plot` method self.button = QPushButton('Plot') self.button.clicked.connect(self.graph) # set the layout layout.addWidget(self.toolbar, 11, 7, 1, 8) layout.addWidget(self.canvas, 12, 7, 5, 8) layout.addWidget(self.button, 15, 3, 1, 1) self.setLayout(layout) self.ex = QPushButton('EXIT', self) layout.addWidget(self.ex, 16, 2, 2, 1) self.ex.clicked.connect(lambda: self._Motor_.cleanUpAPT())
def right(d, v=0.3): motVel = v #motor velocity, in mm/sec Motor2.mcRel(-d, motVel) # Negative Right / Positive Left def up(d, v=0.3): motVel = v #motor velocity, in mm/sec Motor1.mcRel(d, motVel) # negative me / positive knife def down(d, v=0.3): motVel = v #motor velocity, in mm/sec Motor1.mcRel(-d, motVel) # negative me / positive knife Motor1 = APTMotor(45844773, HWTYPE=42) Motor2 = APTMotor(45844576, HWTYPE=42) # print 'Motor1', Motor1.getPos() # time.sleep(0.1) # print 'Motor2', Motor2.getPos() # offset1 = 0 # offset2 = 0 # print 'Motor1', Motor1.getStageAxisInformation() # Motor1.setStageAxisInformation(offset1, offset1 + 145) # print 'Motor1', Motor1.getStageAxisInformation() # print 'Motor2', Motor2.getStageAxisInformation() # Motor2.setStageAxisInformation(offset2, offset2 + 145)
V1.2 20141125 V1.0 First working version 20141201 V1.0a Updated to short notation 20150324 V1.1 Added more descriptions 20150417 V1.2 Implemented motor without serial Michael Leung [email protected] """ # Import APTMotor class from PyAPT from PyAPT import APTMotor import time # Create object corresponding to the motor. Motor1 = APTMotor( 83828393, HWTYPE=31) # The number should correspond to the serial number. # Use help APTMotor to obtain full list of hardware (HW) supported. # Note: You can control multiple motors by creating more APTMotor Objects # Obtain current position of motor print(Motor1.getPos()) # You can control multiple motors by creating more APTMotor Objects # Serial numbers can be added later by using setSerialNumber and initializeHardwareDevice # This functionality is particularly useful in the GUI setup. Motor2 = APTMotor() Motor2.setSerialNumber(83828393) Motor2.initializeHardwareDevice() print(Motor2.getPos())
def __init__(self, parent=None, serial=00000000, verbose=False): super(widgetAPT, self).__init__(parent) self.resize(200, 100) #self.move(100, 100) #setGeometry sets both location and size #self.setGeometry(50, 50, 1180, 900) self.setWindowTitle('APT Motor') #self.m = APTMotor(0) # QT GridLayout # TODO: Implement GridLayout #grid = QGridLayout() # Layout objects sAuthor = QLabel("QT-APT", self) sAuthor.resize(100, 20) sAuthor.move(100, 0) sAuthor.setAlignment(Qt.AlignRight) sVersion = QLabel("v1.0.0", self) sVersion.resize(100, 20) sVersion.move(100, 15) sVersion.setAlignment(Qt.AlignRight) sEmail = QLabel("Michael Leung", self) sEmail.resize(100, 40) sEmail.move(100, 30) sEmail.setAlignment(Qt.AlignRight) # Motor Serial Number sSer = QLabel("Serial:", self) sSer.resize(60, 20) sSer.move(0, 0) self.txtSerial = QSpinBox(self) self.txtSerial.resize(70, 20) self.txtSerial.move(30, 0) self.txtSerial.setRange(0, 99999999) self.txtSerial.setSingleStep(1) self.txtSerial.setValue(83840946) # qle.textChanged[str].connect(self.onChanged) #do onChanged when changed self._Motor_ = APTMotor(verbose=verbose) # Motor Connect self.btnConnect = QPushButton("Connect", self) self.btnConnect.setStyleSheet("background-color: grey") self.btnConnect.setText("Connect") self.btnConnect.setCheckable(True) self.btnConnect.setToolTip("Connect to Motor") self.btnConnect.resize(50, 20) self.btnConnect.move(105, 0) self.btnConnect.clicked[bool].connect(self.connectAPT) sPos = QLabel("Pos:", self) sPos.resize(70, 20) sPos.move(0, 25) self.txtPos = QDoubleSpinBox(self) self.txtPos.resize(60, 20) self.txtPos.move(30, 25) #self.txtPos.setMaxLength(7) self.txtPos.setRange(0, 20) self.txtPos.setSingleStep(.1) self.txtPos.setDecimals(5) self.txtPos.setValue(0.0000000) self.txtPos.setToolTip("Current Motor Position") #self.txtPos.setValidator( QDoubleValidator(0, 100, 2) ) self.txtPos.setEnabled(False) # Go to position btnGOp = QPushButton("Go", self) btnGOp.resize(25, 20) btnGOp.move(100, 25) btnGOp.clicked.connect(lambda: self.motAbs(float(self.txtPos.text()))) # Movement buttons btnN3 = QPushButton("-100", self) btnN3.resize(32, 20) btnN3.move(0, 50) btnN3.clicked.connect(lambda: self.motRel(-.1)) btnN2 = QPushButton("-10", self) btnN2.resize(32, 20) btnN2.move(33, 50) btnN2.clicked.connect(lambda: self.motRel(-.01)) btnN1 = QPushButton("-1", self) btnN1.resize(32, 20) btnN1.move(66, 50) btnN1.clicked.connect(lambda: self.motRel(-.001)) btnP1 = QPushButton("+1", self) btnP1.resize(32, 20) btnP1.move(100, 50) btnP1.clicked.connect(lambda: self.motRel(.001)) btnP2 = QPushButton("+10", self) btnP2.resize(32, 20) btnP2.move(133, 50) btnP2.clicked.connect(lambda: self.motRel(.01)) btnP3 = QPushButton("+100", self) btnP3.resize(32, 20) btnP3.move(166, 50) btnP3.clicked.connect(lambda: self.motRel(.1)) sVel = QLabel("Vel:", self) sVel.resize(60, 20) sVel.move(0, 75) self.txtVel = QDoubleSpinBox(self) self.txtVel.resize(60, 20) self.txtVel.move(30, 75) #self.txtVel.setMaxLength(7) self.txtVel.setRange(0, 2.2) self.txtVel.setSingleStep(.1) self.txtVel.setValue(0.000) self.txtVel.setToolTip("Current Motor Position") self.txtVel.setEnabled(False) # Go to velocity btnGOv = QPushButton("Go", self) btnGOv.resize(25, 20) btnGOv.move(100, 75) btnGOv.clicked.connect( lambda: self._Motor_.setVel(float(self.txtVel.text()))) sBack = QLabel("Backlash:", self) sBack.resize(60, 20) sBack.move(130, 75) self.cbBacklash = QCheckBox(self) self.cbBacklash.resize(60, 20) self.cbBacklash.move(180, 75) self.show()
# Import APTMotor class from PyAPT from PyAPT import APTMotor import time import ipdb # Focus stage (I think) SN = 80851661 HWTYPE = 31 # I2 stage (I think) #SN = 40853360 #HWTYPE = ?? # Create object corresponding to the motor. Motor1 = APTMotor(SN, HWTYPE=HWTYPE) # The number should correspond to the serial number. # Use help APTMotor to obtain full list of hardware (HW) supported. # Note: You can control multiple motors by creating more APTMotor Objects # Obtain current position of motor print(Motor1.getPos()) ipdb.set_trace() # You can control multiple motors by creating more APTMotor Objects # Serial numbers can be added later by using setSerialNumber and initializeHardwareDevice # This functionality is particularly useful in the GUI setup. Motor2 = APTMotor() Motor2.setSerialNumber(SN)
def __init__(self): self.M = APTMotor(83829712, HWTYPE=31, verbose=True) self.df = pd.read_csv('../../HPF_FRD/sequence.csv') self.x = df.x_out_fiber_dist.values
from PyAPT import APTMotor import datetime import time import ipdb #S Focus stage #SN = 80851661 #HWTYPE = 31 ipdb.set_trace() #S Iodine stage SN = 40864672 HWTYPE = 12 motor = APTMotor(SN,HWTYPE) start = datetime.datetime.now() motor.initializeHardwareDevice() end = datetime.datetime.now() print 'connected :' + str((end-start).total_seconds()) currentPos = motor.getPos() print currentPos motor.mAbs(0.0) #time.sleep(5) currentPos = motor.getPos() print currentPos
# -*- coding: utf-8 -*- """ Created on Wed May 24 15:37:18 2017 @author: Neo """ import time import sys import os sys.path.append(os.path.abspath('D:\WMP_setup\Python_codes\PyAPT-master')) from PyAPT import APTMotor #filter, rot4 try: rot4 = APTMotor(83847409,HWTYPE=31) rot4.setVelocityParameters(0,25,25) def move_rot4(ang=None): if ang == None: return rot4.getPos() else: rot4.mAbs(ang) return move_rot4(ang=None) def home_rot4(): rot4.go_home() print 'rot4 online.' except: print('rot4 not connected')
# Connecting to camera bus = PyCapture2.BusManager() cam = PyCapture2.Camera() try: uid = bus.getCameraFromSerialNumber(serial_camera) cam.connect(uid) printCameraInfo(cam) except PyCapture2.Fc2error: print("Error: Failed to connect to camera #", serial_camera) sys.exit() # Connecting to stage try: z_axis = APTMotor(serial_z, HWTYPE=TDC001) except: print("Error: Failed to connec to Z axis #", serial_z) sys.exit() try: x_axis = APTMotor(serial_x, HWTYPE=TDC001) except: print("Error: Failed to connec to X axis #", serial_x) sys.exit() # Homing stage if home: print("Homing axis Z...\t", end='') z_axis.go_home() print("[DONE]\nHoming axis X...\t", end='')
# -*- coding: utf-8 -*- """ Created on Wed May 24 15:37:18 2017 @author: Neo """ import time import sys import os sys.path.append(os.path.abspath('D:\WMP_setup\Python_codes\PyAPT-master')) from PyAPT import APTMotor #unused, rot1 try: rot1 = APTMotor(83845997, HWTYPE=31) rot1.setVelocityParameters(0, 25, 25) def move_rot1(ang=None): if ang == None: return rot1.getPos() else: rot1.mAbs(ang) return move_rot1(ang=None) def home_rot1(): rot1.go_home() print 'rot1 online.' except: print('rot1 not connected')
# -*- coding: utf-8 -*- """ Created on Wed May 24 15:37:18 2017 @author: Neo """ import sys import os sys.path.append(os.path.abspath('D:\WMP_setup\Python_codes\PyAPT-master')) from PyAPT import APTMotor #analyzer, rot5 try: rot5 = APTMotor(28250988,HWTYPE=28) def move_rot5(ang=None): if ang == None: ans = rot5.getPos()*360. if ans > 64800: ans -= 129600 ans %= -360 else: ans %= 360 return ans else: rot5.mAbs((ang/360.)%360) #/360 to convert to correct unit, %360 to keep in 1 rotation return move_rot5(ang=None) def home_rot5(): rot5.go_home()