Fixed mock stage not moving
This commit is contained in:
parent
dc99a12985
commit
394ef15fbe
2 changed files with 17 additions and 2 deletions
|
|
@ -52,5 +52,7 @@ class MoveStageAPI(MicroscopeView):
|
||||||
# Explicitally acquire lock
|
# Explicitally acquire lock
|
||||||
with self.microscope.stage.lock:
|
with self.microscope.stage.lock:
|
||||||
self.microscope.stage.move_rel(position)
|
self.microscope.stage.move_rel(position)
|
||||||
|
else:
|
||||||
|
logging.warning("Unable to move. No stage found.")
|
||||||
|
|
||||||
return jsonify(self.microscope.status["stage"]["position"])
|
return jsonify(self.microscope.status["stage"]["position"])
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ from openflexure_microscope.utilities import axes_to_array
|
||||||
from collections.abc import Iterable
|
from collections.abc import Iterable
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import time
|
import time
|
||||||
|
import logging
|
||||||
|
|
||||||
|
|
||||||
class MockStage(BaseStage):
|
class MockStage(BaseStage):
|
||||||
|
|
@ -75,20 +76,32 @@ class MockStage(BaseStage):
|
||||||
if simulate_time:
|
if simulate_time:
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
if axis is not None:
|
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(
|
assert axis in self.axis_names, "axis must be one of {}".format(
|
||||||
self.axis_names
|
self.axis_names
|
||||||
)
|
)
|
||||||
move = np.zeros(self.n_axes, dtype=np.int)
|
move = np.zeros(self.n_axes, dtype=np.int)
|
||||||
move[np.argmax(np.array(self.axis_names) == axis)] = int(displacement)
|
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):
|
def move_abs(self, final, simulate_time: bool = True, **kwargs):
|
||||||
if simulate_time:
|
if simulate_time:
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
self._position = list(final)
|
self._position = list(final)
|
||||||
|
logging.debug(f"New position: {self._position}")
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
pass
|
pass
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue