Moved setting and getting stage config into root microscope config
This commit is contained in:
parent
55c3014d26
commit
9c488279d2
3 changed files with 19 additions and 76 deletions
|
|
@ -176,6 +176,7 @@ class ConfigAPI(MicroscopeView):
|
|||
|
||||
return jsonify(self.microscope.config)
|
||||
|
||||
|
||||
def construct_blueprint(microscope_obj):
|
||||
|
||||
blueprint = Blueprint('base_blueprint', __name__)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
from openflexure_microscope.api.utilities import gen, axes_to_array, JsonPayload
|
||||
from openflexure_microscope.api.utilities import gen, JsonPayload
|
||||
from openflexure_microscope.api.v1.views import MicroscopeView
|
||||
from openflexure_microscope.utilities import axes_to_array
|
||||
|
||||
from flask import Response, Blueprint, jsonify, request
|
||||
|
||||
|
|
@ -80,69 +81,6 @@ class PositionAPI(MicroscopeView):
|
|||
return jsonify(self.microscope.state['stage']['position'])
|
||||
|
||||
|
||||
class StageParamsAPI(MicroscopeView):
|
||||
|
||||
def get(self):
|
||||
"""
|
||||
Return current parameters of the stage.
|
||||
|
||||
.. :quickref: Stage params; Get current stage parameters
|
||||
|
||||
**Example request**:
|
||||
|
||||
.. sourcecode:: http
|
||||
|
||||
GET /stage/params HTTP/1.1
|
||||
Accept: application/json
|
||||
|
||||
**Example response**:
|
||||
|
||||
.. sourcecode:: http
|
||||
|
||||
HTTP/1.1 200 OK
|
||||
Vary: Accept
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"backlash": {
|
||||
"x": 0,
|
||||
"y": 0,
|
||||
"z": 128
|
||||
},
|
||||
}
|
||||
|
||||
"""
|
||||
|
||||
return jsonify(self.microscope.state['stage'])
|
||||
|
||||
def post(self):
|
||||
"""
|
||||
Set parameters of the stage.
|
||||
|
||||
.. :quickref: Stage params; Set current stage parameters
|
||||
|
||||
:reqheader Accept: application/json
|
||||
:<json json backlash: - **x** *(int)*: x-axis backlash in steps
|
||||
- **y** *(int)*: y-axis backlash in steps
|
||||
- **z** *(int)*: x-axis backlash in steps
|
||||
|
||||
"""
|
||||
# Get payload
|
||||
payload = JsonPayload(request)
|
||||
logging.debug(payload.json)
|
||||
|
||||
# BACKLASH
|
||||
if payload.param('backlash'):
|
||||
# Construct backlash array
|
||||
backlash = axes_to_array(payload.param('backlash'), ['x', 'y', 'z'], [0, 0, 0])
|
||||
logging.debug("BACKLASH: {}".format(backlash))
|
||||
|
||||
# Apply backlash
|
||||
self.microscope.stage.backlash = backlash
|
||||
|
||||
return jsonify(self.microscope.state['stage'])
|
||||
|
||||
|
||||
def construct_blueprint(microscope_obj):
|
||||
|
||||
blueprint = Blueprint('stage_blueprint', __name__)
|
||||
|
|
@ -152,9 +90,4 @@ def construct_blueprint(microscope_obj):
|
|||
view_func=PositionAPI.as_view('position', microscope=microscope_obj)
|
||||
)
|
||||
|
||||
blueprint.add_url_rule(
|
||||
'/params',
|
||||
view_func=StageParamsAPI.as_view('stage_params', microscope=microscope_obj)
|
||||
)
|
||||
|
||||
return(blueprint)
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ from .camera.pi import StreamingCamera
|
|||
|
||||
from .plugins import PluginMount
|
||||
from .config import load_config, save_config, convert_config
|
||||
from .utilities import axes_to_array
|
||||
|
||||
|
||||
class Microscope(object):
|
||||
|
|
@ -141,13 +142,6 @@ class Microscope(object):
|
|||
'z': position[2],
|
||||
}
|
||||
|
||||
backlash = self.stage.backlash.tolist()
|
||||
state['stage']['backlash'] = {
|
||||
'x': backlash[0],
|
||||
'y': backlash[1],
|
||||
'z': backlash[2],
|
||||
}
|
||||
|
||||
# Add camera state
|
||||
state['camera'] = self.camera.state
|
||||
|
||||
|
|
@ -160,6 +154,14 @@ class Microscope(object):
|
|||
# Update camera config params from StreamingCamera object
|
||||
self._config.update(self.camera.config)
|
||||
|
||||
# If attached to a stage
|
||||
backlash = self.stage.backlash.tolist()
|
||||
self._config['backlash'] = {
|
||||
'x': backlash[0],
|
||||
'y': backlash[1],
|
||||
'z': backlash[2],
|
||||
}
|
||||
|
||||
return self._config
|
||||
|
||||
@config.setter
|
||||
|
|
@ -169,5 +171,12 @@ class Microscope(object):
|
|||
# Update camera config
|
||||
self.camera.config = config
|
||||
|
||||
# If attached to a stage
|
||||
if self.stage:
|
||||
if 'backlash' in config:
|
||||
# Construct backlash array
|
||||
backlash = axes_to_array(config['backlash'], ['x', 'y', 'z'], [0, 0, 0])
|
||||
self.stage.backlash = backlash
|
||||
|
||||
# Cache config
|
||||
self._config.update(config)
|
||||
Loading…
Add table
Add a link
Reference in a new issue