Implemented new JSON response handler
This commit is contained in:
parent
6a498eb4eb
commit
81636aa6e9
1 changed files with 16 additions and 22 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
from openflexure_microscope.api.utilities import parse_payload, get_from_payload, gen, get_bool
|
from openflexure_microscope.api.utilities import parse_payload, get_from_payload, gen, get_bool, axes_to_array, JsonResponse
|
||||||
from openflexure_microscope.api.v1.views import MicroscopeView
|
from openflexure_microscope.api.v1.views import MicroscopeView
|
||||||
|
|
||||||
from flask import Response, Blueprint, jsonify, request
|
from flask import Response, Blueprint, jsonify, request
|
||||||
|
|
@ -55,25 +55,23 @@ class PositionAPI(MicroscopeView):
|
||||||
:<json int z: z steps
|
:<json int z: z steps
|
||||||
|
|
||||||
"""
|
"""
|
||||||
# Get payload
|
# Create response object
|
||||||
state = parse_payload(request)
|
response = JsonResponse(request)
|
||||||
logging.debug(state)
|
logging.debug(response.json)
|
||||||
|
|
||||||
# Construct position array
|
# Construct position array
|
||||||
position = [0, 0, 0]
|
position = [0, 0, 0]
|
||||||
|
|
||||||
# Handle absolute positioning
|
# Handle absolute positioning (calculate a relative move from current position and target)
|
||||||
if 'absolute' in state and state['absolute'] is True:
|
if response.param('absolute') is True:
|
||||||
# Get coordinates from payload
|
target_position = axes_to_array(response.json, ['x', 'y', 'z'])
|
||||||
for axis, key in enumerate(['x', 'y', 'z']):
|
logging.debug("TARGET: {}".format(target_position))
|
||||||
if key in state:
|
position = [target_position[i] - self.microscope.stage.position[i] for i in range(3)]
|
||||||
position[axis] = int(state[key]-self.microscope.stage.position[axis])
|
logging.debug("DELTA: {}".format(position))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Get coordinates from payload
|
# Get coordinates from payload
|
||||||
for axis, key in enumerate(['x', 'y', 'z']):
|
position = axes_to_array(response.json, ['x', 'y', 'z'], [0, 0, 0])
|
||||||
if key in state:
|
|
||||||
position[axis] = int(state[key])
|
|
||||||
|
|
||||||
logging.debug(position)
|
logging.debug(position)
|
||||||
|
|
||||||
|
|
@ -130,18 +128,14 @@ class StageParamsAPI(MicroscopeView):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
# Get payload
|
# Get payload
|
||||||
state = parse_payload(request)
|
response = JsonResponse(request)
|
||||||
logging.debug(state)
|
logging.debug(response.json)
|
||||||
|
|
||||||
# BACKLASH
|
# BACKLASH
|
||||||
if 'backlash' in state:
|
if response.param('backlash'):
|
||||||
# Construct backlash array
|
# Construct backlash array
|
||||||
backlash = [0, 0, 0]
|
backlash = axes_to_array(response.param('backlash'), ['x', 'y', 'z'], [0, 0, 0])
|
||||||
|
logging.debug("BACKLASH: {}".format(backlash))
|
||||||
# Get backlash coordinates from payload
|
|
||||||
for axis, key in enumerate(['x', 'y', 'z']):
|
|
||||||
if key in state['backlash']:
|
|
||||||
backlash[axis] = int(state['backlash'][key])
|
|
||||||
|
|
||||||
# Apply backlash
|
# Apply backlash
|
||||||
self.microscope.stage.backlash = backlash
|
self.microscope.stage.backlash = backlash
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue