diff options
author | Eugeniy E. Mikhailov <evgmik@gmail.com> | 2021-04-03 14:12:59 -0400 |
---|---|---|
committer | Eugeniy E. Mikhailov <evgmik@gmail.com> | 2021-04-03 14:12:59 -0400 |
commit | d6f1eb673968b6fed86b179b887e3d4f3681dd9f (patch) | |
tree | 43598ea00e13eaa2d96eb59bb7c94df476cf5b5c | |
parent | e1ef103a8bda50cc26348cbbb672467f5dfb6964 (diff) | |
download | pyExpControl-d6f1eb673968b6fed86b179b887e3d4f3681dd9f.tar.gz pyExpControl-d6f1eb673968b6fed86b179b887e3d4f3681dd9f.zip |
added basic function generator
-rw-r--r-- | panel.py | 43 |
1 files changed, 30 insertions, 13 deletions
@@ -5,12 +5,29 @@ from tkinter import ttk import time # For sleep, clock, time and perf_counter from datetime import datetime +import numpy as np import matplotlib.pyplot as plt from matplotlib.figure import Figure from matplotlib.backends.backend_tkagg import (FigureCanvasTkAgg, NavigationToolbar2Tk) import ue9qol +class SinGen: + def __init__(self, ampl=1, offset=0, phase=0, sweeper=None): + self.ampl = ampl + self.phase = phase + self.sweeper = sweeper + self.offset = offset + + def getValue(self, sweeper=None): + if sweeper is None and self.sweeper is None: + print("Error: generator needs sweeper") + return 0 + if sweeper is None: + sweeper = self.sweeper + return self.ampl * np.sin( 2*np.pi*sweeper.getRelPos()) + self.offset + + class Sweeper: def __init__(self, widget, start, stop, Npoints, SweepTime, onTicCallbacks=[]): # walk from start to stop with Npoints @@ -53,13 +70,9 @@ class Sweeper: self.isRestart = False self.incr() print(self.cnt) - # if self.onTicCallbacks is None: - # self.isTicRunning = False - # return - # print(self.onTicCallbacks) - # for cb in self.onTicCallbacks: - # print(cb) - # cb(self) + for cb in self.onTicCallbacks: + print(cb) + cb(self) self.isTicRunning = False def cmdRestart(self): @@ -111,7 +124,8 @@ class Experiment: self.guiSetup(root) self.hardware = {} self.hardwareSetup() - self.sweeper = Sweeper(self.root, 1, 10, 10, 10) + self.sweeper = Sweeper(self.root, 1, 10, 10, 10, onTicCallbacks=[self.onTic]) + self.funcGen = SinGen(1, 0, sweeper = self.sweeper) # self.root.after(1000, self.hello ) def hardwareSetup(self): @@ -160,16 +174,19 @@ class Experiment: def restart(self): self.sweeper.cmdRestart() - def onTic(self): + def onTic(self,swp=None): + if swp is None: + swp = self.sweeper # self.root.after(1000, self.hello ) # self.sweeper.incr() - tic = self.sweeper.getCnt() - x = self.sweeper.getPos() + # tic = self.sweeper.getCnt() + x = swp.getRelPos() + y = self.funcGen.getValue(swp) # y = self.sweeper.getPos() # self.hardware['LabJack'].setOutputCh(0, x/2) self.hardware['LabJack'].setOutputCh(0, 2) self.data['tic'].append(x) - y= self.hardware['LabJack'].getInputCh(1) + # y= self.hardware['LabJack'].getInputCh(1) # self.data['ch1'].append( self.hardware['LabJack'].getInputCh(1) ) self.data['ch1'].append( y ) start = datetime.now() @@ -178,7 +195,7 @@ class Experiment: self.canvas.draw() stop = datetime.now() runTime = (stop-start).seconds + float((stop-start).microseconds)/1000000 - print("Replot took %s seconds to plot %s points." % (runTime, tic) ) + print("Replot took %s seconds to plot %s points." % (runTime, len(self.data['ch1'])) ) if __name__ == '__main__': |