From 0dff9b6b398dbd0f2246b762146133ea794961c0 Mon Sep 17 00:00:00 2001 From: Joel Collins Date: Tue, 22 Jan 2019 14:47:11 +0000 Subject: [PATCH] Enable web UI to run when no stage is connected --- openflexure_microscope/api/templates/index_v1.html | 2 +- openflexure_microscope/api/v1/blueprints/stage.py | 6 ++++-- openflexure_microscope/microscope.py | 12 ++++++++++-- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/openflexure_microscope/api/templates/index_v1.html b/openflexure_microscope/api/templates/index_v1.html index 7cfadefb..8894de55 100644 --- a/openflexure_microscope/api/templates/index_v1.html +++ b/openflexure_microscope/api/templates/index_v1.html @@ -26,7 +26,7 @@

- +

diff --git a/openflexure_microscope/api/v1/blueprints/stage.py b/openflexure_microscope/api/v1/blueprints/stage.py index 12b215f5..1b816150 100644 --- a/openflexure_microscope/api/v1/blueprints/stage.py +++ b/openflexure_microscope/api/v1/blueprints/stage.py @@ -67,7 +67,7 @@ class PositionAPI(MicroscopeView): position = [0, 0, 0] # Handle absolute positioning (calculate a relative move from current position and target) - if payload.param('absolute') is True: + if (payload.param('absolute') is True) and (self.microscope.stage): # Only if stage exists target_position = axes_to_array(payload.json, ['x', 'y', 'z']) logging.debug("TARGET: {}".format(target_position)) position = [target_position[i] - self.microscope.stage.position[i] for i in range(3)] @@ -79,7 +79,9 @@ class PositionAPI(MicroscopeView): logging.debug(position) - self.microscope.stage.move_rel(position) + # Move if stage exists + if self.microscope.stage: + self.microscope.stage.move_rel(position) out = filter_dict(self.microscope.state, ('stage', 'position')) diff --git a/openflexure_microscope/microscope.py b/openflexure_microscope/microscope.py index eb36efd6..0bad079d 100644 --- a/openflexure_microscope/microscope.py +++ b/openflexure_microscope/microscope.py @@ -138,7 +138,11 @@ class Microscope(object): } # Add stage position - position = self.stage.position + if self.stage: # If stage exists, populate with real values + position = self.stage.position + else: # Else, zero + position = [0, 0, 0] + state['stage']['position'] = { 'x': position[0], 'y': position[1], @@ -158,7 +162,11 @@ class Microscope(object): self._config.update(self.camera.config) # If attached to a stage - backlash = self.stage.backlash.tolist() + if self.stage: + backlash = self.stage.backlash.tolist() + else: + backlash = [0, 0, 0] + self._config['backlash'] = { 'x': backlash[0], 'y': backlash[1],