def start_nr360s(): print(apt.list_available_devices()) motorNo = apt.list_available_devices()[2][1] motor = apt.Motor(motorNo) # Set the Hardware Limit Switches # - Limit switch is activated when electrical # continuity is broken in the reverse direction # - No Limit Switch in forward direction for NR360S motor.set_hardware_limit_switches(rev=3, fwd=1) motor.set_motor_parameters(steps_per_rev=200, gear_box_ratio=1) # Set Stage Info # - Min and Max pos limited to 0 and 360 degrees # - units = mm # - pitch = 5.4546 (from device manual) motor.set_stage_axis_info(min_pos=0.0, max_pos=360.0, units=1, pitch=5.4546) # Set Homing Parameters # - Homing direction is reverse # - Limit Switch is reverse motor.set_move_home_parameters(direction=2, lim_switch=1, velocity=6, zero_offset=0.6) motor.set_velocity_parameters(min_vel=0.0, accn=2.7, max_vel=5.4545) return motor
def __init__(self, name=None, settings=None): super(KDC101, self).__init__(name, settings) list_apt_devices = apt.list_available_devices() if self.settings['serial_number'] in [ list_apt_devices[l][1] for l in range(len(list_apt_devices)) ]: print('KDC101 harware info:') print(apt.hardware_info(self.settings['serial_number'])) self.azimuth = apt.Motor(self.settings['serial_number']) self.azimuth.set_stage_axis_info(0, 360, 2, 7.5) print('stage info:') print(self.azimuth.get_stage_axis_info()) self.azimuth.set_hardware_limit_switches(1, 1) print("hardware limit switches") print(self.azimuth.get_hardware_limit_switches()) else: print('apt devices available:') print(list_apt_devices) raise EnvironmentError("Device with serial=" + str(self.settings['serial_number']) + ' not found')
def init_thorlabs(blocking=True): thor_lab_address1 = apt.list_available_devices() #if not working using the value from thor_lab_address1 motor = apt.Motor(94876441) motor.move_home(blocking) motor.set_move_home_parameters(*motor.get_move_home_parameters()) motor.set_velocity_parameters(*motor.get_velocity_parameters()) return motor
def connect_to_2motors(): try: print("Available Motors: ", apt.list_available_devices()) Mx = apt.Motor(27003942) My = apt.Motor(27003941) except: print("Unable to connect") return False, False return Mx, My
def connect_to_3motors(): try: print("Available Motors: ", apt.list_available_devices()) Mx = apt.Motor(27003941) My = apt.Motor(27003942) Mz = apt.Motor(27003952) except: print("Unable to connect") return None, None, None return Mx, My, Mz
def HardPull(self): elements = apt.list_available_devices() serials = [x[1] for x in elements] serial1 = serials[0] serial2 = serials[1] print(elements) motor1 = apt.Motor(serial1) motor2 = apt.Motor(serial2) motor1.move_home() motor2.move_home(True) print("homed") time.sleep(2) motor1.move_to(50) motor2.move_to(50, True) print("ready") input("Press any key to start pulling") print("pulling") motor1.move_velocity(0.2) motor1.move_to(20) motor2.move_velocity(0.2) motor2.move_to(20) t0 = time.time() while True: t1 = time.time() t = t1 - t0 self.xs.append(t) self.ys.append(self.pmd.power.magnitude * 1000) values = { 'x': self.xs, 'y': self.ys, } self.HardPull.acquire(values) sleep(0.5) if len(xs) < 10: continue else: tail = ys[-10:] maxi = max(tail) mini = min(tail) variance = maxi - mini if variance < 0.001 and t > 20: self.gpd.set_voltage(12) self.gpd.set_output(1) sleep(2) self.gpd.set_output(0) break return
def get_devices(): """ Get the thorlabs hardware stages that can be used with LinearAxis and RotateAxis in a tuple (human readable name, serial number) """ serial_numbers = thorlabs_apt.list_available_devices() devices = [] for number in serial_numbers: info = thorlabs_apt.hardware_info(number[1]) devices.append(("{} {} S/N: {}".format(info[2].decode("utf - 8"), info[0].decode("utf - 8"), number[1]), number[1])) return devices
def start_measure(self): ## What happens when you click "start" ## self.start.setEnabled(False) self.stop.setEnabled(True) self.scan_type = self.scan_type_combo.currentIndex() #0 = Fast, 1=Slow self.counter = nidaqmx.Task() self.counter.ci_channels.add_ci_pulse_width_chan( 'Dev1/ctr0', units=nidaqmx.constants.TimeUnits.TICKS) self.counter.channels.ci_ctr_timebase_src = '/Dev1/PFI8' self.counter.start() if self.scan_type == 0: self.time_bin = self.time_line / self.N_scan N_bin = int(self.time_bin * self.freq_gate) signal = (N_bin * [True] + [False]) * self.N_scan elif self.scan_type == 1: signal = [True] * int(self.time_PL * self.freq_gate / 1000) + [ False ] self.gate = nidaqmx.Task() self.gate.do_channels.add_do_chan('Dev1/port0/line7') self.gate.timing.cfg_samp_clk_timing( self.freq_gate, sample_mode=nidaqmx.constants.AcquisitionType.CONTINUOUS) self.gate.write(signal) ml = apt.list_available_devices() #ml=[(31, 27254827), (31, 27255158)] self.motor_chosen = self.motor_choice.currentIndex() if self.motor_chosen == 1: self.motor = apt.Motor(ml[0][1]) if self.motor_chosen == 0: self.motor = apt.Motor(ml[1][1]) self.index = 0 self.repeat = 1. self.y = np.zeros(self.N_scan) #Start the timer self.timer = QTimer(self, interval=0) if self.scan_type == 0: self.timer.timeout.connect(self.take_line) elif self.scan_type == 1: self.timer.timeout.connect(self.take_point) self.dead_time = False # Pour afficher à chaque fois... self.timer.start()
def __init__(self, spec): self.spec = spec # print(spec) devices = apt.list_available_devices() # print(devices) nr_devices = len(devices) if nr_devices == 0: print( "Not recognised a device. Unplug USB and try again. Use APT user to check if device shows up." ) else: dev_snr = devices[0][1] self.device = apt.Motor(dev_snr) self.operations = spec.get('operations', {})
def apt_device_check(serial_num): """Checks if the given serial number is a valid APT device serial. Parameters: serial_num: int The serial number which is going to be verified. Returns: True if it is a valid device serial, False if it is not valid. """ device_list = aptlib.list_available_devices() for i in range(0, len(device_list), 1): if serial_num == device_list[i][1] and device_list[i][0] == 31: return True return False
def __init__(self, x_serial=27504145, y_serial=27504197, z_serial=27504259, min_pos=0, max_pos=0): devices = [d[1] for d in apt.list_available_devices()] assert x_serial in devices assert y_serial in devices assert z_serial in devices self.x_motor = apt.Motor(x_serial) self.y_motor = apt.Motor(y_serial) self.z_motor = apt.Motor(z_serial) # we are going to assume that all motors are the same model, all units in mm self.max_z_pos = 11 self.min_z_pos = 9 self.min_x_pos = 10 self.max_x_pos = 30 self.min_y_pos = 10 self.max_y_pos = 30 self.min_pos = min_pos self.max_pos = max_pos
def __init__(self, opts): self.out_task_0 = ni.Task() self.out_task_0.do_channels.add_do_chan('cDAQ1Mod1/port0/line0:7', line_grouping=LineGrouping.CHAN_PER_LINE) # self.writer_0 = ni.stream_writers.DigitalMultiChannelWriter(self.out_task_0.out_stream) self.out_task_0.start() # self.out_tasks = [self.out_task_0] self.out_tasks = {'main': self.out_task_0} if opts.n_daq == 2: # if using a box with 2-Daq setup self.out_task_1 = ni.Task() self.out_task_1.do_channels.add_do_chan('cDAQ2Mod1/port0/line0:1', line_grouping=LineGrouping.CHAN_PER_LINE) # self.writer_1 = ni.stream_writers.DigitalMultiChannelWriter(self.out_task_1.out_stream) self.out_task_1.start() # self.out_tasks.append(self.out_task_1) self.out_tasks['cd'] = self.out_task_1 self.in_task = ni.Task() self.in_task.di_channels.add_di_chan('Dev1/port0/line0:1', line_grouping=LineGrouping.CHAN_PER_LINE) self.reader = ni.stream_readers.DigitalMultiChannelReader(self.in_task.in_stream) self.in_task.start() # Writer for error noise self.dev_out_task_0 = ni.Task() self.dev_out_task_0.do_channels.add_do_chan('Dev1/port1/line1', line_grouping=LineGrouping.CHAN_PER_LINE) self.dev_writer_0 = ni.stream_writers.DigitalMultiChannelWriter(self.dev_out_task_0.out_stream) self.dev_out_task_0.start() self.out_tasks['dev'] = self.dev_out_task_0 # MOTOR # if not opts.testing: devices = apt.list_available_devices() motor_0 = apt.Motor(devices[0][1]) # lr motor self.motors = [motor_0] self.forward_motor_step = 10 self.sideways_motor_step = .8 if opts.forward_moving_ports: # print(devices) motor_1 = apt.Motor(devices[1][1]) # forward motor param = motor_1.get_velocity_parameters() motor_1.set_velocity_parameters(param[0], 1e3, 200) self.motors.append(motor_1)
def __initialize_stages(): global __cntrl_x global __cntrl_y global __cntrl_z # get current device lists devices = apt.list_available_devices() # SNs of the KDC101 devices x_stage = 27002265 y_stage = 27002165 z_stage = 27002158 # initialize the motor controllers __cntrl_x = apt.Motor(x_stage) __cntrl_y = apt.Motor(y_stage) __cntrl_z = apt.Motor(z_stage) print('Stages are initialized...') # default positions of x,y, and z all in microns x_pos = 5 y_pos = 5 z_pos = 5 # homing print('Homing is started...') __cntrl_x.move_home() time.sleep(1) # pause 5 to homing __cntrl_y.move_home() time.sleep(1) # pause 5 to homing __cntrl_z.move_home() time.sleep(20) # pause 5 to homing print('Homing is finished...') # go to home positions # print('Going to default positions...') # __cntrl_x.move_to(x_pos) # time.sleep(1) # __cntrl_y.move_to(y_pos) # time.sleep(1) # __cntrl_z.move_to(z_pos) # time.sleep(20) # pause 5 to homing print('Stages are ready...')
import thorlabs_apt as apt #Prend qq secondes pour importer les données moteur import time ml = apt.list_available_devices() #ml=[(31, 27254827), (31, 27255158)] motor1 = apt.Motor(ml[0][1]) motor2 = apt.Motor(ml[1][1]) #motor1.move_home(True) # Bloquant par defaut #motor1.move_to(0,blocking = False) # Lorsque non bloquant (le programe rend la main avant que le moteur ait finit de bouger), l'ordre le plus récent remplace le précédent #time.sleep(1) #motor1.move_to(5,blocking = False)
def Pull(self): #os.system('python process.py') # display motors and assign them to Motor objects import thorlabs_apt as apt elements = apt.list_available_devices() serials = [x[1] for x in elements] serial1 = serials[0] serial2 = serials[1] print('\n') print("Present motor devices:", elements, '\n') motor1 = apt.Motor(serial1) motor2 = apt.Motor(serial2) # home motors print("Motor 1 homing parameters:", motor1.get_move_home_parameters()) print("Motor 2 homing parameters:", motor2.get_move_home_parameters()) motor1.move_home() motor2.move_home() print("Homing...\n") while (not motor1.has_homing_been_completed or not motor2.has_homing_been_completed): continue time.sleep(1) input("Press any key to start readying") # ready motors and then pull on user input print("Motor 1 velocity parameters:", motor1.get_velocity_parameters()) print("Motor 2 velocity parameters:", motor2.get_velocity_parameters()) motor1.move_to(20) motor2.move_to(20) print("Readying...\n") while (motor1.is_in_motion or motor2.is_in_motion): continue time.sleep(1) input("Press any key to start pulling") # pull print("Pulling...\n") motor1.set_velocity_parameters(0, 0.01, 0.05) #(minimum_velocity, acceleration, maximum_velocity) in mm motor2.set_velocity_parameters(0, 0.01, 0.05) motor1.move_velocity(2) motor1.move_to(10) # move to relative/absolute position motor2.move_velocity(2) motor2.move_to(10) #input("Press any key to stop pulling") #motor1.stop_profiled() #motor2.stop_profiled() #print("motors have stopped") t0 = time.time() print("Press Enter to stop") while True: t1 = time.time() t = t1 - t0 self.xs.append(t) self.ys.append(self.pmd.power.magnitude * 1000) while len(self.xs) != len(self.ys): del self.xs[-1] if len(self.xs) < len(self.ys): offset=len(self.xs)-len(self.ys) self.ys = self.ys[offset] if len(self.xs) > len(self.ys): offset=len(self.ys)-len(self.xs) self.xs= self.xs[offset] values = { 'x': self.xs, 'y': self.ys, } if msvcrt.kbhit(): if msvcrt.getwche() == '\r': motor1.stop_profiled() motor2.stop_profiled() print("motors have stopped") break self.Pull.acquire(values) time.sleep(0.1) return
import thorlabs_apt as apt import time # display motors and assign them to Motor objects elements = apt.list_available_devices() serials = [x[1] for x in elements] serial1 = serials[0] serial2 = serials[1] print('\n') print("Present motor devices:", elements, '\n') motor1 = apt.Motor(serial1) motor2 = apt.Motor(serial2) # home motors print("Motor 1 homing parameters:", motor1.get_move_home_parameters()) print("Motor 2 homing parameters:", motor2.get_move_home_parameters()) motor1.move_home() motor2.move_home() print("Homing...\n") while (not motor1.has_homing_been_completed or not motor2.has_homing_been_completed): continue time.sleep(1) input("Press any key to start readying") # ready motors and then pull on user input print("Motor 1 velocity parameters:", motor1.get_velocity_parameters()) print("Motor 2 velocity parameters:", motor2.get_velocity_parameters()) motor1.move_to(40)
def __init__(self): super().__init__() self.available = {sn for _, sn in apt.list_available_devices()} self.connected = {}
Mx.move_by(dx) My.move_by(dy) Mz.move_by(dz) while True: if round(Mx.position,4) == x and round(My.position,4) == y and round(Mz.position,4) == z: print("motorX pos: ", Mx.position, " Motor Y pos: ",My.position, " Motor Z pos: ",Mz.position) time.sleep(0.1) # in sec break print('reached ',x,y,z) ########################################### MOVING = None try: print("Available Motors: ",apt.list_available_devices()) Mx = apt.Motor(27003942) My = apt.Motor(27003941) Mz = apt.Motor(27003952) print("HOMING...") Mx.move_home() My.move_home() Mz.move_home() while True: if Mx.has_homing_been_completed and (My.has_homing_been_completed) and (Mz.has_homing_been_completed): Mx.disable() My.disable() Mz.disable() time.sleep (0.1) #in sec Mx.enable() My.enable()
def start_measure(self): ## What happens when you click "start" ## self.scan_type = self.scan_type_combo.currentIndex() #0 = Fast, 1=Slow qf = QFileDialog.getSaveFileName( self, 'Sava data', 'D:/DATA', "Data files (*.txt *.csv)") # return ("path/to/file", "data type") self.fname = qf[0] if not self.fname: return 0 self.start.setEnabled(False) self.stop.setEnabled(True) self.f = open(self.fname, 'w') self.n_iter = 1. self.counter = nidaqmx.Task() self.counter.ci_channels.add_ci_pulse_width_chan( 'Dev1/ctr0', units=nidaqmx.constants.TimeUnits.TICKS) self.counter.channels.ci_ctr_timebase_src = '/Dev1/PFI8' self.counter.start() if self.scan_type == 0: self.time_bin = self.time_line / self.n_pxl_x N_bin = int(self.time_bin * self.freq_gate) signal = (N_bin * [True] + [False]) * self.n_pxl_x elif self.scan_type == 1: signal = [True] * int(self.time_PL * self.freq_gate / 1000) + [ False ] self.gate = nidaqmx.Task() self.gate.do_channels.add_do_chan('Dev1/port0/line7') self.gate.timing.cfg_samp_clk_timing( self.freq_gate, sample_mode=nidaqmx.constants.AcquisitionType.CONTINUOUS) self.gate.write(signal) if self.scan_type == 0: PL_line = self.measure_line() PL = sum(PL_line) / len(PL_line) elif self.scan_type == 1: PL = self.measure_PL() self.xy = np.ones((self.n_pxl_x, self.n_pxl_y)) * PL ml = apt.list_available_devices() #ml=[(31, 27254827), (31, 27255158)] self.motorX = apt.Motor(ml[1][1]) self.motorY = apt.Motor(ml[0][1]) self.x_list = np.linspace(self.xrange[0], self.xrange[1], self.n_pxl_x) self.y_list = np.linspace(self.yrange[0], self.yrange[1], self.n_pxl_y) self.x_index = 0 self.y_index = 0 self.motorX.move_to(self.x_list[self.x_index], blocking=True) self.motorY.move_to(self.y_list[self.y_index], blocking=True) #Start the timer self.timer = QTimer(self, interval=0) if self.scan_type == 0: self.timer.timeout.connect(self.take_line) elif self.scan_type == 1: self.timer.timeout.connect(self.take_point) self.dead_time = False # Pour afficher à chaque fois... self.timer.start()
from PyQt5 import QtCore, QtGui, QtWidgets import thorlabs_apt as apt apt.list_available_devices() import SynradLaser import sys import numpy as np import threading import winsound import ui import math class Worker(QtCore.QRunnable): def __init__(self, fn, *args, **kwargs): super(Worker, self).__init__() # Store constructor arguments (re-used for processing) self.fn = fn self.args = args self.kwargs = kwargs def run(self): self.fn(*self.args, **self.kwargs) class Ui_MainWindow(object): threadpool = QtCore.QThreadPool() isNotStarted = threading.Event()
Install thorlabs_apt using setup.py Check whether your python is a 32 bit or 64 bit version and install the corresponding Thorlabs' APT software Copy APT.dll from the "APT installation path APT Server" directory to one of the following locations: Windows System32 into the "thorlabs_apt" folder your python application directory ''' #Also add "from ctypes import util" to the thorlabs_apt core.py ###### import thorlabs_apt as apt motor_list = apt.list_available_devices() motor_1 = apt.Motor(motor_list[0][1]) motor_2 = apt.Motor(motor_list[1][1]) #home both motor_1.move_home(True) motor_2.move_home(True) motor_1.move_by(5) motor_2.move_by(5)
import thorlabs_apt as apt print(apt.list_available_devices()) motorX = apt.Motor(27003942) motorY = apt.Motor(27003941) Vmax = 2.29 motorX.move_to(5, True) motorY.move_to(5, True) motorX.move_home() motorY.move_home() while not (motorX.has_homing_been_completed) and not ( motorY.has_homing_been_completed): pass print("X & Y homed") ##print(motor.get_velocity_parameters()) ##print("TEST") ##motor.move_home(True) ##print("done") ##print(motor.has_homing_been_completed) ##motor.move_to(5) ''' def hardware_info(self): is_in_motion(self): move_to(self, value, blocking = False) move_by(self, value, blocking = False) def get_stage_axis_info(self):
Steps per revolution = 512 Gearbox Ratio = 67 DC Servo Settings DC Servo Enabled = 1 DC Proportional Constant = 435 DC Integral Constant = 195 DC Differential Constant = 993 DC Integral Limit = 195 ''' import thorlabs_apt as apt import time motorNo = apt.list_available_devices()[0][1] motor = apt.Motor(motorNo) motor.set_hardware_limit_switches(2, 2) motor.set_motor_parameters(512, 67) motor.set_stage_axis_info(0.0, 25.0, 1, 1.0) motor.set_move_home_parameters(2, 1, 2.3, 0.3) motor.set_velocity_parameters(1.5, 3.5, 2.3) # Maximum Velocity = 2.6 # Maximum Acceleration = 4 # home: motor.move_home() time.sleep(1) wait_completion_1 = True