From 50dc3026943b90cdb9228a1502a905b10dd10ea6 Mon Sep 17 00:00:00 2001 From: "Eugeniy E. Mikhailov" Date: Sat, 3 Apr 2021 22:52:45 -0400 Subject: added triangle generator --- panel.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'panel.py') diff --git a/panel.py b/panel.py index 6b55681..6acf119 100644 --- a/panel.py +++ b/panel.py @@ -42,6 +42,22 @@ class RampGen: sweeper = self.sweeper return self.start + sweeper.getRelPos()*(self.stop - self.start) +class TriangleGen: + # monotonically goes from start to stop, once reaches stop goes back to start + def __init__(self, start=0, stop=0, sweeper=None): + self.start = start + self.stop = stop + self.sweeper = sweeper + + 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 + if sweeper.getRelPos() < 0.5: + return self.start + 2*sweeper.getRelPos()*(self.stop - self.start) + return self.start + 2*(1-sweeper.getRelPos())*(self.stop - self.start) class Sweeper: def __init__(self, widget, start, stop, Npoints, SweepTime, onTicCallbacks=[]): -- cgit v1.2.3