def gainscan(idx): gainnum = 1 #where_i_was=acsc.getRPosition(hcomm,0) acsc.toPoint(hcomm, None, 0, gain_z_out_of_beam) # while(abs(acsc.getFVelocity(hcomm, 0))>wait_ms): # 1+1 while (not acsc.getMotorState(hcomm, 0)['in position'] ): #check for stop event using other API call? time.sleep(.1) while (gainnum < num_gain_per_scan): mmc.snapImage() image_npy = mmc.getImage() image_itk = sitk.GetImageFromArray(image_npy) sitk.WriteImage( image_itk, output_dir + "\\gain\\gain_" + str(idx) + "_" + str(gainnum) + ".tiff" ) #Change this to Gainscan_"+str(idx)+".tiff" if you would rather sort by time and not filename dt = datetime.now() micro = dt.microsecond time_temp = time.strftime("%Y%m%d-%H%M%S") + ":" + str(micro) file_output.write("gain_%d\t%f\t%f\t%f\t%s\t%s\t%d\n" % (idx, 0, acsc.getRPosition(hcomm, 1), acsc.getFPosition(hcomm, 1), time_temp, (datetime.now() - startTime), exposure_inpt)) gainnum = gainnum + 1 acsc.toPoint(hcomm, None, 0, where_i_was) # while(abs(acsc.getFVelocity(hcomm, 0))>wait_ms): # 1+1 while (not acsc.getMotorState(hcomm, 0)['in position'] ): #check for stop event using other API call? time.sleep(.1)
def ptp(self, target, coordinates="absolute", wait=acsc.SYNCHRONOUS): """Performs a point to point move in either relative or absolute (default) coordinates.""" if coordinates == "relative": flags = acsc.AMF_RELATIVE else: flags = None acsc.toPoint(self.controller.hc, flags, self.axisno, target, wait)
def on_goPlatform(self): vel = self.ui.velSpinBox.value() acc = self.ui.accSpinBox.value() acsc.setVelocity(self.hcomm, self.axis, vel) acsc.setAcceleration(self.hcomm, self.axis, acc) acsc.setDeceleration(self.hcomm, self.axis, acc) acsc.setJerk(self.hcomm, self.axis, acc*10) acsc.toPoint(self.hcomm, None, self.axis, self.platform)
def autoabort(self): """This should stop everything and return carriage and turbine back to zero.""" self.autoaborted = True acsc.stopBuffer(self.hc, 19) acsc.halt(self.hc, 0) acsc.halt(self.hc, 1) acsc.halt(self.hc, 4) acsc.halt(self.hc, 5) acsc.toPoint(self.hc, None, 4, 0.0) acsc.setVelocity(self.hc, 5, 0.5) acsc.toPoint(self.hc, None, 5, 0.0)
def run(self): """Start the run. Comms should be open already with the controller.""" if acsc.getOutput(self.hc, 1, 16): acsc.setOutput(self.hc, 1, 16, 0) if self.vectrino: acsc.enable(self.hc, 0) acsc.enable(self.hc, 1) while not acsc.getMotorState(self.hc, 0)["enabled"] or not \ acsc.getMotorState(self.hc, 1)["enabled"]: self.msleep(100) acsc.toPoint(self.hc, None, 0, self.y_R * self.R) acsc.toPoint(self.hc, None, 1, self.z_H * self.H) while not acsc.getMotorState(self.hc, 0)["in position"] or not \ acsc.getMotorState(self.hc, 1)["in position"]: self.msleep(300) print("y- and z-axes in position") acsc.disable(self.hc, 0) acsc.disable(self.hc, 1) self.vec.serial_port = "COM2" self.vec.connect() tstart = time.time() self.timeout = False self.vecstatus = "Connecting to Vectrino..." while not self.vec.connected: self.msleep(300) if time.time() - tstart > 10: print("Vectrino timed out") self.timeout = True break if not self.timeout: self.vec.stop() self.setvecconfig() if self.recordvno: self.vec.start_disk_recording(self.vecsavepath) self.vec.start() self.vecstatus = "Vectrino connected " while self.vec.state != "Confirmation mode": self.msleep(100) print("Vectrino in data collection mode") print("Waiting 6 seconds") self.sleep(6) self.daqthread.start() if self.fbg: self.fbgthread.start() self.start_motion() elif self.nidaq: self.daqthread.start() if self.fbg: self.fbgthread.start() self.start_motion() else: # Start motion self.start_motion()
def run(self): """Start the run. Comms should be open already with the controller.""" if acsc.getOutput(self.hc, 1, 16): acsc.setOutput(self.hc, 1, 16, 0) if self.vectrino: acsc.enable(self.hc, 0) acsc.enable(self.hc, 1) while not acsc.getMotorState(self.hc, 0)["enabled"] or not \ acsc.getMotorState(self.hc, 1)["enabled"]: self.msleep(100) acsc.toPoint(self.hc, None, 0, self.y_R*self.R) acsc.toPoint(self.hc, None, 1, self.z_H*self.H) while not acsc.getMotorState(self.hc, 0)["in position"] or not \ acsc.getMotorState(self.hc, 1)["in position"]: self.msleep(300) print("y- and z-axes in position") acsc.disable(self.hc, 0) acsc.disable(self.hc, 1) self.vec.serial_port = "COM2" self.vec.connect() tstart = time.time() self.timeout = False self.vecstatus = "Connecting to Vectrino..." while not self.vec.connected: self.msleep(300) if time.time() - tstart > 10: print("Vectrino timed out") self.timeout = True break if not self.timeout: self.vec.stop() self.setvecconfig() if self.recordvno: self.vec.start_disk_recording(self.vecsavepath) self.vec.start() self.vecstatus = "Vectrino connected " while self.vec.state != "Confirmation mode": self.msleep(100) print("Vectrino in data collection mode") print("Waiting 6 seconds") self.sleep(6) self.daqthread.start() if self.fbg: self.fbgthread.start() self.start_motion() elif self.nidaq: self.daqthread.start() if self.fbg: self.fbgthread.start() self.start_motion() else: # Start motion self.start_motion()
def on_go(self): target = self.ui.posSpinBox.value() vel = self.ui.velSpinBox.value() acc = self.ui.accSpinBox.value() acsc.setVelocity(self.hcomm, self.axis, vel) acsc.setAcceleration(self.hcomm, self.axis, acc) acsc.setDeceleration(self.hcomm, self.axis, acc) acsc.setJerk(self.hcomm, self.axis, acc*10) if self.ui.rbRelative.isChecked() == True: flags = acsc.AMF_RELATIVE else: flags = None acsc.toPoint(self.hcomm, flags, self.axis, target)
def move(self, axis, distance, relative_or_absolute='r'): """ 'r' for relative, 'a' for absolute distance in [mm] """ if relative_or_absolute == 'r': flags = acsc.AMF_RELATIVE else: flags = 0 acsc.getLastError() if not acsc.toPoint(self.hc, flags, axis, float(distance)): print "Transaction error: %d\n" % (acsc.getLastError())
def ptp(self, axis, target, flags=None, wait=acsc.SYNCHRONOUS): if axis in self.axisdefs: axis = self.axisdefs[axis] acsc.toPoint(self.hc, flags, axis, target, wait)
def move_stage(set_degree): acsc.toPoint(hcomm, None, 1, set_degree)
###camera calls### ################## #load in 10k devices if load_camera10k: camefile_path = "C:\\Users\\ChengLab\\Desktop\\MP71Camera\\VP-71MC-M5_P200SC_4tap(H)_12bit_RG (VST Y12).cam" #Actually do the imaging if do_scan: while (not acsc.getMotorState(hcomm, 1)['in position'] ): #check for stop event using other API call? time.sleep(.1) for focal_idx, focal_position in enumerate(focal_step_mtx): projection_fill[focal_idx] = take_photo(1, 1, focal_position) print("projecting at " + str(focal_position)) where_i_was = acsc.getRPosition(hcomm, 0) acsc.toPoint(hcomm, None, 0, gain_z_out_of_beam) while (not acsc.getMotorState(hcomm, 0)['in position'] ): #check for stop event using other API call? time.sleep(.1) if scan_gain: for focal_idx, focal_position in enumerate(focal_step_mtx): gain_fill[focal_idx] = gainscan(1, focal_position) print("projecting at " + str(focal_position)) acsc.toPoint(hcomm, None, 0, where_i_was) while (not acsc.getMotorState(hcomm, 0)['in position'] ): #check for stop event using other API call? time.sleep(.1) if load_stages: while (not acsc.getMotorState(hcomm, 1)['in position']
def initialization(self): print "Waiting for Motorized Stage (ACS) Initialization" self.hc = acsc.openCommEthernetTCP(address="10.0.0.100", port=701) ## craete comminucation acsc.runBuffer(self.hc, 0) acsc.runBuffer(self.hc, 1) acsc.runBuffer(self.hc, 2) acsc.runBuffer(self.hc, 4) acsc.runBuffer(self.hc, 5) acsc.runBuffer(self.hc, 6) time.sleep(30) ## Homing process ## Axis 6 acsc.waitMotionEnd(self.hc, axis=6) ## stop at left limit if acsc.setFPosition(self.hc, axis=6, fposition=0) != 0: print 'Axis 6 (Receiver Z): Homing completed' else: print 'Axis 6 (Receiver Z): Homing failed' ## Axis 0 acsc.waitMotionEnd(self.hc, axis=0) acsc.toPoint(self.hc, flags=acsc.AMF_RELATIVE, axis=0, target=47.5) acsc.waitMotionEnd(self.hc, axis=0) if acsc.setFPosition(self.hc, axis=0, fposition=0) == 1: print 'Axis 0 (Sample X): Homing completed' else: print 'Axis 0 (Sample X): Homing failed' ## Axis 1 acsc.waitMotionEnd(self.hc, axis=1) acsc.toPoint(self.hc, flags=acsc.AMF_RELATIVE, axis=1, target=19.51) acsc.waitMotionEnd(self.hc, axis=1) if acsc.setFPosition(self.hc, axis=1, fposition=0) == 1: print 'Axis 1 (Sample Y): Homing completed' else: print 'Axis 1 (Sample Y): Homing failed' ## Axis 2 acsc.waitMotionEnd(self.hc, axis=2) ## stop at left limit acsc.toPoint(self.hc, flags=0, axis=2, target=2.8915) print 'Axis 2 (Lens array): Homing completed' ## Axis 4 acsc.waitMotionEnd(self.hc, axis=4) ## stop at left limit acsc.toPoint(self.hc, flags=acsc.AMF_RELATIVE, axis=4, target=4.42) acsc.waitMotionEnd(self.hc, axis=4) if acsc.setFPosition(self.hc, axis=4, fposition=0) == 1: print 'Axis 4 (Receiver X): Homing completed' else: print 'Axis 4 (Receiver X): Homing failed' ## Axis5 acsc.waitMotionEnd(self.hc, axis=5) ## stop at left limit acsc.toPoint(self.hc, flags=acsc.AMF_RELATIVE, axis=5, target=23.8) acsc.waitMotionEnd(self.hc, axis=5) if acsc.setFPosition(self.hc, axis=5, fposition=0) == 1: print 'Axis 5 (Receiver Y): Homing completed' else: print 'Axis 5 (Receiver Y): Homing failed' ## parameter setting acsc.setVelocity(self.hc, 0, 30) ## axis 0 (linear X) acsc.setAcceleration(self.hc, 0, 100) acsc.setDeceleration(self.hc, 0, 100) acsc.setJerk(self.hc, 0, 1000) acsc.setVelocity(self.hc, 1, 30) ## axis1 (linear Y) acsc.setAcceleration(self.hc, 1, 100) acsc.setDeceleration(self.hc, 1, 100) acsc.setJerk(self.hc, 1, 1000) acsc.setVelocity(self.hc, 2, 30) ## axis 2 (revolver) acsc.setAcceleration(self.hc, 2, 100) acsc.setDeceleration(self.hc, 2, 100) acsc.setJerk(self.hc, 2, 1000) acsc.setVelocity(self.hc, 4, 30) ## axis4 (step X) acsc.setAcceleration(self.hc, 4, 100) acsc.setDeceleration(self.hc, 4, 100) acsc.setJerk(self.hc, 4, 1000) acsc.setVelocity(self.hc, 5, 30) ## axis 5 (step Y) acsc.setAcceleration(self.hc, 5, 100) acsc.setDeceleration(self.hc, 5, 100) acsc.setJerk(self.hc, 5, 1000) acsc.setVelocity(self.hc, 6, 5) ## axis 6 (step Z) acsc.setAcceleration(self.hc, 6, 50) acsc.setDeceleration(self.hc, 6, 50) acsc.setJerk(self.hc, 1, 100)
print(device_id) mmc.setExposure(exposure_inpt) mmc.setProperty(device_id, "Binning", binning_value) print(mmc.getProperty(device_id, "Binning")) os.chdir(prev_dir) ################## ####stage calls### ################## if load_stages: #initiate connection hcomm = acsc.openCommEthernetTCP(address="10.0.0.100", port=701) #z if scan_gain: acsc.enable(hcomm, 0) acsc.toPoint(hcomm, None, 0, 110) #YIFU CHECK THIS acsc.setVelocity(hcomm, 0, 5) #velocity in mm/sec #theta acsc.enable(hcomm, 1) acsc.setVelocity(hcomm, 1, 10) #velocity in degrees/sec acsc.setJerk(hcomm, 1, 500) #jerk, normal is 9000 acsc.setDeceleration(hcomm, 1, 450) #jerk, normal is 9000 acsc.setAcceleration(hcomm, 1, 450) #Acceleration, normal is 9000 acsc.toPoint(hcomm, None, 1, 0) #Actually do the imaging if do_scan: for idx in range(degrees_array.shape[0]): q = time.time() set_degree = degrees_array[idx] move_stage(degrees_array[idx])