wavefrontshaping / slmPy

A simple Python module based on wxPython to interact with spatial light modulators handled as secondary monitors.
Other
63 stars 26 forks source link

updateArray method sometimes causes flickering #9

Closed MEisebitt closed 2 years ago

MEisebitt commented 2 years ago

Hey,

I tested the package on a monitor to make sure not to damage the LCoS I plan to control. Currently I just tried to draw a white rectangle onto a black screen that grows over time as a test, however on some refreshes/updateArray() calls the whole screen turns white. I checked an the flickering seems to only occur for a short time as increesing the sleep time in updateArray() does not increase the length of the flickering. It only happens on some draw calls so sometimes I get no flickering aswell. I am scared this might damage the LCoS. therefore I wanted to ask whether you know anything about this.

Below you can find a minimal example to demonstrate the problem:

import slmpy
import numpy as np

slm = slmpy.SLMdisplay(monitor = 1)
resX, resY = slm.getSize()

xEnd = 300
yEnd = 500

for i in range(20):
    img = np.zeros((resY, resX), dtype=np.int8)
    img[200:xEnd, 400:yEnd] = 200
    xEnd += 5
    yEnd += 5
    slm.updateArray(img, sleep=0.2)

The events are so random that sometimes I get 4 or 5 executions in a row without any but the next 4 or 5 all flicker constantly. I am using the latest github version.

Best Regards

MEisebitt commented 2 years ago

I noticed the problem does not occur when using arrays of the half screen size, like you did in your moving fringes example. However when removing the //2 's from your example it also begins to flicker from time to time.

On a side note: Decreasing the sleep time further makes the flashes reappear on the halved resolution aswell.

MEisebitt commented 2 years ago

After a long search, I think I have located the error to the .Refresh() call in the UpdateImage() method of SLMwindow. Calling it with eraseBackground=False makes the flicker disappear for me.

def UpdateImage(self, event):
    self.eventLock = event.eventLock
    self.img = event.img
    self.Refresh(eraseBackground=False)

    self.ReleaseEventLock()
wavefrontshaping commented 2 years ago

Hi,

Sorry for the delay. Thanks for the fix, I did not experience this bug myself but it may be because of different resolutions and parameters. I accepted the merge request.