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
73 stars 42 forks source link

ASI stage not waiting for idle before next move #296

Open juliomateoslangerak opened 1 year ago

juliomateoslangerak commented 1 year ago

While setting some experiments I realized that the stage was not waiting until the next move.

I think I fixed this and I also tried to remove some redundancy in the code managing the moves and the waiting for the stage to idle.

This is all in my branch here. @iandobbie can you check this? You can use this code to test with a tiling array. In my case it was drawing little circles no matter the size of the tile. now it seems to work. Simultaneous move in x and y is kept.

PORT = None
baudrate = 9600

from microscope.controllers.asi import ASIMS2000
controller = ASIMS2000(port=PORT, baudrate=baudrate)
stage = controller.devices["stage"]
stage.enable()

x_tile_size = 1000
y_tile_size = 1000
array_size = 5

pre_experiment_position = stage.position

def spiral(n):
    x = y = 0
    dx = 0
    dy = -1
    for i in range(n**2):
        if (-n/2 < x <= n/2) and (-n/2 < y <= n/2):
            yield (pre_experiment_position["X"] + (x * x_tile_size) , 
                   pre_experiment_position["Y"] + (y * y_tile_size))
        if x == y or (x < 0 and x == -y) or (x > 0 and x == 1-y):
            dx, dy = -dy, dx
        x, y = x+dx, y+dy

for pos_x, pos_y in spiral(array_size):
    stage.move_to({"X": pos_x, "Y": pos_y})

stage.move_to(pre_experiment_position)
iandobbie commented 1 year ago

This appears to work fine. I didnt have a camera connected and wasn't taking images but from feeling the stage it appears to move in x and then y, then back in x etc. The movement weren't regular I assume this is this is the servo have a bit of variable seek time, I strongly suspect out stage could do with some lubrication. I might try to do this.

Overall I think the ASI updates are a big win and appear to work so should be merged into master.