Fixed read and apply config dicts
This commit is contained in:
parent
fdbba08b66
commit
f31c28fe52
6 changed files with 42 additions and 25 deletions
|
|
@ -172,7 +172,7 @@ class ConfigAPI(MicroscopeView):
|
||||||
|
|
||||||
logging.debug("Updating settings from POST request.")
|
logging.debug("Updating settings from POST request.")
|
||||||
|
|
||||||
self.microscope.write_config(payload.json)
|
self.microscope.apply_config(payload.json)
|
||||||
self.microscope.save_config()
|
self.microscope.save_config()
|
||||||
|
|
||||||
return jsonify(self.microscope.read_config(json_safe=True))
|
return jsonify(self.microscope.read_config(json_safe=True))
|
||||||
|
|
|
||||||
|
|
@ -144,7 +144,7 @@ class BaseCamera(metaclass=ABCMeta):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def read_config(self):
|
def read_config(self) -> dict:
|
||||||
"""Return the current settings as a dictionary"""
|
"""Return the current settings as a dictionary"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,7 @@ class StreamingCamera(BaseCamera):
|
||||||
self.camera.close()
|
self.camera.close()
|
||||||
|
|
||||||
# HANDLE SETTINGS
|
# HANDLE SETTINGS
|
||||||
def read_config(self):
|
def read_config(self) -> dict:
|
||||||
"""
|
"""
|
||||||
Return config dictionary of the StreamingCamera.
|
Return config dictionary of the StreamingCamera.
|
||||||
"""
|
"""
|
||||||
|
|
@ -119,7 +119,7 @@ class StreamingCamera(BaseCamera):
|
||||||
|
|
||||||
return conf_dict
|
return conf_dict
|
||||||
|
|
||||||
def apply_config(self, config: dict) -> None:
|
def apply_config(self, config: dict):
|
||||||
"""
|
"""
|
||||||
Write a config dictionary to the StreamingCamera config.
|
Write a config dictionary to the StreamingCamera config.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -164,15 +164,11 @@ class Microscope:
|
||||||
|
|
||||||
# If attached to a camera
|
# If attached to a camera
|
||||||
if ('camera_settings' in config) and self.camera:
|
if ('camera_settings' in config) and self.camera:
|
||||||
# Update camera config
|
|
||||||
self.camera.apply_config(config['camera_settings'])
|
self.camera.apply_config(config['camera_settings'])
|
||||||
|
|
||||||
# If attached to a stage
|
# If attached to a stage
|
||||||
if ('stage_settings' in config) and self.stage:
|
if ('stage_settings' in config) and self.stage:
|
||||||
if 'backlash' in config:
|
self.stage.apply_config(config['stage_settings'])
|
||||||
# Construct backlash array
|
|
||||||
backlash = axes_to_array(config['backlash'], ['x', 'y', 'z'], [0, 0, 0])
|
|
||||||
self.stage.backlash = backlash
|
|
||||||
|
|
||||||
# Todo: tidy up with some loopy goodness
|
# Todo: tidy up with some loopy goodness
|
||||||
if 'id' in config:
|
if 'id' in config:
|
||||||
|
|
@ -208,21 +204,8 @@ class Microscope:
|
||||||
settings_current['camera_settings'] = settings_current_camera
|
settings_current['camera_settings'] = settings_current_camera
|
||||||
|
|
||||||
# If attached to a stage
|
# If attached to a stage
|
||||||
# TODO: Offload to stage object
|
|
||||||
if self.stage:
|
if self.stage:
|
||||||
if hasattr(self.stage.backlash, 'tolist'):
|
settings_current_stage = self.stage.read_config()
|
||||||
backlash = self.stage.backlash.tolist()
|
|
||||||
else:
|
|
||||||
backlash = self.stage.backlash
|
|
||||||
|
|
||||||
settings_current_stage = {
|
|
||||||
'backlash': {
|
|
||||||
'x': backlash[0],
|
|
||||||
'y': backlash[1],
|
|
||||||
'z': backlash[2],
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
settings_current['stage_settings'] = settings_current_stage
|
settings_current['stage_settings'] = settings_current_stage
|
||||||
|
|
||||||
settings_full = self.settings_file.merge(settings_current)
|
settings_full = self.settings_file.merge(settings_current)
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,16 @@ class BaseStage(metaclass=ABCMeta):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.lock = StrictLock(timeout=5)
|
self.lock = StrictLock(timeout=5)
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def apply_config(self, config: dict):
|
||||||
|
"""Update settings from a config dictionary"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
|
def read_config(self):
|
||||||
|
"""Return the current settings as a dictionary"""
|
||||||
|
pass
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def state(self):
|
def state(self):
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import logging
|
||||||
from collections.abc import Iterable
|
from collections.abc import Iterable
|
||||||
from .sangaboard import Sangaboard
|
from .sangaboard import Sangaboard
|
||||||
from openflexure_microscope.stage.base import BaseStage
|
from openflexure_microscope.stage.base import BaseStage
|
||||||
|
from openflexure_microscope.utilities import axes_to_array
|
||||||
|
|
||||||
|
|
||||||
class SangaStage(BaseStage):
|
class SangaStage(BaseStage):
|
||||||
|
|
@ -22,8 +23,9 @@ class SangaStage(BaseStage):
|
||||||
BaseStage.__init__(self)
|
BaseStage.__init__(self)
|
||||||
|
|
||||||
self.board = Sangaboard(port, **kwargs)
|
self.board = Sangaboard(port, **kwargs)
|
||||||
self._backlash = None
|
|
||||||
self.axis_names = ['x', 'y', 'z']
|
self._backlash = None # Initialise backlash storage, used by property setter/getter
|
||||||
|
self.axis_names = ['x', 'y', 'z'] # Assume all sangaboards are 3 axis
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
|
|
@ -80,6 +82,28 @@ class SangaStage(BaseStage):
|
||||||
else:
|
else:
|
||||||
self._backlash = np.array([int(blsh)]*self.n_axes, dtype=np.int)
|
self._backlash = np.array([int(blsh)]*self.n_axes, dtype=np.int)
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
def move_rel(self, displacement, axis=None, backlash=True):
|
def move_rel(self, displacement, axis=None, backlash=True):
|
||||||
"""Make a relative move, optionally correcting for backlash.
|
"""Make a relative move, optionally correcting for backlash.
|
||||||
displacement: integer or array/list of 3 integers
|
displacement: integer or array/list of 3 integers
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue