diff --git a/openflexure_microscope/stage/mock.py b/openflexure_microscope/stage/mock.py index 345d822f..0c2ddfec 100644 --- a/openflexure_microscope/stage/mock.py +++ b/openflexure_microscope/stage/mock.py @@ -1,5 +1,8 @@ from openflexure_microscope.stage.base import BaseStage +from openflexure_microscope.utilities import axes_to_array +from collections.abc import Iterable +import numpy as np class MockStage(BaseStage): def __init__(self, port=None, **kwargs): @@ -22,6 +25,27 @@ class MockStage(BaseStage): } return state + def apply_config(self, config: dict): + """Update settings from a config dictionary""" + + # Set backlash. Expects a dictionary with axis labels + if 'backlash' in config: + # Construct backlash array + backlash = axes_to_array(config['backlash'], ['x', 'y', 'z'], [0, 0, 0]) + self.backlash = backlash + + def read_config(self) -> dict: + """Return the current settings as a dictionary""" + blsh = self.backlash.tolist() + config = { + 'backlash': { + 'x': blsh[0], + 'y': blsh[1], + 'z': blsh[2], + } + } + return config + @property def n_axes(self): return self._n_axis @@ -32,14 +56,20 @@ class MockStage(BaseStage): @property def backlash(self): - return self._backlash if self._backlash else [0]*self.n_axes + if self._backlash is not None: + return self._backlash + else: + return np.array([0] * self.n_axes) @backlash.setter def backlash(self, blsh): if blsh is None: self._backlash = None - assert len(blsh) == self.n_axes - self._backlash = [int(blsh)]*self.n_axes + elif isinstance(blsh, Iterable): + assert len(blsh) == self.n_axes + self._backlash = np.array(blsh) + else: + self._backlash = np.array([int(blsh)]*self.n_axes, dtype=np.int) def move_rel(self, displacement, axis=None, backlash=True): pass