Commit fbe9966a authored by Emmanuel Papillon's avatar Emmanuel Papillon
Browse files

fshutter : added enable()/disable()

presets : check fshutter disabled
          in standard scans, open/close at begin/end of scans if
          no frelon camera are used
finterlaced id11 wrapper added
parent c074097e
......@@ -15,6 +15,9 @@ class FastShutter:
self.__session_mux = config["session_mux"]
self.__settings = HashObjSetting(f"fastshutter:{name}")
self.__time = None
self.__enabled = self.__settings.get("enabled", True)
if not self.__enabled:
self.disable()
self.__calib = None
calib_config = config.get("calibration", None)
......@@ -30,11 +33,16 @@ class FastShutter:
return self.__config
def __info__(self):
if self.is_enabled():
scan_state = "YES"
else:
scan_state = "NO (shutter DISABLED)"
info = f"FastShutter [{self.name}]:\n"
info += f"Controlled by session = {self.session}\n"
info += f"Shutter polarity = {self.polarity}\n"
info += f"Shutter mode = {self.mode}\n"
info += f"Shutter time = {self.shutter_time:.3f} sec\n"
info += f"Shutter used in scans = {scan_state}\n"
return info
@property
......@@ -74,9 +82,23 @@ class FastShutter:
@property
def multiplexer(self):
return self.__shutter_mux
def enable(self):
self.__enabled = True
self.__settings["enabled"] = True
def disable(self):
self.__enabled = False
self.__settings["enabled"] = False
self.__shutter_mux.switch("SHUTTER", "CLOSE")
def is_enabled(self):
return self.__enabled
def open(self, wait=False):
self.__check_session()
if not self.__enabled:
raise RuntimeError("Shutter is DISABLED. Cannot open it !!")
self.__shutter_mux.switch("SHUTTER", "OPEN")
if wait:
gevent.sleep(self.shutter_time)
......@@ -98,6 +120,8 @@ class FastShutter:
@mode.setter
def mode(self, value):
self.__check_session()
if not self.__enabled:
raise RuntimeError("Shutter is DISABLED. Cannot change mode !!")
self.__shutter_mux.switch("SHUTTER", value.upper())
@property
......
......@@ -2,6 +2,7 @@ import gevent
import time
from fscan.fscanrunner import FScanRunner, FScanDiagRunner
from fscan.finterlaced import FInterlacedMode
class ID11CameraCalib:
......@@ -116,6 +117,49 @@ class ID11FScan(FScanDiagRunner):
def __call__(self, motor, start_pos, step_size, npoints, acq_time, **kwargs):
pars = dict(motor=motor, start_pos=start_pos, step_size=step_size, npoints=npoints, acq_time=acq_time, step_time=0.)
pars.update(kwargs)
self.pars.set(**kwargs)
self.pars.set(**pars)
self.run()
class ID11FInterlaced(FScanDiagRunner):
def __init__(self, scanname, scanmaster, fshutter):
self._fsh = fshutter
self._calib = ID11CameraCalib()
self._min_latency_time = 1e-5
super().__init__(scanname, scanmaster)
def validate(self):
pars = self.pars
# --- frelon readout checks
limadevs = self._master.get_controllers_found("lima")
frelons = [ dev for dev in limadevs if dev._proxy.lima_type == "Frelon" ]
if len(frelons):
readout_time = self._calib.calibrate(frelons, pars.acq_time, self._fsh.shutter_time)
if pars.acq_time < readout_time:
raise RuntimeError(f"Acquisition time too short for frelon (min={readout_time})")
# --- shift_pos adjusted in zigzag mode with frelon
pars.shift_pos = 0.
if pars.mode == FInterlacedMode.ZIGZAG and len(frelons):
dev = frelons[0]
if dev.camera.image_mode != "FRAME TRANSFER":
shut_time = self._fsh.shutter_time
mot_speed = abs(pars.acq_size) / pars.acq_time
shut_pos = shut_time * mot_speed
pars.shift_pos = shut_pos / 2.
super().validate()
def __call__(self, motor, start_pos, acq_size, npoints, acq_time, mode="ZIGZAG", **kwargs):
pars = dict(motor=motor,
start_pos=start_pos,
acq_size=acq_size,
npoints=npoints,
acq_time=acq_time,
mode=mode,
)
pars.update(kwargs)
self.pars.set(**pars)
self.run()
......@@ -26,20 +26,30 @@ class CountMuxPreset(ChainPreset):
self.fsh = fsh
def prepare(self, chain):
self.soft_fsh = True
# --- shutter
frelonnodes = [
node for node in chain.nodes_list if node.name.startswith("frelon")
]
frelon2shutter = {"frelon1": "CAM1", "frelon2": "CAM2", "frelon3": "CAM3"}
shutter_mode = "COUNTER"
for node in frelonnodes:
dev = node.device
if dev.name in frelon2shutter:
shutter_mode = frelon2shutter[dev.name]
dev.shutter.mode = "AUTO_FRAME"
dev.shutter.close_time = self.fsh.shutter_time
break
self.fsh.mode = shutter_mode
if dev.camera.image_mode == "FULL FRAME":
shutter_mode = frelon2shutter[dev.name]
dev.shutter.mode = "AUTO_FRAME"
dev.shutter.close_time = self.fsh.shutter_time
if self.fsh.is_enabled():
self.fsh.mode = shutter_mode
self.soft_fsh = False
else:
print("!!! WARNING !!!")
print(f"Your are using frelon {dev.name} in FULL FRAME mode")
print("but the fastshutter is DISABLED !!!\n")
break
if not self.fsh.is_enabled():
self.soft_fsh = False
# --- triggers
self.opmux.switch("TRIGGER_MODE", "COUNTER_CARD")
......@@ -48,6 +58,14 @@ class CountMuxPreset(ChainPreset):
self.opmux.switch("CAM3", "ON")
self.opmux.switch("MARANA", "ON")
def start(self, chain):
if self.soft_fsh:
self.fsh.open(wait=True)
def stop(self, chain):
if self.soft_fsh:
self.fsh.close()
CAM2MUX = {
"frelon1": "CAM1",
"frelon2": "CAM2",
......@@ -64,9 +82,6 @@ class FScanMuxPreset(ScanPreset):
self.limadevs = master.lima_used
def prepare(self, scan):
pass
def start(self, scan):
self.soft_fsh = True
self.opmux.switch("TRIGGER_MODE", "MUSST")
self.opmux.switch("MUSST", "BTRIG")
......@@ -76,9 +91,21 @@ class FScanMuxPreset(ScanPreset):
self.opmux.switch(cam_mux, "ON")
if dev.name.startswith("frelon") and self.soft_fsh is True:
if dev.camera.image_mode == "FULL FRAME":
self.soft_fsh = False
self.fsh.mode = cam_mux
dev.shutter.mode = "AUTO_FRAME"
dev.shutter.close_time = self.fsh.shutter_time
if self.fsh.is_enabled():
self.fsh.mode = cam_mux
self.soft_fsh = False
else:
print("!!! WARNING !!!")
print(f"Your are using frelon {dev.name} in FULL FRAME mode")
print("but the fastshutter is DISABLED !!!\n")
if not self.fsh.is_enabled():
self.soft_fsh = False
def start(self, scan):
if self.soft_fsh:
self.fsh.open(wait=True)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment