Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change ExEngine motor's API #36

Open
jacopoabramo opened this issue Dec 1, 2024 · 1 comment
Open

Change ExEngine motor's API #36

jacopoabramo opened this issue Dec 1, 2024 · 1 comment

Comments

@jacopoabramo
Copy link
Contributor

jacopoabramo commented Dec 1, 2024

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

@jacopoabramo
Copy link
Contributor Author

I still think that the typing for triggerable sequences can be done even better, but this is a first draft that came to me on a whim while working on my application.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant