python-microscope / microscope

Python library for control of microscope devices, supporting hardware triggers and distribution of devices over the network for performance and flexibility.
https://www.python-microscope.org
GNU General Public License v3.0
66 stars 38 forks source link

exploring adding attocube AMC300 controller #300

Open LauraA-Octopus opened 3 months ago

LauraA-Octopus commented 3 months ago

Good morning, I am exploring the idea of adding a control software for an attocube AMC300 3-axis stage controller. Can you please suggest me if you already have a code/part of it/in development that could be useful for this?

thank you

iandobbie commented 3 months ago

as far as I know no one has previously worked on this. They claim to have a JSON restful API or some python code. Given our previous experience with python APIs I would strongly suggest you look at going directly to the lowest level possible, probably the JSON interface rather than trying use the python library.

The reason for this is that we have previously found in every case that the python interface is neither properly documented or implemented. We find that changes to the API are not reflected in the python interface and also that the only documentation is usually to follow the python code through to the underlying API and find the documentation for that. This make the seemed simplicity of the already implemented python code is actually worse than useless.

LauraA-Octopus commented 3 months ago

Thank you for your reply, your suggestions are very much appreciated. Indeed the control protocol is not well documented. I have never worked with JSON interface directly. How would you suggest to start? Will it be possible to have a GUI in this case? Thank you for your help

iandobbie commented 3 months ago

I would use an existing json python library to enable you to create the relevant json objects and parse the json replies, then it depends exactly how the ssytem is designed but presumable there is a network interface to send those json objects over and recevie replies from.

Then you would need to go through the abstract base class for stages (in abc.py) and implement all the required methods, multi axis stages are a bit strange as each axis is an object and then the stage is a composite of the various axes. If you look at one of the existing stages that might help. Some of the stages are in the controllers directory as the stage controllers can also control filter wheels, shutters, etc...

I dont quite understand what you want the GUI for. If you want to control a whol;e microscope then I would use cockpit (https://github.com/microscope-cockpit/cockpit), which gives a GUI interface to the stage, but requires some work to setup if you have never used it before. For testing it can cirtainly control the stage a simulate cameras etc...

There are also very basic GUI components in microscope to allow testing of components and I think there is a single axis gui control for stages.

LauraA-Octopus commented 3 months ago

Hello Ian, thank you for your suggestion. The GUI is to indeed control an entire custom-made microscope. I will also need to write several adapters to control devices that are not supported in python-microscope yet. I wanted to ask if you have an example of code that I could look at as reference to write the AMC300 one. thank you very much for your suggestions. Best regards

carandraug commented 3 months ago

Hi Laura, all the stages that we have at the moment are devices that control a stage and other device types such as lights and filter wheels (ASI stage, ludl, Prior, and zaber). The attocube AMC300 would be the first. I can create such a template but first you need to decide the interface you want to take.

Looking at their documentation I see "directly through a JSON-based REST API Wrappers for Python, LabVIEW, Matlab, C-Library (Windows/Lin)" but it's not clear to me if this means it has a REST API and they provide wrappers to it to all of those languages, or if they provide a Python wrapper to the REST API and different drivers for the other languages. Can you clarify?

If the REST API and all their drivers are wrappers to those languages, then I guess we need to use the REST API (through their wrappers or through one of ours depending on what it is documented). If the REST API is for Python only and they have a native C library, I think using the C library directly may be better (provided it is documented). Do you have documentation that you can share with us?

juliomateoslangerak commented 3 months ago

Hi @LauraA-Octopus, I would add another question. Does the controller have analogue inputs?

LauraA-Octopus commented 3 months ago

Thanks all for your replies.

@juliomateoslangerak the controller doesn't have analogue inputs.

The general idea here is to integrate several devices (developing python adapters) that are all part of a microscope using your python-microscope and cockpit as general user interface to run experiments.

iandobbie commented 3 months ago

One thing to be aware of is that cockpit is fundamentally based around the idea of a hardware trigger device for running experiments in a reliable a repeatable manner. There are basically 2 choices at the moment, a ~$300 red pitaya single board linux computer, or a ~$5000+ (maybe more now not sure exactly how little you can get away with) National Instruments FPGA setup.

If you have no analogue devices I have a plan to implement digital only control on a Raspberry Pi Pico (~$5) but nothing beyond a simple test by Julio has been done towards implementing this.

iandobbie commented 3 months ago

Looking at their documentation I see "directly through a JSON-based REST API Wrappers for Python, LabVIEW, Matlab, C-Library (Windows/Lin)" but it's not clear to me if this means it has a REST API and they provide wrappers to it to all of those languages, or if they provide a Python wrapper to the REST API and different drivers for the other languages. Can you clarify?

To answer this the manual posted says.... ''' The device allows platform-independent communication using JSON-RPC via TCP/IP and websocket. The JSON commands are the lower level that all other wrappers (e.g. Python or C) use. '''

With that in mind I would target the JSON layer directly as the least likely to have unpleasent surprises or fail silently with an upgrade.

LauraA-Octopus commented 3 months ago

I'll give it a go targeting the JSON layer then. Thank you very much for your help and time