Skip to content

Commit e96e316

Browse files
committed
Stage: remove need_homed and add may_move_on_enable (#246)
This commit removes the recent `need_homed` abstract property and optional `home` method (added in 9c50cb9) and adds a new abstract method `may_move_on_enable`. This commit also implements the new method in the zaber and ludl stages.
1 parent 4584856 commit e96e316

File tree

4 files changed

+45
-34
lines changed

4 files changed

+45
-34
lines changed

NEWS.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ Version 0.7.0 (upcoming)
1313
`Camera.get_trigger_type` does not return the same as
1414
`Camera.trigger_type` property.
1515

16+
* Changes to device ABCs:
17+
18+
* The `Stage` ABC has a new method `may_move_on_enable` to hint
19+
whether calling `enable` will cause the stage to move.
20+
1621
* New devices supported:
1722

1823
* Toptica iChrome MLE

microscope/abc.py

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,7 +1396,7 @@ class Stage(Device, metaclass=abc.ABCMeta):
13961396
.. code-block:: python
13971397
13981398
stage = SomeStageDevice()
1399-
stage.enable() # may trigger a stage move
1399+
stage.enable() # may trigger a stage move
14001400
14011401
# move operations
14021402
stage.move_to({'x': 42.0, 'y': -5.1})
@@ -1447,7 +1447,7 @@ class documentation for hardware specific details.
14471447
14481448
Some stages need to find a reference position, home, before being
14491449
able to be moved. If required, this happens automatically during
1450-
:func:`enable`.
1450+
:func:`enable` (see also :func:`may_move_on_enable`).
14511451
"""
14521452

14531453
@property
@@ -1468,27 +1468,34 @@ def axes(self) -> typing.Mapping[str, StageAxis]:
14681468
"""
14691469
raise NotImplementedError()
14701470

1471-
@property
1472-
def need_homed(self) -> bool:
1473-
"""Boolean flag to say if the stage needs to be homed. Many stages
1474-
need to be driven to their limts at startup to find a repeatable zero
1475-
position and sometimes to find their limits as well.
1476-
1477-
By default this function returns "False". If the stage needs
1478-
to be homed then this function should be overwritten to return
1479-
"True" until the homing operation has been performed.
1480-
Additionaly a stage that needs to be homed should implement a
1481-
home() fucntion that performs the home move, sets limits and
1482-
leaves the stage somewhere sensible. This function should
1483-
also set the need_homed propety to False.
1484-
1485-
Stages that dont need homing can leave this default function
1486-
and dont need to implment the home() function.
1471+
1472+
@abc.abstractmethod
1473+
def may_move_on_enable(self) -> bool:
1474+
"""Whether calling :func:`enable` is likely to make the stage move.
1475+
1476+
Most stages need to be driven to their limits at startup to
1477+
find a repeatable zero position and sometimes to find their
1478+
limits as well. This is typically called "homing".
1479+
1480+
Stages that need to "home" differ on how often they need it
1481+
but they only do it during :func:`enable`. They may need to
1482+
move each time `enable` is called, the first time after the
1483+
`Stage` object has been created, or even only the first time
1484+
since the device was powered up.
1485+
1486+
Note the "*may*" on "may_move_on_enable". This is because it
1487+
can be difficult to know for certain if `enable` will cause
1488+
the stage to home. Still, knowing that the stage *may* move
1489+
is essential for safety. An unexpected movement of the stage,
1490+
particularly large movements such as moving to the stage
1491+
limits, can destroy a sample on the stage --- or even worse,
1492+
it can damage an objective or the stage itself. When in
1493+
doubt, implementations should return `True`.
14871494
14881495
"""
1489-
return False
1496+
raise NotImplementedError()
1497+
14901498

1491-
14921499
@property
14931500
def position(self) -> typing.Mapping[str, float]:
14941501
"""Map of axis name to their current position.

microscope/controllers/zaber.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,9 @@ def _do_enable(self) -> bool:
346346
self._dev_conn.home()
347347
return True
348348

349+
def may_move_on_enable(self) -> bool:
350+
return not self._dev_conn.been_homed()
351+
349352
@property
350353
def axes(self) -> typing.Mapping[str, microscope.abc.StageAxis]:
351354
return self._axes

microscope/stages/ludl.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,6 @@ def __init__(self, port: str, baudrate: int, timeout: float) -> None:
133133
def is_busy(self):
134134
pass
135135

136-
def been_homed(self):
137-
return self.homed
138-
139136
def get_number_axes(self):
140137
return 2
141138

@@ -348,16 +345,22 @@ def _do_enable(self) -> bool:
348345
# Before a device can moved, it first needs to establish a
349346
# reference to the home position. We won't be able to move
350347
# unless we home it first.
348+
if not self.homed:
349+
axes=self.axes
350+
for axis in axes:
351+
self.axes[axis].home()
352+
self.homed = True
351353
return True
352354

355+
356+
def may_move_on_enable(self) -> bool:
357+
return not self.homed
358+
359+
353360
@property
354361
def axes(self) -> typing.Mapping[str, microscope.abc.StageAxis]:
355362
return self._axes
356363

357-
@property
358-
def need_homed(self):
359-
return not self.homed
360-
361364
def move_by(self, delta: typing.Mapping[str, float]) -> None:
362365
"""Move specified axes by the specified distance. """
363366
for axis_name, axis_delta in delta.items():
@@ -375,13 +378,6 @@ def move_to(self, position: typing.Mapping[str, float]) -> None:
375378
)
376379
self._dev_conn.wait_until_idle()
377380

378-
def home(self):
379-
if self.need_homed:
380-
axes=self.axes
381-
for axis in axes:
382-
self.axes[axis].home()
383-
self.homed = True
384-
385381
# def assert_filterwheel_number(self, number: int) -> None:
386382
# assert number > 0 and number < 4
387383

0 commit comments

Comments
 (0)