Microscope Simulator

Since my microscope broke (and I’m still waiting for replacement parts), I decided to build a sim to continue my work in the mean time. While the v3 branch does have an elementary simulator, it doesn’t accurately mimic things like focus and lighting - which is important for the work I happen to be doing right now. The sim seems to work okay. I wrote it in C++ with an OpenGL rendering backend, and I pipe the contents to a v4l2 loopback device. This allows me to seamlessly plug it into software I have written, or existing software like the v3 branch of the OpenFlexure software. Here’s an image of it running in VLC:


The blurring is based on the optical simulation running in the OpenGL shader, which simulates a larger aperture in order to get a narrow focal point range (notice the blurring on the corners of the frame). The lighting is adjustable. The virtual stage and lighting controls are based on the command syntax of the sangaboard and are read from stdin of the program. The simulator also mimics step loss from the motors, to simulate drift.

3 Likes

This is really cool! I’d love to improve the simulator in v3, and should make sure to look more closely at what you’ve done when we do. OpenGL may or may not play nicely with things like testing in CI, but for sure there will be people who want an interactive simulator that’s more sophisticated than the (deliberately basic) one we have at the moment.

@r.w.bowman thanks. OpenGL can work in CI, just takes a little bit of workarounds. What is currently used in the v3 branch looks perfectly fine. Deliberately basic, as you mentioned, is the right philosophy there. I only needed this slightly more complicated version to test some automation features that are sensitive to step loss and focus.