microscope-cockpit / cockpit

Cockpit is a microscope graphical user interface. It is a flexible and easy to extend platform aimed at life scientists using bespoke microscopes.
https://microscope-cockpit.org
GNU General Public License v3.0
35 stars 26 forks source link

Stage position updates if stage has a joystick. #856

Closed iandobbie closed 1 year ago

iandobbie commented 1 year ago

Stages such as the Ludl and ASI systems have a joystick that allows manual control of the stage position. Cockpit has no awareness of this and completely fails to register any changes.

In fact it is even worse than this. If you move the stage manually then cause a redraw of the mosaic window, say click "find stage", the stage position will update in that window but the macrostage windows doesn't update.

Problem is at least 2 fold as I see it.

1) Manual moves are not signaled.

2) when motion is registered eg in the mosaic, it doesn't update in other windows.

To solve the not signaled moves we could push the stage position but this seems pretty blunt tool with lots of additional complication for not much benefit. I think it would be more effective to have a relatively slow poll of the stage position, have a thread that polls position say every 10 s and checks to see if the position has changed. If it has sends and update event. This may also help the no update during large moves issue as well, but that depends if we can poll position while the stage is moving.

Issue 2 could easily be fixed by checking if we see a move when doing a position update and sending an event if we have.

iandobbie commented 1 year ago

So I have fixed number 2 above by triggering an event when the mosaic reads the position, as we have that data we might as well broadcast it.

I have a fix for number 1 which involves starting a thread which polls the stage every n (default 10) seconds if there is a poll-stage: True config entry. The one issue is that we need to know how many axes this stage has in order to wait until they are all initialized. I have added a config option to change the poll interval and some basic documentation in the depot configuration section.

iandobbie commented 1 year ago

Closed as seems complete

iandobbie commented 1 year ago

Turns out my timer thread was stupid and all the recent wx.timer fixes made me realise this. I have a rework of this that utilises a wx.timer and is shifted to the macrostage code as this is in wx, whereas the stage device isnt so cant do the wx timer.

I will tidy it up, test it with a real stage and push it into the main branch.

iandobbie commented 1 year ago

Properly fixed but forgot to merge as one commit. Added a wx.timer in fd85aae02ea33813caf40e5ab7b7d9913be8ada6 and removed the old timer code in 3a55173c8ab0e310e0174371e03695d50cdcdc8c

One remaining issue is there is a config parameter poll-stage that doesn't actually do anything at the moment. Need to trace how to access the parameter in the macrostageXY module where the polling is actually done now. Will open a new issue as the main issue is solved.

carandraug commented 1 year ago

something to keep in mind in the future: at least the stages from Thorlabs (or the ones I tried) have this builtin and it's possible to register callbacks. I'd imagine that other stages have something similar, so there's scope that have something like that in Microscope itself.

iandobbie commented 1 year ago

I'm not sure how this would work over a serial connection which is how I am talking to the ludl stage. I will look to see if it will send a signal but then I guess I would need to poll the serial connection to see if it received anything.

carandraug commented 1 year ago

Probably wouldn't work for stages controlled over a serial connection. The callbacks I was talking about was a function we can register with the stage C library (when it exists). Anyway, I don't think we have to do anything about this now, it was just something to keep in mind for the future. Some stages come with that functionality builtin.