Skip to content

Commit 50e7658

Browse files
author
Mathias Guijarro
committed
fix(#1184): PositionerBase as an ABC to ensure .egu and .move() are overwritten in subclasses
1 parent 5c03c3f commit 50e7658

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

ophyd/positioner.py

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import functools
22
import logging
33
import time
4+
from abc import ABCMeta, abstractmethod
45
from collections import OrderedDict
56
from typing import Any, Callable
67

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

1516

16-
class PositionerBase(OphydObject):
17+
class PositionerBase(OphydObject, metaclass=ABCMeta):
1718
"""The positioner base class
1819
1920
Subclass from this to implement your own positioners.
2021
21-
.. note ::
22-
23-
Subclasses should add an additional 'wait' keyword argument on
24-
the move method. The `MoveStatus` object returned from
25-
`PositionerBase` can then be waited on after the subclass
26-
finishes the motion configuration.
27-
2822
"""
2923

3024
SUB_START = "start_moving"
@@ -136,9 +130,10 @@ def report(self):
136130
return rep
137131

138132
@property
133+
@abstractmethod
139134
def egu(self):
140135
"""The engineering units (EGU) for positions"""
141-
raise NotImplementedError("Subclass must implement egu")
136+
pass
142137

143138
@property
144139
def limits(self):
@@ -152,7 +147,8 @@ def low_limit(self):
152147
def high_limit(self):
153148
return self.limits[1]
154149

155-
def move(self, position, moved_cb=None, timeout=None):
150+
@abstractmethod
151+
def move(self, position, wait=False, moved_cb=None, timeout=None):
156152
"""Move to a specified position, optionally waiting for motion to
157153
complete.
158154
@@ -175,6 +171,8 @@ def move(self, position, moved_cb=None, timeout=None):
175171
timeout : float, optional
176172
Maximum time to wait for the motion. If None, the default timeout
177173
for this positioner is used.
174+
wait : bool, optional
175+
Wait for the Status object to be complete (False by default)
178176
179177
Returns
180178
-------
@@ -208,6 +206,9 @@ def move(self, position, moved_cb=None, timeout=None):
208206

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

209+
if wait:
210+
status.wait()
211+
211212
return status
212213

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

0 commit comments

Comments
 (0)