From 394ef15fbe6db3bf4c19a49c744c3b0af2f51d20 Mon Sep 17 00:00:00 2001 From: Joel Collins Date: Thu, 21 Nov 2019 16:05:26 +0000 Subject: [PATCH] Fixed mock stage not moving --- .../api/v2/blueprints/actions/stage.py | 2 ++ openflexure_microscope/stage/mock.py | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/openflexure_microscope/api/v2/blueprints/actions/stage.py b/openflexure_microscope/api/v2/blueprints/actions/stage.py index efd69964..62b98244 100644 --- a/openflexure_microscope/api/v2/blueprints/actions/stage.py +++ b/openflexure_microscope/api/v2/blueprints/actions/stage.py @@ -52,5 +52,7 @@ class MoveStageAPI(MicroscopeView): # Explicitally acquire lock with self.microscope.stage.lock: self.microscope.stage.move_rel(position) + else: + logging.warning("Unable to move. No stage found.") return jsonify(self.microscope.status["stage"]["position"]) diff --git a/openflexure_microscope/stage/mock.py b/openflexure_microscope/stage/mock.py index 7e3be54b..2ed5a745 100644 --- a/openflexure_microscope/stage/mock.py +++ b/openflexure_microscope/stage/mock.py @@ -4,6 +4,7 @@ from openflexure_microscope.utilities import axes_to_array from collections.abc import Iterable import numpy as np import time +import logging class MockStage(BaseStage): @@ -75,20 +76,32 @@ class MockStage(BaseStage): if simulate_time: time.sleep(1) if axis is not None: - # This code just converts single-axis moves into all-axis moves. + assert axis in self.axis_names, "axis must be one of {}".format( self.axis_names ) move = np.zeros(self.n_axes, dtype=np.int) move[np.argmax(np.array(self.axis_names) == axis)] = int(displacement) + displacement = move - self._position = list(np.array(self._position) + np.array(move)) + initial_move = np.array(displacement, dtype=np.int) + + initial_move -= np.where( + self.backlash * displacement < 0, + self.backlash, + np.zeros(self.n_axes, dtype=self.backlash.dtype), + ) + + self._position = list(np.array(self._position) + np.array(initial_move)) + logging.debug(np.array(self._position) + np.array(initial_move)) + logging.debug(f"New position: {self._position}") def move_abs(self, final, simulate_time: bool = True, **kwargs): if simulate_time: time.sleep(1) self._position = list(final) + logging.debug(f"New position: {self._position}") def close(self): pass