I’ve created some code that renders a procedurally generated model of a simple maze. The y-position is controlled by a wheel connected to a rotary encoder which communicates to the program using a ZMQ socket connection. I have defined a Task which receives messages and updates the position variable. Everything is working approximately fine, and the reported frame rate is usually my monitor refresh rate (60 Hz).
Yesterday, I instrumented it with a photosensor, and discovered that the scene updates are occurring with a lag of between 3 and 4 frames. The 1 frame variability makes sense to me (the update will occur sometime between frames), but I don’t understand the 3-frame baseline. Is there some sort of double buffering that I can turn off?
More detail on my Task - I poll on the socket with a 0.01 ms timeout for the first message and a 0 ms timeout for subsequent ones (I expect ~8-9 messages per frame), and only finally update the position when no more messages are available.
Second more detail - I should mention that this is running on a Raspberry Pi 4B. Panda reports that I can do stable framerates up to 75Hz, but I really should try also on my desktop.
(The code is here - github.com/kemerelab/PyRenderMaze. It’s hard to make a minimal implementation b/c the instrumentation requires some hardware.)