Skip to content

Commit

Permalink
fix(#1184): PositionerBase as an ABC to ensure .egu and .move() are o…
Browse files Browse the repository at this point in the history
…verwritten in subclasses
  • Loading branch information
Mathias Guijarro committed Apr 8, 2024
1 parent 8243d21 commit 7687519
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions ophyd/positioner.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import functools
import logging
import time
from abc import ABCMeta, abstractmethod
from collections import OrderedDict
from typing import Any, Callable

Expand All @@ -13,18 +14,11 @@
logger = logging.getLogger(__name__)


class PositionerBase(OphydObject):
class PositionerBase(OphydObject, metaclass=ABCMeta):
"""The positioner base class
Subclass from this to implement your own positioners.
.. note ::
Subclasses should add an additional 'wait' keyword argument on
the move method. The `MoveStatus` object returned from
`PositionerBase` can then be waited on after the subclass
finishes the motion configuration.
"""

SUB_START = "start_moving"
Expand Down Expand Up @@ -136,9 +130,10 @@ def report(self):
return rep

@property
@abstractmethod
def egu(self):
"""The engineering units (EGU) for positions"""
raise NotImplementedError("Subclass must implement egu")
pass

@property
def limits(self):
Expand All @@ -152,6 +147,7 @@ def low_limit(self):
def high_limit(self):
return self.limits[1]

@abstractmethod
def move(self, position, wait=False, moved_cb=None, timeout=None):
"""Move to a specified position, optionally waiting for motion to
complete.
Expand Down Expand Up @@ -210,6 +206,9 @@ def move(self, position, wait=False, moved_cb=None, timeout=None):

self.subscribe(status._finished, event_type=self._SUB_REQ_DONE, run=False)

if wait:
status.wait()

return status

def _done_moving(self, success=True, timestamp=None, value=None, **kwargs):
Expand Down

0 comments on commit 7687519

Please sign in to comment.