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

Asynchronous digital devices via microscope. #824

Closed iandobbie closed 1 year ago

iandobbie commented 2 years ago

There is a need for a digital control that doesn't rely on the hardware trigger timing. This can control things like flip mirrors etc... This has been implemented on DeepSIM and CryoSIM via the piDio (raspberry Pi Digital IO) control previously but needs to be migrated into microscope to provide a consistent interface. Discussion of the microscope side of this is at

https://github.com/python-microscope/microscope/issues/251

Here we should try to base the implementation of the cockpit side on the piDio device as this has the required GUI elements etc. Code is probably very much in need of refactoring.

iandobbie commented 2 years ago

To support the existing use of piDIO on the DeepSIM and CryoSIM systems the cockpit side needs to support:

1) path switching, specifically between widefield and SIM light paths

2) Objective switching

So as well as an interface to the remote device we need:

a) configuration definition

b) debug gui component to enable testing and switching of individual lines

c) binding of the objective change events to switch the relevant lines on objective change

Need to think about a digital in definition. None of the current systems are using this. I also think it would be worth including an interface to the logviewer functionality so we can do temperature measurements, as the existing systems do, but also log other values of interested possibly the digital in signals.

iandobbie commented 2 years ago

I was thinking about config formats for the light paths. Seems to me this should go into depot.conf, but needs to be much more readable and understandable than the existing regex split text strings. I thought of having a dictionary something like this:

{ 'Path Name': [[mirror #, state],[mirror#,state]], 'Path Name': [[mirror #, state],[mirror#,state]] }

But I'm not sure if that is easily encoded into the depot.conf file as this is not pure python unlike the config.py file.

iandobbie commented 1 year ago

I have finished a basic implementation of a microscope digitalIO device with an abc and a concrete implementation on a RaspberryPi which appears to work. Based on this I have started a cockpit side microscopeDevice.MicroscopeDIO device. So far this does init and allows calls to the remote functions to set lines to input or output and read/write the lines. It also implements a debug window which allows flipping of output lines.

The implementation is is https://github.com/iandobbie/cockpit/tree/DIOdev and requires https://github.com/iandobbie/microscope/tree/DIO to work

With the basic implementation in place I think there is a bit more functionality which needs to be added.

1) The ability to flip IO channels between input and output in the GUI 2) Be able to read input channels 3) A Main window GUI element for Julio's (and DeepSIMs) need to change excitation and/or emission path. a) provide buttons with labels b) clicks take a dictionary which defines DIO state c) maybe able to send specific events such as objective change, or filter change.

I am sure there are other requirements but this seems like a good start.

iandobbie commented 1 year ago

Julio suggested (in private email) a config along the lines of

[asyncDIO] type: devices.microscopeDevice.MicroscopeDIO uri: ... states: WideField: {"Mirror 0": True, "Mirror 1": True} # assuming True = High 3D-SIM: {"Mirror 0": False, "Mirror 1": False}

My issue was how to achieve this in the depot.conf which is not a python file. One thought I had is to read the config as a string from the config file and eval it in the code which would save a whole load of parsing but obviously a big possible security whole. I feel as the system is already python code if people are worried about the security they can have file system access privileges that are appropriate.

iandobbie commented 1 year ago

Now got a working implementation, but probably need to improve the config format. Current format is:

[DIO] type: cockpit.devices.microscopeDevice.MicroscopeDIO uri: PYRO:SimulatedDigitalIO@127.0.0.1:8010 labels: Mirror1 Mirror2 Flip1 Lens L3 L4 F2 F3 paths:{ "Widefield": [{"Mirror1": True, "Mirror2": False}, {"SIM": False}], "SIM": [{"Mirror1": False, "Mirror2": True}, {"Widefield": True}]}

Labels is a list of names that are used for the later buttons and used to label the debug buttons.

Paths is a string which is eval'd to allow us to get dicts and arrays without complex parsing. Format is a dict with a path name, followed by a list which is a dict of labels and states for given path followed by a dict of other paths which are set to the defined state.

Not very clean but I 'm not sure how to make it easier and stiull provide the same functionality.

iandobbie commented 1 year ago

I have been playing with the virtual device for the last few days as I have been back and forth between the lab and home but I will test this on the concrete Raspberry Pi implementation and then pull it into master.

iandobbie commented 1 year ago

Updated it to track changes with events so the debug window actually reflects current state. I am happy but needs testing on real hardware.

One additional feature I would like to add is pushed data from the remote system to update inout line states when they change.

iandobbie commented 1 year ago

Added interface in commit 23a49023761bb4b4b0288578848a9e06a4d79aae. Improvements in anew issue.