diff --git a/config_schema/camera.schema.json b/config_schema/camera.schema.json index a50ab80..9dbbefe 100644 --- a/config_schema/camera.schema.json +++ b/config_schema/camera.schema.json @@ -31,6 +31,16 @@ "objective": { "type": "number", "description": "If there is a optical magnifier, specify the zooming factor of the objective." + }, + "shutter": { + "allOf": [ + { + "$ref": "instrument.schema.json" + }, + { + "description": "A shutter from https://github.com/Ledger-Donjon/shutter-controller." + } + ] } }, "oneOf": [ diff --git a/laserstudio/instruments/camera.py b/laserstudio/instruments/camera.py index 4f4f0c3..2ee4f29 100644 --- a/laserstudio/instruments/camera.py +++ b/laserstudio/instruments/camera.py @@ -4,6 +4,7 @@ from typing import Optional, Literal, cast from ..utils.util import yaml_to_qtransform, qtransform_to_yaml from .instrument import Instrument +from .shutter import ShutterInstrument class CameraInstrument(Instrument): @@ -39,6 +40,11 @@ def __init__(self, config: dict): # Correction matrix self.correction_matrix: Optional[QTransform] = None + # Shutter + shutter = config.get("shutter") + if shutter is not None: + self.shutter = ShutterInstrument(shutter) + def select_objective(self, factor: float): """Select an objective with a magnifying factor. diff --git a/laserstudio/instruments/shutter.py b/laserstudio/instruments/shutter.py new file mode 100644 index 0000000..dda17dc --- /dev/null +++ b/laserstudio/instruments/shutter.py @@ -0,0 +1,23 @@ +from pystages import Tic, TicDirection, Vector +from .instrument import Instrument + + +class ShutterInstrument(Instrument): + def __init__(self, config: dict): + super().__init__(config=config) + self.tic = Tic() + self.tic.exit_safe_start() + self.tic.go_home(TicDirection.FORWARD) + self.__open = True # Open after homing + + @property + def open(self) -> bool: + return self.__open + + @open.setter + def open(self, value: bool): + if type(value) is not bool: + raise ValueError("Expected bool") + if value != self.__open: + self.tic.position = Vector({False: -106, True: 0}[value]) + self.__open = value