Getting ProScan III Z-Encoder position into Micro-manager after movement

Hello everyone!

First post here, so let me know if anything doesn’t follow the rules/guidelines!

I’m currently working on a piece of software in Python that uses Micro-manager (controlled via the Pycromanager package) for stage movement while addressing an external camera through other means. The software loops over the positions in the micro-manager position list and manually fires the external camera at each position and calls some other code there.
To control the stage we have a Prior ProScan III which has X-Y stepper motors and an add-on Z/focus drive. It also receives Z-position information from a Z encoder plugged into the ProScan III. When using the Prior controller software the Z-encoder sends very detailed z-information to the ProScan III controller, allowing for accurate position for focus.
The problem is that when micro-manager moves between different Multistage positions which have different z-values using the position list or the stage movement tool it overwrites the z-encoded position value (we see that the z-position stops fluctuating and loses 1-2 decimals in position). The Z-position from the encoder is (seemingly at least) not overwritten upon starting the Micro-manager software, only upon computerized movement.

Does anyone know from where this “internal” z-position is calculated from and if micro-manager can be forced to keep the z-position coming from ProScan itself?
I also wonder if anyone has used the MMCore serialPort commands? The ProScan III can be addressed via serial port messaging so I was considering whether writing an function to reenable the Encoder (in case Micro-manager somehow switches it off) after each acquisition might be worth a try?

Thankful for any response!

Is this using the pycromanager Acquisition class or are you controlling the core directly. If the latter, this is likely a problem in device adapter in your z stage, and it is worth opening an issue on the main micro-manager github about this.

Assuming that you use the Prior device adapter and that it communicates through the serial port. Correct me if any of these assumptions are wrong.

The Prior device adapter reads the position of the Z-stage using the “PZ” command. I do not know whether this gets the position of the encode or the position of the actual Z stage. You can experiments with this by executing in the Script Panel (under the Tools menu):
mmc.getPosition();
That will return the value coming from the controller as a response to the PZ command. If that is the value of the encoder, then the device adapter does what you would like it to do, and the issue is somewhere upstream, if it is the value of the focus driver, then the device adapter would need to be modified to use the encoder when present and when it is desired to use it. Someone will need to write those…

Continuing the discussion from Getting ProScan III Z-Encoder position into Micro-manager after movement:

@henrypinkard I am not using the Acquisition class, I am moving the stage via the core directly (by using MultistagePos method go_to_position). So this makes it more likely to be a MM/Device adapter issue I would guess.

@nicost Okay thank you, after returning to the lab I ran some tests and have the following information:
mmc.getPosition() returns the encoder value from Prior. The problem comes from the fact that in micro-manager does not automatically enable the focus encoder, but this needs to be enabled manually in prior beforehand. Furthermore Prior doesn’t report when the encoder becomes disabled due to a difference in encoder and stepper position, and doesn’t reenable it. In the device adapter it would perhaps be nice to either add in as a field to the z-stage device an option to automatically switch on the encoder (i.e. send a ENCODER command, to find out what encoders are active, then activate these with Encoder {AXIS} 1 commands) alternatively create a new device adapter for the encoder-type devices which Prior uses. Is the source code for the device adapers readily available?

Yes, the source code for all device adapters is here: GitHub - micro-manager/mmCoreAndDevices: The c++ code at the core of the Micro-Manager project., the Prior code can be found at: mmCoreAndDevices/DeviceAdapters/Prior at main · micro-manager/mmCoreAndDevices · GitHub.

We’ll be happy with Pull Requests, but it will be important that the code also works with controllers that do not have an encoder. It may be useful to ask Prior for help.