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 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 stagesButtonClicked(self): global motor1 global motor2 try: motor1 = apt.Motor(90864300) motor2 = apt.Motor(90864301) motor1.set_move_home_parameters(2, 1, 5.0, 0.0001) motor2.set_move_home_parameters(2, 1, 5.0, 0.0001) self.logText('Stages connected successfully') except: self.logWarningText(str(sys.exc_info()[1]))
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 __init__(self, xMotorAddress=45992790, yMotorAddress=45951900): self.x = apt.Motor(xMotorAddress) self.y = apt.Motor(yMotorAddress) self.position = (self.x.position, self.y.position) self.x.enable() self.y.enable() if self.x.has_homing_been_completed and self.y.has_homing_been_completed: self.__homed = True else: self.__homed = False
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, 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 serial_entry(self, evt): """Verifies serial input and initialises the motor if possible. Called on data entry into the serial number field. Verifies the entered serial and gives a warning if it is not valid. If it is valid, initialises `apt_motor` with the serial, sets `serial` to be the serial input which was validated, and uses the `apt_motor_init` flag to state the motor was initialised. Parameters ---------- evt : wx.Event The source event which called the method. """ # Don't attempt to verify if the entry is not 8 digits if self.get_serial() < 10000000: return # Disable the UI while blocking is occurring self.disable_ui() if apt_device_check(self.get_serial()) is False: serial_warn() self.enable_ui() return global serial serial = self.get_serial() global apt_motor apt_motor = aptlib.Motor(serial) apt_motor.enable() global apt_motor_init apt_motor_init = True self.enable_ui()
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 _update_stage(self, _): if not self._widget.device_list.value is None and self._widget.device_list.value != 'None': self._rotation_stage = thorlabs_apt.Motor( self._widget.device_list.value) self._rotation_stage.identify() self._value = self.get_current_value() if not self._rotation_stage.has_homing_been_completed: self.goto_home()
def _update_stage(self, _): device = self._widget.device_list.value if device is not None and device != 'None': self._linear_stage = thorlabs_apt.Motor(device) self._linear_stage.identify() self._value = self.get_current_value() if not self._linear_stage.has_homing_been_completed: self.goto_home()
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 __init__(self, serial, name=None): self.name = name self.serial = serial self.motor = apt.Motor(serial) self.motor.set_hardware_limit_switches(2, 2) self.motor.set_motor_parameters(512, 67) self.motor.set_stage_axis_info(0.0, 25.0, 1, 1.0) self.motor.set_move_home_parameters(2, 1, 2.3, 0.3) self.motor.set_velocity_parameters(1.0, 1.0, 1.0)
def command_connect(self, sn): try: sn = int(sn) motor = apt.Motor(sn) self.connected[sn] = motor except Exception: return None, 'failed to connect (invalid sn?)' return None, None
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 __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...')
def SearchForThorLabs(self, SN): import thorlabs_apt as apt try: self.ThorLabs = apt.Motor(SN) return self.ThorLabs except: self.ThorLabs = None
def connect(self): if self.connected: return try: import thorlabs_apt as apt self._motor = apt.Motor(self._port) if self._zero is None: self._zero = self._motor.position except: pass
def __init__(self, xStageSN='27003853', yStageSN='27003868' ): # should become a parameter, see other stages print(['Serial numbers x-stage ', xStageSN, ' y-stage ', yStageSN]) self.motorX = apt.Motor(xStageSN) self.motorY = apt.Motor(yStageSN) self.wait = 1 # move commands wait for motion to stop self.unit_to_um = 1000.0 # controller reports in mm self.um_to_unit = 1.0 / self.unit_to_um # # we used the for the memory free KDC controllers # self.motorX.set_stage_axis_info(-25,25,1,1.0) # self.motorY.set_stage_axis_info(-25,25,1,1.0) self.motorX.set_stage_axis_info(-250, 250, 1, 1.0) self.motorY.set_stage_axis_info(-250, 250, 1, 1.0) # Connect to the stage. self.good = 1
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', {})
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)
@author: khart """ import thorlabs_apt as apt from flirpy.camera.boson import Boson import matplotlib.pyplot as plt import cv2 import numpy as np import time import h5py """options for measurement""" name = "dark" save_path = 'C:\\Users\\khart\\Documents\\IRCAM_data\\jun032021\\' #SET UP MOTOR motor = apt.Motor(83830277) #set velocity parameters to be maximum [minv, a, v] = motor.get_velocity_parameters() [maxa, maxv] = motor.get_velocity_parameter_limits() motor.set_velocity_parameters(minv, maxa, maxv) motor.move_home(True) #initialize camera camera = Boson(port='COM4') camera.set_ffc_manual() wait = 5 frames = 100
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)
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):
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 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
ip_xcross = 10 channel = 0 motor_1_ID = 27504591 motor_2_ID = 27504633 hist_len_code = 6 #### ###Initialise devices### hh = HH.HydraHarp(hh_dev_no) hh.initialise(0, 0) hh.calibrate() hh.set_histo_length(hist_len_code) hh.set_sync_cfd(sync_level, sync_xcross) hh.set_input_cfd(channel, ip_level, ip_xcross) motor_x = apt.Motor(motor_1_ID) motor_y = apt.Motor(motor_2_ID) motor_x.move_home(True) motor_y.move_home(True) #### ###move and take data### x_points = tgt_area_width / inter_dwell_dist y_points = tgt_area_height / inter_dwell_dist x_pos = 0 y_pos = 0 while y_pos < y_points: while x_pos < x_points: hh.start_meas(dwell_time) hh.CTC_status() while hh.ctcStatus.value == 0:
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 import numpy as np motorTorch = apt.Motor( 27003356) #serial number of the stage with the torch on it motorLeft = apt.Motor(27003323) #serial number of the left stage motorRight = apt.Motor(27003363) #serial number of the right stage # Maximum Velocity = 2.6 # Maximum Acceleration = 4 motorTorch.set_hardware_limit_switches(2, 2) motorTorch.set_motor_parameters(512, 67) motorTorch.set_stage_axis_info(0.0, 25.0, 1, 1.0) motorTorch.set_move_home_parameters(2, 1, 2.3, 0.3) motorTorch.set_velocity_parameters(1.0, 1.0, 1.0) # min, acceleration, max ---mm/s/s motorLeft.set_hardware_limit_switches(2, 2) motorLeft.set_motor_parameters(512, 67) motorLeft.set_stage_axis_info(0.0, 25.0, 1, 1.0)
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() Mz.enable()