예제 #1
0
class Window(QtWidgets.QMainWindow):
    #only way I found to get keypressed working
    def __init__(self):
        super(Window, self).__init__()
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)
        #PMA Setup, mostly copied from the file-based motion control
        try:
            USB_DEVICE = 'COM6'
            ZABER_ASCII_PORT = AsciiSerial(USB_DEVICE)
            print("NUTS!")
            self.torch_output = 1
            self.wire_output = 2
            self.iodev = AsciiDevice(
                ZABER_ASCII_PORT, 1)  #additional xy dev created to deal w/ io
            self.xdev = AsciiDevice(ZABER_ASCII_PORT, 1).axis(1)
            self.ydev = AsciiDevice(ZABER_ASCII_PORT, 1).axis(2)
            self.zdev = AsciiDevice(ZABER_ASCII_PORT, 2)
            self.number_devices = 2
            self.xdev.home()
            self.ydev.home()
            self.zdev.home()
            self.cm = 2016
        except:
            print("No Connection!!")

    #wasd control not working currently, leaving it here
    def keyPressEvent(self, e):
        print("key press")
        if e.key() == QtCore.Qt.Key_W:
            print('+y')
            reply = self.ydev.move_rel(self.cm)
        elif e.key() == QtCore.Qt.Key_S:
            print('-y')
            reply = self.ydev.move_rel(-self.cm)
        elif e.key() == QtCore.Qt.Key_A:
            print('+x')
            reply = self.xdev.move_rel(self.cm)
        elif e.key() == QtCore.Qt.Key_D:
            print('-x')
            reply = self.xdev.move_rel(-self.cm)
        elif e.key() == QtCore.Qt.Key_Up:
            print('+z')
            reply = self.zdev.move_rel(self.cm)
        elif e.key() == QtCore.Qt.Key_Down:
            print('-z')
            reply = self.zdev.move_rel(-self.cm)

    def keyReleaseEvent(self, e):
        print("key release")
        if e.key() == QtCore.Qt.Key_W:
            print('0y')
        elif e.key() == QtCore.Qt.Key_S:
            print('0y')
        elif e.key() == QtCore.Qt.Key_A:
            print('0x')
        elif e.key() == QtCore.Qt.Key_D:
            print('0x')
        elif e.key() == QtCore.Qt.Key_Up:
            print('0z')
        elif e.key() == QtCore.Qt.Key_Down:
            print('0z')
예제 #2
0
class Zaber_lin_stage(Instrument):
    '''
        None
    '''
    def __init__(self, name, device_number=1):
        '''
           None
        '''
        logging.info(__name__ +
                     ' : Initializing instrument Zaber Linear Stage')
        Instrument.__init__(self, name, tags=['physical'])

        self.add_parameter('position',
                           units='',
                           type=types.IntType,
                           flags=Instrument.FLAG_GETSET +
                           Instrument.FLAG_GET_AFTER_SET)

        self.add_parameter('device_number',
                           flags=Instrument.FLAG_GET,
                           type=types.StringType)

        self._device_number = device_number
        self.step_to_mm = 0.047625e-3

        self.client = AsciiDevice(AsciiSerial("COM4"), device_number)

    def poll_until_idle(self):
        reply = self.client.poll_until_idle()

    def home(self):
        reply = self.client.home()

    def move_rel(self, distance, blocking=True):
        reply = self.client.move_rel(distance, blocking)

    def move_rel_mm(self, distance, blocking=True):
        reply = self.client.move_rel(int(distance / self.step_to_mm), blocking)

    def move_abs(self, position, blocking=True):
        reply = self.client.move_abs(position, blocking)

    def move_abs_mm(self, position, blocking=True):
        reply = self.client.move_abs(int(position / self.step_to_mm), blocking)

    def move_vel(self, speed, blocking=False):
        reply = self.client.move_vel(speed, blocking)

    def move_vel_distance(self, vel, distance):
        x0 = self.client.get_position()
        speed = int(vel / self.step_to_mm)
        d = int(distance / self.step_to_mm)
        reply = self.client.move_vel(vel)
        while (1):
            x = self.client.get_position()
            if (abs(x - x0) > d):
                self.client.stop()
                breaktnm

    def stop(self):
        reply = self.client.stop()

    def current_status(self):
        reply = self.client.get_status()

    def current_position(self):
        reply = self.client.get_position()
        return reply