aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--funcGenerator.py21
1 files changed, 16 insertions, 5 deletions
diff --git a/funcGenerator.py b/funcGenerator.py
index 1e7be5e..54a3b1b 100644
--- a/funcGenerator.py
+++ b/funcGenerator.py
@@ -55,18 +55,29 @@ class RampGen:
sweeper = self.sweeper
return self.start + sweeper.getRelPos()*(self.stop - self.start)
-class TriangleGen(RampGen):
+class SawGen(RampGen):
# monotonically goes from start to stop, once reaches stop goes back to start
- # does it with 50% duty cycle, i.e half of period we go up, the other half down
+ # does it with duty_cycle,
+ # i.e duty_cycle*period we go up, the other time we go down
+ def __init__(self, duty_cycle=0.5, **kwds):
+ self.duty_cycle = duty_cycle;
+ super().__init__(**kwds)
+
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)
+ if sweeper.getRelPos() < self.duty_cycle:
+ return self.start + sweeper.getRelPos()/self.duty_cycle*(self.stop - self.start)
+ return self.start + (1-sweeper.getRelPos())/(1-self.duty_cycle)*(self.stop - self.start)
+
+class TriangleGen(SawGen):
+ # monotonically goes from start to stop, once reaches stop goes back to start
+ # does it with 50% duty cycle, i.e half of period we go up, the other half down
+ def __init__(self, **kwds):
+ super().__init__(duty_cycle=0.5, **kwds)
class PulseGen:
# produce ampl for the first half a period and 0 for the other half