def __init__(self, gui, camera, actuator, *args, **kwargs): super().__init__(*args, **kwargs) self.gui = gui self.camera = camera self.actuator = actuator self.locked = False self.standAlone = False self.npoints = 400 # checks image size rawimage = self.camera.latest_frame() image = np.sum(rawimage, axis=2) self.sensorSize = np.array(image.shape) self.focusSignal = 0 # set focus update rate self.scansPerS = 20 self.camera.start_live_video(framerate='20 Hz') self.focusTime = 1000 / self.scansPerS self.focusTimer = QtCore.QTimer() self.focusTimer.timeout.connect(self.update) self.focusTimer.start(self.focusTime) self.currentZ = tools.convert(self.actuator.Get_FPar(52), 'UtoX') self.currentX = tools.convert(self.actuator.Get_FPar(50), 'UtoX') self.currentY = tools.convert(self.actuator.Get_FPar(51), 'UtoX') self.reset()
def getPosition(self): xPos = self.adw.Get_FPar(50) yPos = self.adw.Get_FPar(51) zPos = self.adw.Get_FPar(52) self.xPos = tools.convert(xPos, 'UtoX') self.yPos = tools.convert(yPos, 'UtoX') self.zPos = tools.convert(zPos, 'UtoX')
def actuatorParameters(adwin, z_f, n_pixels_z=50, pixeltime=1000): z_f = tools.convert(z_f, 'XtoU') adwin.Set_Par(23, n_pixels_z) adwin.Set_FPar(25, z_f) adwin.Set_FPar(26, tools.timeToADwin(pixeltime))
def moveToParameters(self, x_f, y_f, z_f, n_pixels_x=128, n_pixels_y=128, n_pixels_z=128, pixeltime=2000): x_f = tools.convert(x_f, 'XtoU') y_f = tools.convert(y_f, 'XtoU') z_f = tools.convert(z_f, 'XtoU') # print(x_f, y_f, z_f) self.adw.Set_Par(21, n_pixels_x) self.adw.Set_Par(22, n_pixels_y) self.adw.Set_Par(23, n_pixels_z) self.adw.Set_FPar(23, x_f) self.adw.Set_FPar(24, y_f) self.adw.Set_FPar(25, z_f) self.adw.Set_FPar(26, tools.timeToADwin(pixeltime))
def __init__(self, gui, adwin, *args, **kwargs): super().__init__(*args, **kwargs) self.gui = gui self.adw = adwin self.edited_scan = True # edited_scan = True --> size of the useful part of the scan # edited_scan = False --> size of the full scan including aux parts self.APDmaxCounts = 5 * 10**6 # 5MHz is max count rate of the P. Elmer APD # Create a timer for the update of the liveview self.viewtimer = QtCore.QTimer() self.viewtimer.timeout.connect(self.updateView) # Counter for the saved images self.imageNumber = 0 # initialize flag for the ADwin process self.flag = 0 # update parameters self.paramChanged() # initialize fpar_50, fpar_51, fpar_52 ADwin position parameters pos_zero = tools.convert(0, 'XtoU') self.adw.Set_FPar(50, pos_zero) self.adw.Set_FPar(51, pos_zero) self.adw.Set_FPar(52, pos_zero) # move to z = 10 µm self.moveTo(0, 0, 10) # initial directory self.initialDir = r'C:\Data'
dropLocation = np.array([0.0, 0.0, 0.0]) wind_vel = 5.36 wind = np.array([ wind_vel * np.cos(np.radians(30)), -wind_vel * np.sin(np.radians(30)), 0.0 ]) test = PayloadPlanner(dropLocation, obstaclesList, boundariesList, boundaryPoly, wind) test.drop_altitude = 41.611332 test.chi_offset = np.pi / 6. test.time_delay = 0.0 test.time_to_open_parachute = 0.5 result = test.plan(wind) test.plot() print(test.NED_release_location) drop2 = convert(40.36350202, -111.9019713, 0.0, 40.36419521, -111.9023111, 41.611332) print("Drop 2:", drop2) difference = (-test.NED_release_location.item(0) - drop2[0], -test.NED_release_location.item(1) - drop2[1]) print(difference) dropLocation = np.array([0.0, 0.0, 0.0]) wind = 2.68 wind = np.array([0.0, 2.68, 0.0]) test = PayloadPlanner(dropLocation, obstaclesList, boundariesList, boundaryPoly, wind) test.drop_altitude = 21.141054 test.chi_offset = 3 * np.pi / 2 test.time_delay = 0.0 test.time_to_open_parachute = 0.5
if __name__ == '__main__': print('Focus lock module running in stand-alone mode') app = QtGui.QApplication([]) cam = uc480.UC480_Camera() DEVICENUMBER = 0x1 adw = ADwin.ADwin(DEVICENUMBER, 1) scan.setupDevice(adw) # initialize fpar_52 (z) ADwin position parameters pos_zero = tools.convert(0, 'XtoU') adw.Set_FPar(52, pos_zero) zMoveTo(adw, 10) win = focusWidget(cam, adw) win.fworker.standAlone = True win.setWindowTitle('Focus lock') win.resize(1500, 500) win.show() app.exec_()
home = [38.146269,-76.428164, 0.0] bd0 = [38.146269,-76.428164, 0.0] bd1 = [38.151625,-76.428683, 0.0] bd2 = [38.151889, -76.431467, 0.0] bd3 = [38.150594, -76.435361, 0.0] bd4 = [38.147567, -76.432342, 0.0] bd5 = [38.144667, -76.432947, 0.0] bd6 = [38.143256, -76.434767, 0.0] bd7 = [38.140464, -76.432636, 0.0] bd8 = [38.140719, -76.426014, 0.0] bd9 = [38.143761, -76.421206, 0.0] bd10 = [38.147347, -76.423211, 0.0] bd11 = [38.146131, -76.426653, 0.0] bd0_m = convert(home[0],home[1],home[2],bd0[0],bd0[1],bd0[2]) bd1_m = convert(home[0],home[1],home[2],bd1[0],bd1[1],bd1[2]) bd2_m = convert(home[0],home[1],home[2],bd2[0],bd2[1],bd2[2]) bd3_m = convert(home[0],home[1],home[2],bd3[0],bd3[1],bd3[2]) bd4_m = convert(home[0],home[1],home[2],bd4[0],bd4[1],bd4[2]) bd5_m = convert(home[0],home[1],home[2],bd5[0],bd5[1],bd5[2]) bd6_m = convert(home[0],home[1],home[2],bd6[0],bd6[1],bd6[2]) bd7_m = convert(home[0],home[1],home[2],bd7[0],bd7[1],bd7[2]) bd8_m = convert(home[0],home[1],home[2],bd8[0],bd8[1],bd8[2]) bd9_m = convert(home[0],home[1],home[2],bd9[0],bd9[1],bd9[2]) bd10_m = convert(home[0],home[1],home[2],bd10[0],bd10[1],bd10[2]) bd11_m = convert(home[0],home[1],home[2],bd11[0],bd11[1],bd11[2]) boundariesList.append(msg_ned(bd0_m[0],bd0_m[1])) boundariesList.append(msg_ned(bd1_m[0],bd1_m[1])) boundariesList.append(msg_ned(bd2_m[0],bd2_m[1]))
def updateDeviceParameters(self): if self.detector == 'APD': self.adw.Set_Par(30, 0) # Digital input (APD) if self.detector == 'photodiode': self.adw.Set_Par(30, 1) # Analog input (photodiode) # select scan type if self.scantype == 'xy': self.adw.Set_FPar(10, 1) self.adw.Set_FPar(11, 2) if self.scantype == 'xz': self.adw.Set_FPar(10, 1) self.adw.Set_FPar(11, 6) if self.scantype == 'yz': self.adw.Set_FPar(10, 2) self.adw.Set_FPar(11, 6) # initial positions x and y self.x_i = self.initialPos[0] self.y_i = self.initialPos[1] self.z_i = self.initialPos[2] self.x_offset = 0 self.y_offset = 0 self.z_offset = 0 # load ADwin parameters self.adw.Set_Par(1, self.tot_pixels) self.data_t_adwin = tools.timeToADwin(self.data_t) self.data_x_adwin = tools.convert(self.data_x, 'XtoU') self.data_y_adwin = tools.convert(self.data_y, 'XtoU') # repeat last element because time array has to have one more # element than position array dt = self.data_t_adwin[-1] - self.data_t_adwin[-2] self.data_t_adwin = np.append(self.data_t_adwin, (self.data_t_adwin[-1] + dt)) # prepare arrays for conversion into ADwin-readable data self.time_range = np.size(self.data_t_adwin) self.space_range = np.size(self.data_x_adwin) self.data_t_adwin = np.array(self.data_t_adwin, dtype='int') self.data_x_adwin = np.array(self.data_x_adwin, dtype='int') self.data_y_adwin = np.array(self.data_y_adwin, dtype='int') self.data_t_adwin = list(self.data_t_adwin) self.data_x_adwin = list(self.data_x_adwin) self.data_y_adwin = list(self.data_y_adwin) self.adw.SetData_Long(self.data_t_adwin, 2, 1, self.time_range) self.adw.SetData_Long(self.data_x_adwin, 3, 1, self.space_range) self.adw.SetData_Long(self.data_y_adwin, 4, 1, self.space_range)
def updateView(self): if self.scantype == 'xy': dy = tools.convert(self.dy, 'ΔXtoU') self.y_offset = int(self.y_offset + dy) self.adw.Set_FPar(2, self.y_offset) if self.scantype == 'xz' or self.scantype == 'yz': dz = tools.convert(self.dz, 'ΔXtoU') self.z_offset = int(self.z_offset + dz) self.adw.Set_FPar(2, self.z_offset) self.lineData = self.lineAcquisition() if self.edited_scan is True: c0 = self.NofAuxPixels c1 = self.NofAuxPixels + self.NofPixels self.lineData_edited = self.lineData[c0:c1] self.image[:, self.NofPixels - 1 - self.i] = self.lineData_edited else: self.image[:, self.NofPixels - 1 - self.i] = self.lineData if self.gui.nodisplayCheckBox.isChecked() is False: # display image after every scanned line self.gui.img.setImage(self.image, autoLevels=False) if self.i < self.NofPixels - 1: self.i = self.i + 1 else: print('Frame ended') if self.acquisitionMode == 'frame': self.frameAcquisitionStop() self.i = 0 self.y_offset = 0 self.z_offset = 0 if self.scantype == 'xy': self.moveTo(self.x_i, self.y_i, self.z_i) if self.scantype == 'xz': self.moveTo(self.x_i, self.y_i + self.scanRange / 2, self.z_i - self.scanRange / 2) if self.scantype == 'yz': self.moveTo(self.x_i + self.scanRange / 2, self.y_i, self.z_i - self.scanRange / 2) self.updateDeviceParameters()