From a1f27b00911d18b501e73d9c6a357f2d076b8c66 Mon Sep 17 00:00:00 2001 From: samuelmcdermott Date: Sun, 11 Oct 2020 00:59:11 +0100 Subject: [PATCH 01/10] Move set_stage into a new function --- openflexure_microscope/microscope.py | 66 ++++++++++++++++++++-------- 1 file changed, 48 insertions(+), 18 deletions(-) diff --git a/openflexure_microscope/microscope.py b/openflexure_microscope/microscope.py index 32b75ff2..9e9e1e3f 100644 --- a/openflexure_microscope/microscope.py +++ b/openflexure_microscope/microscope.py @@ -105,24 +105,8 @@ class Microscope: logging.warning("No compatible camera hardware found.") ### Stage - logging.info("Creating stage") - if configuration.get("stage"): - stage_type = configuration["stage"].get("type") - stage_port = configuration["stage"].get("port") - if stage_type in ("SangaBoard", "SangaStage"): - try: - logging.info("Trying SangaStage") - self.stage = SangaStage(port=stage_port) - except Exception as e: - logging.error(e) - logging.warning("No compatible Sangaboard hardware found.") - elif stage_type in ("SangaDeltaStage"): - try: - logging.info("Trying SangaDeltaStage") - self.stage = SangaDeltaStage(port=stage_port) - except Exception as e: - logging.error(e) - logging.warning("No compatible Sangaboard hardware found.") + self.set_stage(configuration=configuration) + logging.info("Handling fallbacks") ### Fallbacks @@ -138,6 +122,51 @@ class Microscope: if hasattr(self.stage, "lock"): self.lock.locks.append(self.stage.lock) + def set_stage(self, configuration=None, stage_type=None): + """ + Set or change the stage geometry + """ + if not configuration: + configuration = self.configuration + + if stage_type: + if stage_type == configuration["stage"].get("type"): + logging.info("Stage already set to that stage type") + return + else: + stage_type = configuration["stage"].get("type") + + ### Close any existing stages + if self.stage: + stage_port = self.stage.port + self.stage.close() + + + logging.info("Setting stage") + stage_port = configuration["stage"].get("port") + + if stage_type in ("SangaBoard", "SangaStage"): + try: + logging.info("Trying SangaStage") + self.stage = SangaStage(port=stage_port) + except Exception as e: + logging.error(e) + logging.warning("No compatible Sangaboard hardware found.") + elif stage_type in ("SangaDeltaStage"): + try: + logging.info("Trying SangaDeltaStage") + self.stage = SangaDeltaStage(port=stage_port) + + except Exception as e: + logging.error(e) + logging.warning("No compatible Sangaboard hardware found.") + else: + logging.warning("The stage type is incorrectly defined.") + + logging.info("Saving new stage type configuration") + configuration["stage"]["type"] = stage_type + self.configuration_file.save(configuration) + def has_real_stage(self) -> bool: """ Check if a real (non-mock) stage is currently attached. @@ -363,6 +392,7 @@ class Microscope: # Capture to output object logging.info(f"Starting microscope capture {output.file}") + print(output) self.camera.capture( output, use_video_port=use_video_port, From 79f3104409d19fed5a35529995ee82d848f6aac8 Mon Sep 17 00:00:00 2001 From: samuelmcdermott Date: Sun, 11 Oct 2020 01:01:21 +0100 Subject: [PATCH 02/10] Add API to set the stage --- .../api/v2/views/actions/__init__.py | 5 +++++ .../api/v2/views/actions/stage.py | 15 +++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/openflexure_microscope/api/v2/views/actions/__init__.py b/openflexure_microscope/api/v2/views/actions/__init__.py index 1c26e31a..8a740316 100644 --- a/openflexure_microscope/api/v2/views/actions/__init__.py +++ b/openflexure_microscope/api/v2/views/actions/__init__.py @@ -39,6 +39,11 @@ _actions = { "view_class": stage.ZeroStageAPI, "conditions": True, }, + "setStage": { + "rule" : "/stage/set/", + "view_class": stage.SetStageAPI, + "conditions": True, + }, "shutdown": { "rule": "/system/shutdown/", "view_class": system.ShutdownAPI, diff --git a/openflexure_microscope/api/v2/views/actions/stage.py b/openflexure_microscope/api/v2/views/actions/stage.py index cb26823f..d037cc9c 100644 --- a/openflexure_microscope/api/v2/views/actions/stage.py +++ b/openflexure_microscope/api/v2/views/actions/stage.py @@ -65,3 +65,18 @@ class ZeroStageAPI(ActionView): # TODO: Make schema for microscope state return microscope.state["stage"] + +class SetStageAPI(ActionView): + args = { + "stage_type": fields.String(missing = None, example = "SangaStage", description = "The stage geometry [SangaStage, SangaDeltaStage]") + } + def post(self,args): + """ + Set the stage geometry. + """ + microscope = find_component("org.openflexure.microscope") + microscope.set_stage(stage_type=args.get("stage_type")) + + # TODO: Make schema for microscope state + return microscope.state["stage"] + From 81ca2c9cb164f457917e7fdfb37ce241b3e2b380 Mon Sep 17 00:00:00 2001 From: samuelmcdermott Date: Mon, 12 Oct 2020 01:23:44 +0100 Subject: [PATCH 03/10] Add a get route for the stage type and rename --- .../api/v2/views/actions/__init__.py | 4 ++-- openflexure_microscope/api/v2/views/actions/stage.py | 11 +++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/openflexure_microscope/api/v2/views/actions/__init__.py b/openflexure_microscope/api/v2/views/actions/__init__.py index 8a740316..9a5e08d2 100644 --- a/openflexure_microscope/api/v2/views/actions/__init__.py +++ b/openflexure_microscope/api/v2/views/actions/__init__.py @@ -40,8 +40,8 @@ _actions = { "conditions": True, }, "setStage": { - "rule" : "/stage/set/", - "view_class": stage.SetStageAPI, + "rule" : "/stage/type/", + "view_class": stage.StageTypeAPI, "conditions": True, }, "shutdown": { diff --git a/openflexure_microscope/api/v2/views/actions/stage.py b/openflexure_microscope/api/v2/views/actions/stage.py index d037cc9c..c805d7e9 100644 --- a/openflexure_microscope/api/v2/views/actions/stage.py +++ b/openflexure_microscope/api/v2/views/actions/stage.py @@ -66,7 +66,7 @@ class ZeroStageAPI(ActionView): # TODO: Make schema for microscope state return microscope.state["stage"] -class SetStageAPI(ActionView): +class StageTypeAPI(ActionView): args = { "stage_type": fields.String(missing = None, example = "SangaStage", description = "The stage geometry [SangaStage, SangaDeltaStage]") } @@ -78,5 +78,12 @@ class SetStageAPI(ActionView): microscope.set_stage(stage_type=args.get("stage_type")) # TODO: Make schema for microscope state - return microscope.state["stage"] + return microscope.configuration["stage"]["type"] + + def get(self): + """ + Get the stage geometry. + """ + microscope = find_component("org.openflexure.microscope") + return microscope.configuration["stage"]["type"] From b25e7b75e04ebd769553a11e1afeb0dc97e32195 Mon Sep 17 00:00:00 2001 From: samuelmcdermott Date: Mon, 12 Oct 2020 01:28:41 +0100 Subject: [PATCH 04/10] Add Vue component for changing the stage type via API --- .../settingsComponents/stageSettings.vue | 78 +++++++++++++++++++ .../viewComponents/settingsDisplay.vue | 26 ++++++- 2 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 openflexure_microscope/api/static/src/components/viewComponents/settingsComponents/stageSettings.vue diff --git a/openflexure_microscope/api/static/src/components/viewComponents/settingsComponents/stageSettings.vue b/openflexure_microscope/api/static/src/components/viewComponents/settingsComponents/stageSettings.vue new file mode 100644 index 00000000..9923e353 --- /dev/null +++ b/openflexure_microscope/api/static/src/components/viewComponents/settingsComponents/stageSettings.vue @@ -0,0 +1,78 @@ + + + + + diff --git a/openflexure_microscope/api/static/src/components/viewComponents/settingsDisplay.vue b/openflexure_microscope/api/static/src/components/viewComponents/settingsDisplay.vue index 60cd1e0a..4db2a467 100644 --- a/openflexure_microscope/api/static/src/components/viewComponents/settingsDisplay.vue +++ b/openflexure_microscope/api/static/src/components/viewComponents/settingsDisplay.vue @@ -44,6 +44,19 @@ Camera +
  • + + Stage + +
  • + +
    + +
    +
    + Date: Mon, 12 Oct 2020 16:56:25 +0100 Subject: [PATCH 05/10] stage API returns a dict --- openflexure_microscope/api/v2/views/actions/stage.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/openflexure_microscope/api/v2/views/actions/stage.py b/openflexure_microscope/api/v2/views/actions/stage.py index c805d7e9..525a1d5b 100644 --- a/openflexure_microscope/api/v2/views/actions/stage.py +++ b/openflexure_microscope/api/v2/views/actions/stage.py @@ -76,14 +76,12 @@ class StageTypeAPI(ActionView): """ microscope = find_component("org.openflexure.microscope") microscope.set_stage(stage_type=args.get("stage_type")) - - # TODO: Make schema for microscope state - return microscope.configuration["stage"]["type"] + return {"stage_type": microscope.configuration["stage"]["type"]} def get(self): """ Get the stage geometry. """ microscope = find_component("org.openflexure.microscope") - return microscope.configuration["stage"]["type"] + return {"stage_type": microscope.configuration["stage"]["type"]} From e886e9db28cd7c194695056ab6ea7363b0643761 Mon Sep 17 00:00:00 2001 From: samuelmcdermott Date: Mon, 12 Oct 2020 16:56:58 +0100 Subject: [PATCH 06/10] change vue to use a task submitter for setting stage --- .../settingsComponents/stageSettings.vue | 55 +++++++++++-------- 1 file changed, 33 insertions(+), 22 deletions(-) diff --git a/openflexure_microscope/api/static/src/components/viewComponents/settingsComponents/stageSettings.vue b/openflexure_microscope/api/static/src/components/viewComponents/settingsComponents/stageSettings.vue index 9923e353..4556a316 100644 --- a/openflexure_microscope/api/static/src/components/viewComponents/settingsComponents/stageSettings.vue +++ b/openflexure_microscope/api/static/src/components/viewComponents/settingsComponents/stageSettings.vue @@ -6,10 +6,24 @@ @@ -21,10 +35,15 @@