Code cleanup
This commit is contained in:
parent
2bfb988460
commit
994e83dbeb
46 changed files with 261 additions and 318 deletions
|
|
@ -17,36 +17,30 @@ class BaseStage(metaclass=ABCMeta):
|
|||
@abstractmethod
|
||||
def update_settings(self, config: dict):
|
||||
"""Update settings from a config dictionary"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def read_settings(self):
|
||||
"""Return the current settings as a dictionary"""
|
||||
pass
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def state(self):
|
||||
"""The general state dictionary of the board."""
|
||||
pass
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def configuration(self):
|
||||
"""The general stage configuration."""
|
||||
pass
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def n_axes(self):
|
||||
"""The number of axes this stage has."""
|
||||
pass
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def position(self):
|
||||
"""The current position, as a list"""
|
||||
pass
|
||||
|
||||
@property
|
||||
def position_map(self):
|
||||
|
|
@ -56,36 +50,30 @@ class BaseStage(metaclass=ABCMeta):
|
|||
@abstractmethod
|
||||
def backlash(self):
|
||||
"""Get the distance used for backlash compensation."""
|
||||
pass
|
||||
|
||||
@backlash.setter
|
||||
@abstractmethod
|
||||
def backlash(self):
|
||||
"""Set the distance used for backlash compensation."""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def move_rel(self, displacement, backlash=True):
|
||||
def move_rel(self, displacement: list, axis=None, backlash=True):
|
||||
"""Make a relative move, optionally correcting for backlash.
|
||||
displacement: integer or array/list of 3 integers
|
||||
backlash: (default: True) whether to correct for backlash.
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def move_abs(self, final, **kwargs):
|
||||
"""Make an absolute move to a position"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def zero_position(self):
|
||||
"""Set the current position to zero"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def close(self):
|
||||
"""Cleanly close communication with the stage"""
|
||||
pass
|
||||
|
||||
def scan_linear(self, rel_positions, backlash=True, return_to_start=True):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ from openflexure_microscope.utilities import axes_to_array
|
|||
|
||||
|
||||
class MissingStage(BaseStage):
|
||||
def __init__(self, port=None, **kwargs):
|
||||
def __init__(self, *args, **kwargs): # pylint: disable=unused-argument
|
||||
BaseStage.__init__(self)
|
||||
self._position = [0, 0, 0]
|
||||
self._n_axis = 3
|
||||
|
|
@ -66,11 +66,8 @@ class MissingStage(BaseStage):
|
|||
else:
|
||||
self._backlash = np.array([int(blsh)] * self.n_axes, dtype=np.int)
|
||||
|
||||
def move_rel(
|
||||
self, displacement: list, axis=None, backlash=True, simulate_time: bool = True
|
||||
):
|
||||
if simulate_time:
|
||||
time.sleep(0.5)
|
||||
def move_rel(self, displacement: list, axis=None, backlash=True):
|
||||
time.sleep(0.5)
|
||||
if axis is not None:
|
||||
assert axis in self.axis_names, "axis must be one of {}".format(
|
||||
self.axis_names
|
||||
|
|
@ -83,14 +80,13 @@ class MissingStage(BaseStage):
|
|||
|
||||
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}")
|
||||
logging.debug("New position: %s", self._position)
|
||||
|
||||
def move_abs(self, final, simulate_time: bool = True, **kwargs):
|
||||
if simulate_time:
|
||||
time.sleep(0.5)
|
||||
def move_abs(self, final, **kwargs):
|
||||
time.sleep(0.5)
|
||||
|
||||
self._position = list(final)
|
||||
logging.debug(f"New position: {self._position}")
|
||||
logging.debug("New position: %s", self._position)
|
||||
|
||||
def zero_position(self):
|
||||
"""Set the current position to zero"""
|
||||
|
|
|
|||
|
|
@ -29,10 +29,12 @@ class SangaStage(BaseStage):
|
|||
self.board = Sangaboard(port, **kwargs)
|
||||
|
||||
self._backlash = (
|
||||
None
|
||||
) # Initialise backlash storage, used by property setter/getter
|
||||
None # Initialise backlash storage, used by property setter/getter
|
||||
)
|
||||
self.axis_names = ["x", "y", "z"] # Assume all sangaboards are 3 axis
|
||||
|
||||
self._position_on_enter = None
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
"""The general state dictionary of the board."""
|
||||
|
|
@ -111,7 +113,7 @@ class SangaStage(BaseStage):
|
|||
backlash: (default: True) whether to correct for backlash.
|
||||
"""
|
||||
with self.lock:
|
||||
logging.debug(f"Moving sangaboard by {displacement}")
|
||||
logging.debug("Moving sangaboard by %s", displacement)
|
||||
if not backlash or self.backlash is None:
|
||||
return self.board.move_rel(displacement, axis=axis)
|
||||
if axis is not None:
|
||||
|
|
@ -148,7 +150,7 @@ class SangaStage(BaseStage):
|
|||
"""Make an absolute move to a position
|
||||
"""
|
||||
with self.lock:
|
||||
logging.debug(f"Moving sangaboard to {final}")
|
||||
logging.debug("Moving sangaboard to %s", final)
|
||||
self.board.move_abs(final, **kwargs)
|
||||
|
||||
def zero_position(self):
|
||||
|
|
@ -171,12 +173,12 @@ class SangaStage(BaseStage):
|
|||
self._position_on_enter = self.position
|
||||
return self
|
||||
|
||||
def __exit__(self, type, value, traceback):
|
||||
def __exit__(self, type_, value, traceback):
|
||||
"""The end of the with statement. Reset position if it went wrong.
|
||||
NB the instrument is closed when the object is deleted, so we don't
|
||||
need to worry about that here.
|
||||
"""
|
||||
if type is not None:
|
||||
if type_ is not None:
|
||||
print(
|
||||
"An exception occurred inside a with block, resetting position \
|
||||
to its value at the start of the with block"
|
||||
|
|
@ -184,7 +186,7 @@ class SangaStage(BaseStage):
|
|||
try:
|
||||
time.sleep(0.5)
|
||||
self.move_abs(self._position_on_enter)
|
||||
except Exception as e:
|
||||
except Exception as e: # pylint: disable=W0703
|
||||
print(
|
||||
"A further exception occurred when resetting position: {}".format(e)
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue