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

Number of axis is ASI stage is hard coded. #287

Closed iandobbie closed 8 months ago

iandobbie commented 8 months ago

In asi.py about line 413 we have

class _ASIStage(microscope.abc.Stage):
    def __init__(self, conn: _ASIController, **kwargs) -> None:
        super().__init__(**kwargs)
        self._dev_conn = conn
        self._axes = {
            str(i): _ASIStageAxis(self._dev_conn, i)
            for i in range(1, 3)  # self._dev_conn.get_number_axes() + 1)w
        }
        self.homed = False

Maybe you just need to replace the range (1,3) with self._dev_conn.get_number_axes() + 1 as suggested?

juliomateoslangerak commented 8 months ago

I'm receiving this week an RAMM-mim from ASI for the mifobio workshop and I think I have to spend some time on this implementation. I think we might extract the information through the INFO command that you use to get the devices that are connected. I do not quite get this. According to the doc this is used to get device specific info, but that's not how you use this command... If the docs are right we might loop through the axes to get info and we might get some error when the axis is not present...

iandobbie commented 8 months ago

Yes you are correct. I am just using the info command to see that the stage is connected and responding, I just throw away the reply. We should really parse it! I will grab my output and if you could also grab your we can write somethng that will pull out sensible data from both as I suspect they may be different, I think my controller is from at least 20 years ago!

juliomateoslangerak commented 8 months ago

I just checked and requesting INFO from a non existing axis returns nothing. Now is bedtime but kids and wife are away for 2 weeks, so I can work into this. I should be getting some led sources form ASI, so I will have to implement these too. As I understand they are only controlled by the TIGER controller. My own is a Z only controller MCF2000, so we can cover quite some controllers

iandobbie commented 8 months ago

Ok, I can have a look at interrogating the controller to find the connected axes, but not till later in the week. My wife and half the kids are away as well, but still have a couple of hungry teens to feed and corral.

There are options for filter wheels and I think a transmission source on my controller but we don't have them so I didn't do any work to implement them as I couldn't test them.

iandobbie commented 8 months ago

So it seems like an approach might be to send info x, info y and info Z and parse the responses. to find out what axes are present on the system.

iandobbie commented 8 months ago

my system returns this.....

send %s b'INFO X'
read line b'\n\r'
read line b'Axis Name    :  X                Limits Status: f\r'
read line b'Input Device :      JS_X [J]       In_Dev Sign  :         1\r'
read line b'Max Lim      :   110.000 [SU]    Min Lim      :  -110.000 [SL] \r'
read line b'Ramp Time    :       100 (ms)[AC]Max Ramp Stps:        16      \r'
read line b'Run Speed    :   5.76000(mm/s)[S]vmax_enc     :      1728      \r'
read line b'Servo Lp Time:         6 (ms)    Ramp Length  :     24480 (enc)\r'
read line b'dv_enc       :       102         LL Axis ID   :        24\r'
read line b'Drift Error  :  0.000500 (mm)[E] enc_drift_err:        25   \r'
read line b'Finish Error :  0.000022 (mm)[PC]enc_finsh_err:         1      \r'
read line b'Backlash     :  0.000000 (mm)[B] enc_backlash :         0   \r'
read line b'Overshoot    :  0.000000 (mm)[OS] enc_overshoot:         0   \r'
read line b'Kp           :        60 [KP]    Ki           :         8 [KI]\r'
read line b'Kv           :         6 [KV]    Kd           :        -1 [KD]\r'
read line b'Axis Enable  :         3 [MC]    Motor Enable :         0   \r'
read line b'CMD_stat     :   NO_MOVE           Move_stat    :      IDLE\r'
read line b'Current pos  :    0.0000 (mm)    enc position :         0\r'
read line b'Target pos   :    0.0000 (mm)    enc target   :         0\r'
read line b'enc pos error:         0         EEsum        :         0\r'
read line b'Lst Stle Time:         0 (ms)    Av Settle Tim:         0 (ms) \r'
read line b'Home position:   1000.01 (mm)    Motor Signal :         0 (DAC)\r'
read line b'mm/sec/DAC_ct:   0.07500 [D]     Enc Cnts/mm  :  50000.00 [C] \r'
read line b'Wait Time    :         0 [WT]     Button Enable byte: 95 [BE]  \r'
read line b'\n'
read line b''
juliomateoslangerak commented 8 months ago

Just pushed some fixes for this.

Can you have a look?

juliomateoslangerak commented 8 months ago

Just checked that your units might not work cause they are in parenthesis (mine are not). Anyway you should get units in parenthesis. They are not used anyway for the moment

juliomateoslangerak commented 8 months ago

Adding the stage device settings is working but values is not describing ranges as those can not be requested. They are in the docs. But I do not feel like gong through this. We might do it for some of the key parameters. Left to do is to modify some of the internal functions to use the device.settings to get the values, like min_limit and upper_limit

iandobbie commented 8 months ago

I was grabbing the range in the init function. It drives the stage all the way to the -ve end of the range until it hits a stop, zero's the position then drives to the positive limit and sets the range from this. I do plan to update this a little bit. Jon from ASI suggested that I should just drive to a large negative positon rahrer than use the free run function, I dont see the fundamental reason for this to be honest.

I do however have to do some more work on the speed as my original code just set it very high, which effetcive runs it at the max speed. The x axis worked but rhe Y didn't. I have no set arbitary lower speeds but Jon suggested setting it very high, then reading the actual speed and setting it to 70% of this. Easy fix, just not done it yet.

juliomateoslangerak commented 8 months ago

Do you think I can push my changes to main and move from there?

I just received today a RAMM-mim for MiFoBio with a MS2000 controlling XYZ and 2 leds.

iandobbie commented 8 months ago

I'm happy with this proposal as I am not using this in anger. We should reach out to the McGill crowd and get them to test it as well as me.

juliomateoslangerak commented 8 months ago

I will push this to main and close this as the original issue is fixed

iandobbie commented 8 months ago

Just to update the issue to say that this works fine on my MS2000 controller with xy stage and piezo Z output that goes to a madcity labs piezo controller.