Skip to content

Change ExEngine motor's API #36

Open
@jacopoabramo

Description

@jacopoabramo

I'm currently reviewing a bit the API for the motors and I believe they can be better expressed to be more generic than they currently are.

At the time I believe that they were a starting point to address an initial design; for the application I'm working on I may propose a change that looks something along these lines (affected module is exengine.device_types):

"""
Base classes for device_implementations that can be used by the execution engine
"""

from abc import abstractmethod
import numpy as np
from exengine.kernel.device import Device
from typing import TypedDict, Generic, TypeVar, Sequence

T = TypeVar('T')
X = TypeVar('X')

class Position(TypedDict, Generic[T]):
    """Typed dictionary for describing position values of a positioner.
    
    Parameters
    ----------
    axis : X
        The axis or axes that the value corresponds to.
    """
    
    axis: str
    value: T

class Positioner(Device):
    """ A positioner that can move along a single axis (e.g. a z drive used as a focus stage) """

    @abstractmethod
    def set_position(self, position: Position[float]) -> None:
        """Set the position of the device."""
        ...

    @abstractmethod
    def get_position(self, axis: str) -> Position[float]:
        """Return the position of the device on the specific axis."""
        ...


class TriggerablePositioner(Positioner):
    """
    A special type of positioner that can accept a sequence of positions to move to when provided external TTL triggers
    """
    @abstractmethod
    def set_sequence(self, positions: Sequence[Position[np.ndarray]]) -> None:
        ...

    @abstractmethod
    def get_sequence_length(self) -> int:
        ...

    @abstractmethod
    def stop_sequence(self) -> None:
        ...

I understand that this might be somewhat disruptive of the current situation, but I remember that the initial design was closely related to Micro-Manager APIs. This would give a much needed higher level of flexibility to whoever wants to implement it's own device interface.

EDIT: link typo

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions