diff --git a/openflexure_microscope/api/v2/blueprints/actions/__init__.py b/openflexure_microscope/api/v2/blueprints/actions/__init__.py index fbf376fe..e57c2c04 100644 --- a/openflexure_microscope/api/v2/blueprints/actions/__init__.py +++ b/openflexure_microscope/api/v2/blueprints/actions/__init__.py @@ -37,6 +37,11 @@ _actions = { "view_class": stage.MoveStageAPI, "conditions": True, }, + "zeroStage": { + "rule": "/stage/zero/", + "view_class": stage.ZeroStageAPI, + "conditions": True, + }, "shutdown": { "rule": "/system/shutdown/", "view_class": system.ShutdownAPI, diff --git a/openflexure_microscope/api/v2/blueprints/actions/stage.py b/openflexure_microscope/api/v2/blueprints/actions/stage.py index 838ea783..3ea76208 100644 --- a/openflexure_microscope/api/v2/blueprints/actions/stage.py +++ b/openflexure_microscope/api/v2/blueprints/actions/stage.py @@ -56,3 +56,22 @@ class MoveStageAPI(MicroscopeView): logging.warning("Unable to move. No stage found.") return jsonify(self.microscope.status["stage"]["position"]) + + +class ZeroStageAPI(MicroscopeView): + """ + Zero stage coordinates + """ + + def post(self): + """ + Set the current position to zero + + .. :quickref: Actions; Zero stage + + :reqheader Accept: application/json + + """ + self.microscope.stage.zero_position() + + return jsonify(self.microscope.status["stage"]) diff --git a/openflexure_microscope/stage/base.py b/openflexure_microscope/stage/base.py index 4eca632e..45607a77 100644 --- a/openflexure_microscope/stage/base.py +++ b/openflexure_microscope/stage/base.py @@ -74,6 +74,11 @@ class BaseStage(metaclass=ABCMeta): """Make an absolute move to a position""" pass + @abstractmethod + def zero_position(self): + """Set the current position to zero""" + pass + @abstractmethod def close(self): """Cleanly close communication with the stage""" diff --git a/openflexure_microscope/stage/mock.py b/openflexure_microscope/stage/mock.py index bec61bf1..92765ec3 100644 --- a/openflexure_microscope/stage/mock.py +++ b/openflexure_microscope/stage/mock.py @@ -96,5 +96,9 @@ class MockStage(BaseStage): self._position = list(final) logging.debug(f"New position: {self._position}") + def zero_position(self): + """Set the current position to zero""" + self._position = [0, 0, 0] + def close(self): pass diff --git a/openflexure_microscope/stage/sanga.py b/openflexure_microscope/stage/sanga.py index 5588a929..27b192a5 100644 --- a/openflexure_microscope/stage/sanga.py +++ b/openflexure_microscope/stage/sanga.py @@ -147,6 +147,11 @@ class SangaStage(BaseStage): with self.lock: self.board.move_abs(final, **kwargs) + def zero_position(self): + """Set the current position to zero""" + with self.lock: + self.board.zero_position() + def close(self): """Cleanly close communication with the stage""" if hasattr(self, "board"): diff --git a/openflexure_microscope/stage/sangaboard/sangaboard.py b/openflexure_microscope/stage/sangaboard/sangaboard.py index bd97adbb..62008c3d 100644 --- a/openflexure_microscope/stage/sangaboard/sangaboard.py +++ b/openflexure_microscope/stage/sangaboard/sangaboard.py @@ -52,7 +52,7 @@ class Sangaboard(ExtensibleSerialInstrument): # These are the settings for the sangaboards serial port, and can usually be left as default. port_settings = { - "baudrate": 115200, + "baudrate": 115_200, "bytesize": EIGHTBITS, "parity": PARITY_NONE, "stopbits": STOPBITS_ONE, @@ -215,6 +215,10 @@ class Sangaboard(ExtensibleSerialInstrument): """De-energise the stepper motor coils""" self.query("release") + def zero_position(self): + """Set the current position to zero""" + self.query("zero") + def move_abs(self, final, **kwargs): """Make an absolute move to a position