Hi, I am working no a cursor based task where the subject interfaces with some external non-classical computer interface hardware (as in no keyboard/mouse etc) and I want to use the data to update what is on the screen. Currently, I have the data available on a udp port and I use standard socket module to read from it.
The problem that I am facing is that the data comes in at 100Hz, and when I draw on received udp data I very quickly accumulate a massive lag. It seems to me that the iohub could be a solution to deal with events that happen at a different rate than the screen refresh rate, but I could not find or understand a matching example.
Here is some example code:
from psychopy import visual, core, monitors
import socket
import struct
mon = monitors.Monitor(name="display",width=10,distance=5)
win = visual.Window(size=[1024,768], monitor=mon, screen=0, fullscr=False, useFBO=True)
gabor = visual.GratingStim(win, tex='sin', mask='gauss', sf=5, name='gabor', autoLog=False, size=2)
def update(x,y):
gabor.pos = [x,y]
gabor.draw()
win.flip()
UDP_IP, UDP_PORT = "127.0.0.1", 4002
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP
sock.bind((UDP_IP, UDP_PORT))
sock.setblocking(False)
while True:
try:
raw_read = sock.recv(8)
x,y = struct.unpack('ff',raw_read)
update(x,y)
except BlockingIOError:
pass
What is the correct place to look, or how else should I approach this? Thanks for help!