Skip to content

Commit

Permalink
Merge branch 'master' of github.com:soapy/soapy
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewpaulreeves committed Mar 3, 2016
2 parents f99453c + f38d4c8 commit de23b3b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
27 changes: 11 additions & 16 deletions soapy/aoSimLib.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,26 +685,21 @@ def photonsPerMag(mag, mask, pxlScale, wvlBand, expTime):
######################


class FixedLengthBuffer:
class DelayBuffer(list):
'''
A fixed length buffer.
A delay buffer.
Each time the buffer is called the input value is stored.
If the buffer is full, the oldest value is removed and returned.
If the buffer is not yet full, a zero os similar shape as the last input
Each time delay() is called on the buffer, the input value is stored.
If the buffer is larger than count, the oldest value is removed and returned.
If the buffer is not yet full, a zero of similar shape as the last input
is returned.
Args:
length: length of the buffer.
'''

def __init__(self, length):
print("Creating buffer of length {0}".format(length))
self.buffer = [None] * length

def __call__(self, value):
self.buffer.append(value)
result = self.buffer.pop(0)
if result is None:
def delay(self, value, count):
self.append(value)
if len(self) <= count:
result = value*0.0
else:
for _ in range(len(self)-count):
result = self.pop(0)
return result
4 changes: 2 additions & 2 deletions soapy/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def aoinit(self):
self.initSaveData()

#Init simulation
self.delay = aoSimLib.FixedLengthBuffer(self.config.sim.loopDelay)
self.buffer = aoSimLib.DelayBuffer()
self.iters=0

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

# Delay the dmCommands if loopDelay is configured
self.dmCommands = self.delay(self.dmCommands)
self.dmCommands = self.buffer.delay(self.dmCommands, self.config.sim.loopDelay)

# Get dmShape from closed loop DMs
self.closedCorrection += self.runDM(
Expand Down

0 comments on commit de23b3b

Please sign in to comment.