Ejemplo n.º 1
0
class MotorController(object):
    '''
    classdocs
    '''


    def __init__(self):
        '''
        Constructor
        
        correct serial number:
        old 83863559
        83815746
        '''
        self.connectFailed = False
        try:
            self.Motor1 = APTMotor(83863559, HWTYPE=31)
            print self.Motor1.getHardwareInformation()
            print self.Motor1.getStageAxisInformation()
            print self.Motor1.getVelocityParameters()
#             self.degreeConv = 15.0156077
            self.degreeConv = 1
            self.Motor1.setVelocityParameters(0.0, 5.0, 5.99976)
            print self.Motor1.getVelocityParameters()
        except Exception as e:
            import ThreadedGUI
            self.connectFailed = True
            title = "Motor Connection Error"
            text = "Motor connection failed, make sure it is connected"
            p = mp.Process(target = ThreadedGUI.displayError, args =(title, text) )
            p.start()
            p.join()
    
    
    def moveMotor(self, ang):
        self.Motor1.mcRel(ang/self.degreeConv,5.99976)
#         ans = self.Motor1.getPos()*self.degreeConv
#         return ans
        return 1
    
    def Home(self):
        self.Motor1.go_home()
        return True
    
    def BlinkSomeLights(self):
        self.Motor1.identify()
        return True
    
    def getPosition(self):
        return self.Motor1.getPos()*self.degreeConv
    
    def moveTo(self, ang):
        return self.Motor1.mAbs(ang/self.degreeConv)*self.degreeConv
        
Ejemplo n.º 2
0
class widgetAPT(QWidget):
    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 live(self):

        if self.lbox.isChecked():
            self.timer.timeout.connect(self.updater)
            self.timer.start(5)

        else:
            self.timer.stop()

    def updater(self):
        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)

    def scan(self, pressed):

        self.completed = 0

        self.pbar.setValue(self.completed)
        #writing in file
        starting = float(self.txtSpos.text()) - 0.045
        self.motAbs(starting)

        if (self.fname.text() == ""):
            now = datetime.datetime.now()
            self.name = now.strftime("%Y %m %d %H %M")

        else:
            self.name = self.fname.text()
        speed = 3e8
        for i in range(60):  #replaced 60 by 100

            self.completed += 1.66667

            self.pbar.setValue(self.completed)

            self.motRel(0.00150)

            fo = open(
                r"C:\Users\creates\Desktop\Frog\FROG_soft\DATA_ACQUISITION\\" +
                self.name + ".txt", "a+")

            cam.sptdll.getFrame(byref(self.spectra), 0xFFFF)
            self.b = np.frombuffer(self.spectra, dtype=np.uint16)
            fo.write("\t")

            for j in range(3653):
                fo.write(str((i + 1 - 30) * (0.000015) * (1 / speed)))
                fo.write("\t")
                fo.write(str(self.data[j]))
                fo.write("\t")
                fo.write(str(self.b[j]))
                fo.write("\n")
                fo.write("\t")
            fo.close()
        self.completed = 100
        self.pbar.setValue(self.completed)
        return True

    def assignexp(self, pressed):
        e = c_uint32(int(self.timexp.text()))
        cam.sptdll.setExposure(cam.timeofexposure)
        cam.sptdll.setAcquisitionParameters(cam.numScans, cam.numblankscans,
                                            cam.scanmode, e)
        pg.QtGui.QApplication.processEvents()
        return True

    def assignnscan(self, pressed):
        n = c_uint16(int(self.nscantxt.text()))
        cam.sptdll.setAcquisitionParameters(n, cam.numblankscans, cam.scanmode,
                                            cam.timeofexposure)
        pg.QtGui.QApplication.processEvents()
        return True

    def connectAPT(self, pressed):
        if pressed:
            #APT Motor connect
            Serial = int(self.txtSerial.text())
            self._Motor_.setSerialNumber(Serial)
            self._Motor_.initializeHardwareDevice()

            # Success
            self.btnConnect.setStyleSheet("background-color: green")
            self.btnConnect.setText("Connected")

            self.txtSerial.setEnabled(False)
            self.txtPos.setEnabled(True)
            # Update text to show position
            self.txtPos.setValue(self._Motor_.getPos())

            self.txtVel.setEnabled(True)
            _, _, maxVel = self._Motor_.getVelocityParameters()
            self.txtVel.setValue(maxVel)
            self._Motor_.go_home()

            return True
        else:
            self.btnConnect.setStyleSheet("background-color: grey")
            self.btnConnect.setText("Connect")

            self.txtSerial.setEnabled(True)
            self.txtPos.setEnabled(False)
            self.txtVel.setEnabled(False)
            self.txtPos.setValue(0.0000)
            self.txtPos.setToolTip("Current Motor Position")
            return True

    def motRel(self, relDistance):
        self._Motor_.setVel(float(self.txtVel.text()))
        if self.cbBacklash.isChecked():
            self._Motor_.mbRel(relDistance)
        else:
            self._Motor_.mcRel(relDistance)

        self.txtPos.setValue(self._Motor_.getPos())

    def motAbs(self, absDistance):
        self._Motor_.setVel(float(self.txtVel.text()))
        if self.cbBacklash.isChecked():
            self._Motor_.mbAbs(absDistance)
        else:
            self._Motor_.mAbs(absDistance)
        # Update text to show position
        self.txtPos.setValue(self._Motor_.getPos())

    def graph(self):
        ''' plot some random stuff '''
        filename = str("max2_F.txt")

        data = np.loadtxt(filename)
        x = data[:, 0]  #Scan number
        y = data[:, 1]
        z = data[:, 2]  #Intensity
        zmat = z.reshape(60, 3653)
        ##        print("here")
        # create an axis

        ax = self.figure.add_subplot(111)
        ax2 = self.figure.add_subplot(112)
        # discards the old graph
        ax.clear()

        ax.imshow(np.transpose(zmat),
                  cmap=cm.jet,
                  aspect=10,
                  extent=(-150, 150, 370, 430),
                  interpolation='nearest')  ##,aspect=10,extent=(0,300,370,430)

        self.canvas.draw()
Ejemplo n.º 3
0
[email protected]
"""

# Import APTMotor class from PyAPT
from PyAPT import APTMotor
import time

# Create object corresponding to the motor.83840805
Motor1 = APTMotor(83840805, 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(83829690)
Motor2.initializeHardwareDevice()
print(Motor2.getPos())

# Move motor forward by 1mm, wait half a second, and return to original position.
# mRel is move relative. mAbs is move absolute (go to position xxx)
Motor1.mRel(1) # advance 1mm
time.sleep(.5)
Motor1.mRel(-1) # retract 1mm
Ejemplo n.º 4
0
[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())

# Move motor forward by 1mm, wait half a second, and return to original position.
# mRel is move relative. mAbs is move absolute (go to position xxx)
Motor1.mRel(1)  # advance 1mm
time.sleep(.5)
Motor1.mRel(-1)  # retract 1mm
Ejemplo n.º 5
0
class widgetAPT(QWidget):
    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()

    def connectAPT(self, pressed):
        if pressed:
            #APT Motor connect
            Serial = int(self.txtSerial.text())
            self._Motor_.setSerialNumber(Serial)
            self._Motor_.initializeHardwareDevice()

            # Success
            self.btnConnect.setStyleSheet("background-color: green")
            self.btnConnect.setText("Connected")

            self.txtSerial.setEnabled(False)
            self.txtPos.setEnabled(True)
            # Update text to show position
            self.txtPos.setValue(self._Motor_.getPos())

            self.txtVel.setEnabled(True)
            _, _, maxVel = self._Motor_.getVelocityParameters()
            self.txtVel.setValue(maxVel)

            return True
        else:
            #APT Motor disconnect
            self._Motor_.cleanUpAPT()
            # Success
            self.btnConnect.setStyleSheet("background-color: grey")
            self.btnConnect.setText("Connect")

            self.txtSerial.setEnabled(True)
            self.txtPos.setEnabled(False)
            self.txtVel.setEnabled(False)
            self.txtPos.setValue(0.0000)
            self.txtPos.setToolTip("Current Motor Position")
            return True

    def motRel(self, relDistance):
        if self.cbBacklash.isChecked():
            self._Motor_.mbRel(relDistance)
        else:
            self._Motor_.mRel(relDistance)
        # Update text to show position
        self.txtPos.setValue(self._Motor_.getPos())

    def motAbs(self, absDistance):
        if self.cbBacklash.isChecked():
            self._Motor_.mbAbs(absDistance)
        else:
            self._Motor_.mAbs(absDistance)
        # Update text to show position
        self.txtPos.setValue(self._Motor_.getPos())
Ejemplo n.º 6
0
class widgetAPT(QWidget):
    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()

    def connectAPT(self, pressed):
        if pressed:
            #APT Motor connect
            Serial = int(self.txtSerial.text())
            self._Motor_.setSerialNumber(Serial)
            self._Motor_.initializeHardwareDevice()

            # Success
            self.btnConnect.setStyleSheet("background-color: green")
            self.btnConnect.setText("Connected")

            self.txtSerial.setEnabled(False)
            self.txtPos.setEnabled(True)
            # Update text to show position
            self.txtPos.setValue( self._Motor_.getPos() )

            self.txtVel.setEnabled(True)
            _, _, maxVel = self._Motor_.getVelocityParameters()
            self.txtVel.setValue( maxVel )

            return True
        else:
            #APT Motor disconnect
            self._Motor_.cleanUpAPT()
            # Success
            self.btnConnect.setStyleSheet("background-color: grey")
            self.btnConnect.setText("Connect")

            self.txtSerial.setEnabled(True)
            self.txtPos.setEnabled(False)
            self.txtVel.setEnabled(False)
            self.txtPos.setValue(0.0000)
            self.txtPos.setToolTip("Current Motor Position")
            return True

    def motRel(self, relDistance):
        if self.cbBacklash.isChecked() :
            self._Motor_.mbRel(relDistance)
        else:
            self._Motor_.mRel(relDistance)
        # Update text to show position
        self.txtPos.setValue( self._Motor_.getPos() )

    def motAbs(self, absDistance):
        if self.cbBacklash.isChecked() :
            self._Motor_.mbAbs(absDistance)
        else:
            self._Motor_.mAbs(absDistance)
        # Update text to show position
        self.txtPos.setValue( self._Motor_.getPos() )
Ejemplo n.º 7
0
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


start = datetime.datetime.now()
motor.cleanUpAPT()
end = datetime.datetime.now()
Ejemplo n.º 8
0
class BBD103():
    """
    Thorlabs USB interface to BBD103 controller for a MLS203 stage
    """
    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"

    ## getStatus
    #
    # @return True/False if we are actually connected to the stage.
    #
    def getStatus(self):
        return self.live

    def goAbsolute(self, x, y):
        x = x * self.um_to_unit
        y = y * self.um_to_unit
        self.Motor1.mAbs(x)  #
        self.Motor2.mAbs(y)  #

    def goRelative(self, x, y):
        x = x * self.um_to_unit
        y = y * self.um_to_unit
        self.Motor1.mRel(x)  #
        self.Motor2.mRel(y)  #

    def jog(self, x_speed,
            y_speed):  # shouldn't this also specify a relative position
        vx = x_speed * self.um_to_unit
        vy = y_speed * self.um_to_unit
        self.Motor1.setVel(x_speed)
        self.Motor2.setVel(y_speed)

    def joystickOnOff(self, on):
        if on:
            self.writeline("!joy 2")
        else:
            self.writeline("!joy 0")

    ## lockout
    #
    # Calls joystickOnOff.
    #
    # @param flag True/False.
    #
    def lockout(self, flag):
        self.joystickOnOff(not flag)

    ## position
    #
    # @return [stage x (um), stage y (um), stage z (um)]
    #
    def position(self):
        if self.live:
            x0 = self.Motor1.getPos()  # query single axis
            y0 = self.Motor2.getPos()  # query single axis
            return {"x": x0, "y": y0}

    def serialNumber(self):
        """
        Return the stages serial number.
        """
        return self.Motor1.getHardwareInformation()

    def setVelocity(self, x_vel, y_vel):
        """
        x_vel - The maximum stage velocity allowed in x.
        y_vel - The maximum stage velocity allowed in y.
        I'm not sure this should be allowed to change the max velocity here. 
        """
        pass

    ## shutDown
    #
    # Disconnect from the stage.
    #
    def shutDown(self):
        # Disconnect from the stage (not sure this is correct)
        if self.live:
            self.Motor1.cleanUpAPT()
            self.Motor2.cleanUpAPT()

    def zero(self):
        pass