Skip to content

Commit f38d4c8

Browse files
author
Andrew Reeves
committed
Merge pull request #40 from jwoillez/live_loop_delay
config.sim.loopDelay can now be changed on the fly
2 parents c80985f + 81189e6 commit f38d4c8

File tree

2 files changed

+13
-18
lines changed

2 files changed

+13
-18
lines changed

soapy/aoSimLib.py

+11-16
Original file line numberDiff line numberDiff line change
@@ -684,26 +684,21 @@ def photonsPerMag(mag, mask, pxlScale, wvlBand, expTime):
684684
######################
685685

686686

687-
class FixedLengthBuffer:
687+
class DelayBuffer(list):
688688
'''
689-
A fixed length buffer.
689+
A delay buffer.
690690
691-
Each time the buffer is called the input value is stored.
692-
If the buffer is full, the oldest value is removed and returned.
693-
If the buffer is not yet full, a zero os similar shape as the last input
691+
Each time delay() is called on the buffer, the input value is stored.
692+
If the buffer is larger than count, the oldest value is removed and returned.
693+
If the buffer is not yet full, a zero of similar shape as the last input
694694
is returned.
695-
696-
Args:
697-
length: length of the buffer.
698695
'''
699696

700-
def __init__(self, length):
701-
print("Creating buffer of length {0}".format(length))
702-
self.buffer = [None] * length
703-
704-
def __call__(self, value):
705-
self.buffer.append(value)
706-
result = self.buffer.pop(0)
707-
if result is None:
697+
def delay(self, value, count):
698+
self.append(value)
699+
if len(self) <= count:
708700
result = value*0.0
701+
else:
702+
for _ in range(len(self)-count):
703+
result = self.pop(0)
709704
return result

soapy/simulation.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ def aoinit(self):
281281
self.initSaveData()
282282

283283
#Init simulation
284-
self.delay = aoSimLib.FixedLengthBuffer(self.config.sim.loopDelay)
284+
self.buffer = aoSimLib.DelayBuffer()
285285
self.iters=0
286286

287287
#Init performance tracking
@@ -524,7 +524,7 @@ def loopFrame(self):
524524
self.dmCommands[:] = self.recon.reconstruct(self.slopes)
525525

526526
# Delay the dmCommands if loopDelay is configured
527-
self.dmCommands = self.delay(self.dmCommands)
527+
self.dmCommands = self.buffer.delay(self.dmCommands, self.config.sim.loopDelay)
528528

529529
# Get dmShape from closed loop DMs
530530
self.closedCorrection += self.runDM(

0 commit comments

Comments
 (0)