aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--panel.py35
1 files changed, 23 insertions, 12 deletions
diff --git a/panel.py b/panel.py
index 6acf119..921bb1f 100644
--- a/panel.py
+++ b/panel.py
@@ -60,16 +60,16 @@ class TriangleGen:
return self.start + 2*(1-sweeper.getRelPos())*(self.stop - self.start)
class Sweeper:
- def __init__(self, widget, start, stop, Npoints, SweepTime, onTicCallbacks=[]):
+ def __init__(self, widget, Npoints, SweepTime, onTicCallbacks=[]):
# walk from start to stop with Npoints
# cnt = 1 corresponds to start
# cnt = Npoints corresponds to stop
# variables like relVar are relative to the start of the period
self.cnt = 0 # onTic will increase it right away
self.widget = widget
- self.start = start
- self.stop = stop
self.Npoints = Npoints
+ self.start = 1
+ self.stop = self.Npoints
self.SweepTime = SweepTime
self.onTicCallbacks = onTicCallbacks
self.isOn = False
@@ -80,7 +80,7 @@ class Sweeper:
self.center = (self.stop + self.start)/2
self.dPos = self.span/(self.Npoints-1)
self.dT = self.SweepTime/(self.Npoints-1)
- self.dTmS = round(self.dT*1000) # dT in microSeconds
+ self.dTmS = round(self.dT*1000) # dT in milliseconds
def reset(self):
self.cnt = 0 # onTic will increase it right away
@@ -100,8 +100,13 @@ class Sweeper:
self.reset()
self.isRestart = False
self.incr()
+ start = datetime.now()
+ print(start)
for cb in self.onTicCallbacks:
cb(self)
+ stop = datetime.now()
+ runTime = (stop-start).seconds + float((stop-start).microseconds)/1000000
+ print("Callbacks took %s seconds." % (runTime) )
self.isTicRunning = False
def cmdRestart(self):
@@ -147,14 +152,14 @@ class Experiment:
def __init__(self, root):
self.root = root
self.tic = 0
- self.data = {}
- self.data['tic'] = []
- self.data['ch1'] = []
+ self.clearData()
self.guiSetup(root)
self.hardware = {}
self.hardwareSetup()
- self.sweeper = Sweeper(self.root, 1, 10, 100, 10, onTicCallbacks=[self.onTic])
- self.funcGen = SinGen(1, 0, sweeper = self.sweeper)
+ self.sweeper = Sweeper(self.root, Npoints=100, SweepTime=1, onTicCallbacks=[self.onTic])
+ # self.funcGen = SinGen(2, 2, sweeper = self.sweeper)
+ # self.funcGen = RampGen(0, 5, sweeper = self.sweeper)
+ self.funcGen = TriangleGen(0, 5, sweeper = self.sweeper)
# self.root.after(1000, self.hello )
def hardwareSetup(self):
@@ -194,6 +199,11 @@ class Experiment:
# placing the toolbar on the Tkinter window
self.canvas.get_tk_widget().pack()
+ def clearData(self):
+ self.data = {}
+ self.data['tic'] = []
+ self.data['ch1'] = []
+
def stop(self):
self.sweeper.cmdStop()
@@ -201,6 +211,7 @@ class Experiment:
self.sweeper.cmdStart()
def restart(self):
+ self.clearData()
self.sweeper.cmdRestart()
def onTic(self,swp=None):
@@ -213,14 +224,14 @@ class Experiment:
y = self.funcGen.getValue(swp)
# y = self.sweeper.getPos()
# self.hardware['LabJack'].setOutputCh(0, x/2)
- self.hardware['LabJack'].setOutputCh(0, 2)
+ self.hardware['LabJack'].setOutputCh(0, y)
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()
self.ax.cla()
- self.ax.plot(self.data['tic'], self.data['ch1'])
+ self.ax.plot(self.data['tic'], self.data['ch1'], '.')
self.canvas.draw()
stop = datetime.now()
runTime = (stop-start).seconds + float((stop-start).microseconds)/1000000