def zero(channel): gf.zero(channel) # Change 'Zeroed' indicator color if channel == 1: app.btnZeroed1.config(bg="#1cb251") elif (channel == 2): app.btnZeroed2.config(bg="#1cb251") elif (channel == 3): app.btnZeroed3.config(bg="#1cb251")
def closeMode(channel): gf.closeLoop(channel) # Change calling button's color to show what mode the piezo controller is in. # #1cb251 is a darkish green if channel == 1: app.btnOLoop1.config(bg="gray") app.btnCLoop1.config(bg="#1cb251") elif channel == 2: app.btnOLoop2.config(bg="gray") app.btnCLoop2.config(bg="#1cb251") elif channel == 3: app.btnOLoop3.config(bg="gray") app.btnCLoop3.config(bg="#1cb251")
def updatePosition(): position_um = gf.getPosition() # The round function is rounding to the nearest thousandth. app.txtPos1.delete(0, Tkinter.END) app.txtPos1.insert(0, str(round(position_um[0], 3))) app.txtPos2.delete(0, Tkinter.END) app.txtPos2.insert(0, str(round(position_um[1], 3))) app.txtPos3.delete(0, Tkinter.END) app.txtPos3.insert(0, str(round(position_um[2], 3))) #print position_um[0] app.after(200, updatePosition)
# Imports for plotting path import matplotlib as mpl from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt #def sphere(x): # print x[0] # print x[1] # print x[2] # print "" # return sum((x[0:])**2.0) #def rosen(x): # return sum(100.0*(x[1:]-x[:-1]**2.0)**2.0 + (1-x[:-1])**2.0) #bnds = ((2,5),(-2,0)) x0 = numpy.array([10, 10]) gf.connect() sleep(3) # Gives piezo enough time to initialize res = minimize(daq.J, x0, method='nelder-mead', options={ 'xatol': 0.2, 'fatol': 10, 'disp': True }) print(res.x) course = daq.getPath() # Plot the course fig = plt.figure() ax = fig.gca(projection='3d')
def setTarget3(): position = float(app.txtTarget3.get()) gf.setPosition(position, 3) app.txtTarget3.delete(0, Tkinter.END) app.txtTarget3.insert(0, "")
def down(step, channel): step = float(step) gf.stepDown(step, channel)
def up(step, channel): step = float(step) gf.stepUp(step, channel)
def on_closing(): gf.disconnect() app.destroy() print "NOTE: \nUntil a bug fix is found, please use the key combination \"Ctrl + C\" to terminate the program.\n"
def initialize(self): self.grid() # CHANNEL LABELS # Channel 1 label self.lblCh1 = Tkinter.Label(self, text="Ch 1:") self.lblCh1.grid(column=0, row=0, rowspan=2, sticky='EW') # Channel 2 Label self.lblCh2 = Tkinter.Label(self, text="Ch 2:") self.lblCh2.grid(column=0, row=2, rowspan=2, sticky='EW') # Channel 3 Label self.lblCh3 = Tkinter.Label(self, text="Ch 3:") self.lblCh3.grid(column=0, row=4, rowspan=2, sticky='EW') # IDENT BUTTONS # Chanel 1 IDENT self.btnId1 = Tkinter.Button(self, text="IDENT", bg="#f4a641", command=lambda: gf.identify(1)) self.btnId1.grid(column=1, row=0, rowspan=2, sticky='EW') # Chanel 2 IDENT self.btnId2 = Tkinter.Button(self, text="IDENT", bg="#f4a641", command=lambda: gf.identify(2)) self.btnId2.grid(column=1, row=2, rowspan=2, sticky='EW') # Chanel 3 IDENT self.btnId3 = Tkinter.Button(self, text="IDENT", bg="#f4a641", command=lambda: gf.identify(3)) self.btnId3.grid(column=1, row=4, rowspan=2, sticky='EW') # POSITION DISPLAY # Chanel 1 Position self.frmPos1 = Tkinter.Frame(self) self.frmPos1.grid(column=2, row=0, rowspan=2, sticky='EW') self.grpPos1 = Tkinter.LabelFrame(self.frmPos1, text="Position (um)", padx=5, pady=5) self.grpPos1.grid(column=0, row=0, sticky='EW') self.txtPos1 = Tkinter.Entry(self.grpPos1, text="this") self.txtPos1.grid(column=0, row=0, sticky='EW') # Chanel 2 Position self.frmPos2 = Tkinter.Frame(self) self.frmPos2.grid(column=2, row=2, rowspan=2, sticky='EW') self.grpPos2 = Tkinter.LabelFrame(self.frmPos2, text="Position (um)", padx=5, pady=5) self.grpPos2.grid(column=0, row=0, sticky='EW') self.txtPos2 = Tkinter.Entry(self.grpPos2) self.txtPos2.grid(column=0, row=0, sticky='EW') # Chanel 3 Position self.frmPos3 = Tkinter.Frame(self) self.frmPos3.grid(column=2, row=4, rowspan=2, sticky='EW') self.grpPos3 = Tkinter.LabelFrame(self.frmPos3, text="Position (um)", padx=5, pady=5) self.grpPos3.grid(column=0, row=0, sticky='EW') self.txtPos3 = Tkinter.Entry(self.grpPos3) self.txtPos3.grid(column=0, row=0, sticky='EW') # LOOP MODE BUTTONS # Chanel 1 Mode self.btnOLoop1 = Tkinter.Button( self, text="Open Loop", bg="gray", command=lambda: openMode(1)) #gf.openLoop1) self.btnOLoop1.grid(column=3, row=0, sticky='SEW') self.btnCLoop1 = Tkinter.Button( self, text="Closed Loop", bg="#1cb251", command=lambda: closeMode(1)) #gf.closeLoop1) self.btnCLoop1.grid(column=3, row=1, sticky='NEW') # Chanel 2 Mode self.btnOLoop2 = Tkinter.Button(self, text="Open Loop", bg="gray", command=lambda: openMode(2)) self.btnOLoop2.grid(column=3, row=2, sticky='SEW') self.btnCLoop2 = Tkinter.Button(self, text="Closed Loop", bg="#1cb251", command=lambda: closeMode(2)) self.btnCLoop2.grid(column=3, row=3, sticky='NEW') # Chanel 3 Mode self.btnOLoop3 = Tkinter.Button(self, text="Open Loop", bg="gray", command=lambda: openMode(3)) self.btnOLoop3.grid(column=3, row=4, sticky='SEW') self.btnCLoop3 = Tkinter.Button(self, text="Closed Loop", bg="#1cb251", command=lambda: closeMode(3)) self.btnCLoop3.grid(column=3, row=5, sticky='NEW') # TARGET VALUE TEXT BOX # Chanel 1 Target self.lblInfo1 = Tkinter.Label(self, text="Range 0.0 to 20 um") self.lblInfo1.grid(column=4, row=0, sticky='SEW') self.txtTarget1 = Tkinter.Entry(self) self.txtTarget1.bind("<Return>", setTargetEvent1) self.txtTarget1.grid(column=4, row=1, sticky='NEW') # Chanel 2 Target self.lblInfo2 = Tkinter.Label(self, text="Range 0.0 to 20 um") self.lblInfo2.grid(column=4, row=2, sticky='SEW') self.txtTarget2 = Tkinter.Entry(self) self.txtTarget2.bind("<Return>", setTargetEvent2) self.txtTarget2.grid(column=4, row=3, sticky='NEW') # Chanel 3 Target self.lblInfo3 = Tkinter.Label(self, text="Range 0.0 to 20 um") self.lblInfo3.grid(column=4, row=4, sticky='SEW') self.txtTarget3 = Tkinter.Entry(self) self.txtTarget3.bind("<Return>", setTargetEvent3) self.txtTarget3.grid(column=4, row=5, sticky='NEW') # SET TARGET BUTTON # Chanel 1 Set Button self.btnSetTarget1 = Tkinter.Button(self, text="SET TARGET", bg="#4286f4", command=setTarget1) self.btnSetTarget1.grid(column=5, row=0, rowspan=2, sticky='EW') # Chanel 2 Set Button self.btnSetTarget2 = Tkinter.Button(self, text="SET TARGET", bg="#4286f4", command=setTarget2) self.btnSetTarget2.grid(column=5, row=2, rowspan=2, sticky='EW') # Chanel 3 Set Button self.btnSetTarget3 = Tkinter.Button(self, text="SET TARGET", bg="#4286f4", command=setTarget3) self.btnSetTarget3.grid(column=5, row=4, rowspan=2, sticky='EW') # STEP SIZE LABEL # Chanel 1 Label self.lblStepSize1 = Tkinter.Label(self, text="STEP\nSIZE") self.lblStepSize1.grid(column=6, row=0, rowspan=2, sticky='EW') # Chanel 2 Label self.lblStepSize2 = Tkinter.Label(self, text="STEP\nSIZE") self.lblStepSize2.grid(column=6, row=2, rowspan=2, sticky='EW') # Chanel 3 Label self.lblStepSize3 = Tkinter.Label(self, text="STEP\nSIZE") self.lblStepSize3.grid(column=6, row=4, rowspan=2, sticky='EW') # STEP VALUE TEXT BOX # Chanel 1 Step self.lblStepInfo1 = Tkinter.Label(self, text="Range 0.005 to 20 um") self.lblStepInfo1.grid(column=7, row=0, sticky='SEW') self.txtStepVal1 = Tkinter.Spinbox(self, from_=.005, to=7.5, increment=.005) self.txtStepVal1.grid(column=7, row=1, sticky='NEW') # Chanel 2 Step self.lblStepInfo2 = Tkinter.Label(self, text="Range 0.005 to 20 um") self.lblStepInfo2.grid(column=7, row=2, sticky='SEW') self.txtStepVal2 = Tkinter.Spinbox(self, from_=.005, to=7.5, increment=.005) self.txtStepVal2.grid(column=7, row=3, sticky='NEW') # Chanel 3 Step self.lblStepInfo3 = Tkinter.Label(self, text="Range 0.005 to 20 um") self.lblStepInfo3.grid(column=7, row=4, sticky='SEW') self.txtStepVal3 = Tkinter.Spinbox(self, from_=.005, to=7.5, increment=.005) self.txtStepVal3.grid(column=7, row=5, sticky='NEW') # STEP BUTTONS # Chanel 1 Mode self.btnStepUp1 = Tkinter.Button( self, text="UP", bg="#1cb251", command=lambda: up(self.txtStepVal1.get(), 1)) self.btnStepUp1.grid(column=8, row=0, sticky='SEW') self.btnStepDown1 = Tkinter.Button( self, text="DOWN", bg="#d83e3e", command=lambda: down(self.txtStepVal1.get(), 1)) self.btnStepDown1.grid(column=8, row=1, sticky='NEW') # Chanel 2 Mode self.btnStepUp2 = Tkinter.Button( self, text="UP", bg="#1cb251", command=lambda: up(self.txtStepVal2.get(), 2)) self.btnStepUp2.grid(column=8, row=2, sticky='SEW') self.btnStepDown2 = Tkinter.Button( self, text="DOWN", bg="#d83e3e", command=lambda: down(self.txtStepVal2.get(), 2)) self.btnStepDown2.grid(column=8, row=3, sticky='NEW') # Chanel 3 Mode self.btnStepUp3 = Tkinter.Button( self, text="UP", bg="#1cb251", command=lambda: up(self.txtStepVal3.get(), 3)) self.btnStepUp3.grid(column=8, row=4, sticky='SEW') self.btnStepDown3 = Tkinter.Button( self, text="DOWN", bg="#d83e3e", command=lambda: down(self.txtStepVal3.get(), 3)) self.btnStepDown3.grid(column=8, row=5, sticky='NEW') # ZERO BUTTONS # Chanel 1 Zeroes self.btnZero1 = Tkinter.Button(self, text="Zero", command=lambda: zero(1)) self.btnZero1.grid(column=9, row=0, sticky='SEW') self.btnZeroed1 = Tkinter.Button(self, text="Zeroed", bg="#1cb251", state="disabled") #bg="gray" self.btnZeroed1.grid(column=9, row=1, sticky='NEW') # Chanel 2 Zeroes self.btnZero2 = Tkinter.Button(self, text="Zero", command=lambda: zero(2)) self.btnZero2.grid(column=9, row=2, sticky='SEW') self.btnZeroed2 = Tkinter.Button(self, text="Zeroed", bg="#1cb251", state="disabled") #bg="gray" self.btnZeroed2.grid(column=9, row=3, sticky='NEW') # Chanel 3 Zeroes self.btnZero3 = Tkinter.Button(self, text="Zero", command=lambda: zero(3)) self.btnZero3.grid(column=9, row=4, sticky='SEW') self.btnZeroed3 = Tkinter.Button(self, text="Zeroed", bg="#1cb251", state="disabled") #bg="gray" self.btnZeroed3.grid(column=9, row=5, sticky='NEW') # STATUS BAR self.statusLbl = Tkinter.Label(self, text="STATUS:") self.statusLbl.grid(column=1, row=6, sticky='W') self.status = Tkinter.Label(self, text="READY") self.status.grid(column=2, row=6, sticky='EW') # OPEN GRAPH BUTTON self.oscopeBtn = Tkinter.Button(self, text="Start Oscilloscope", command=lambda: openScope(self)) self.oscopeBtn.grid(column=3, row=6, sticky='EW') # GRAPH self.fig = plt.figure() self.ax1 = self.fig.add_subplot(1, 1, 1) #self.ani = animation.FuncAnimation(self.fig, animate, interval=20) self.canvas = FigureCanvasTkAgg(self.fig, self) self.canvas.draw() self.canvas.get_tk_widget().grid(column=10, row=0, rowspan=7, sticky='EW')
def __init__(self, parent): gf.connect() Tkinter.Tk.__init__(self, parent) self.parent = parent self.initialize()