From af2a69f8258629f5ff0c2f885e6762cde7781c6b Mon Sep 17 00:00:00 2001 From: x01dc Date: Fri, 31 Oct 2025 11:38:27 +0100 Subject: [PATCH] various fixes or adjustments during testing the new alignment gui --- .../plugins/flomni/flomni.py | 8 +-- .../plugins/flomni/flomni_optics_mixin.py | 2 +- .../plugins/flomni/gui_tools.py | 15 ++++++ .../plugins/flomni/x_ray_eye_align.py | 54 +++++++++++++------ .../widgets/omny_alignment/omny_alignment.py | 4 +- .../widgets/omny_alignment/omny_alignment.ui | 2 +- .../bec_widgets/widgets/xray_eye/x_ray_eye.py | 4 +- csaxs_bec/device_configs/flomni_config.yaml | 4 +- 8 files changed, 66 insertions(+), 27 deletions(-) diff --git a/csaxs_bec/bec_ipython_client/plugins/flomni/flomni.py b/csaxs_bec/bec_ipython_client/plugins/flomni/flomni.py index e2a0f33..374ec61 100644 --- a/csaxs_bec/bec_ipython_client/plugins/flomni/flomni.py +++ b/csaxs_bec/bec_ipython_client/plugins/flomni/flomni.py @@ -1172,12 +1172,12 @@ class Flomni( self.align = XrayEyeAlign(self.client, self) self.set_client(client) - def start_x_ray_eye_alignment(self): + def start_x_ray_eye_alignment(self, keep_shutter_open=False): if self.OMNYTools.yesno("Starting Xrayeye alignment. Deleting any potential existing alignment for this sample.", "y"): self.align = XrayEyeAlign(self.client, self) try: - self.align.align() + self.align.align(keep_shutter_open) except KeyboardInterrupt as exc: fsamx_in = self._get_user_param_safe(dev.fsamx, "in") if np.isclose(fsamx_in, dev.fsamx.readback.get(), 0.5): @@ -1189,8 +1189,8 @@ class Flomni( def xrayeye_update_frame(self): self.align.update_frame() - def xrayeye_alignment_start(self): - self.start_x_ray_eye_alignment() + def xrayeye_alignment_start(self, keep_shutter_open=False): + self.start_x_ray_eye_alignment(keep_shutter_open) def drive_axis_to_limit(self, device, direction): axis_id = device._config["deviceConfig"].get("axis_Id") diff --git a/csaxs_bec/bec_ipython_client/plugins/flomni/flomni_optics_mixin.py b/csaxs_bec/bec_ipython_client/plugins/flomni/flomni_optics_mixin.py index b79fa98..903e4c9 100644 --- a/csaxs_bec/bec_ipython_client/plugins/flomni/flomni_optics_mixin.py +++ b/csaxs_bec/bec_ipython_client/plugins/flomni/flomni_optics_mixin.py @@ -33,7 +33,7 @@ class FlomniOpticsMixin: feyex_in = self._get_user_param_safe("feyex", "in") feyey_in = self._get_user_param_safe("feyey", "in") umv(dev.feyex, feyex_in, dev.feyey, feyey_in) - self.align.update_frame() + #self.align.update_frame() def _ffzp_in(self): foptx_in = self._get_user_param_safe("foptx", "in") diff --git a/csaxs_bec/bec_ipython_client/plugins/flomni/gui_tools.py b/csaxs_bec/bec_ipython_client/plugins/flomni/gui_tools.py index 2093b5d..f02f501 100644 --- a/csaxs_bec/bec_ipython_client/plugins/flomni/gui_tools.py +++ b/csaxs_bec/bec_ipython_client/plugins/flomni/gui_tools.py @@ -21,6 +21,7 @@ class flomniGuiTools: self.gui_window = None self.camera_gripper_image = None self.camera_overview_image = None + self.xeyegui = None self.progressbar = None self.text_box = None self.idle_text_box = None @@ -38,6 +39,18 @@ class flomniGuiTools: def flomnigui_stop_gui(self): self.gui.flomni.hide() + def flomnigui_raise(self): + self.gui.flomni.raise_window() + + def flomnigui_show_xeyealign(self): + self.flomnigui_show_gui() + if self.xeyegui is None: + self.flomnigui_remove_all_docks() + self.xeyegui = self.gui.flomni.new("xeyegui").new("XRayEye") + # start live + if not dev.cam_xeye.live_mode: + dev.cam_xeye.live_mode = True + def flomnigui_show_cameras(self): self.flomnigui_show_gui() if self.camera_gripper_image is None or self.camera_overview_image is None: @@ -68,9 +81,11 @@ class flomniGuiTools: def flomnigui_remove_all_docks(self): dev.cam_flomni_overview.stop_live_mode() dev.cam_flomni_gripper.stop_live_mode() + dev.cam_xeye.live_mode = False self.gui.flomni.delete_all() self.camera_gripper_image = None self.camera_overview_image = None + self.xeyegui = None self.progressbar = None self.text_box = None self.idle_text_box = None diff --git a/csaxs_bec/bec_ipython_client/plugins/flomni/x_ray_eye_align.py b/csaxs_bec/bec_ipython_client/plugins/flomni/x_ray_eye_align.py index f02bf19..893e5ad 100644 --- a/csaxs_bec/bec_ipython_client/plugins/flomni/x_ray_eye_align.py +++ b/csaxs_bec/bec_ipython_client/plugins/flomni/x_ray_eye_align.py @@ -41,16 +41,22 @@ class XrayEyeAlign: def save_frame(self): epics_put("XOMNYI-XEYE-SAVFRAME:0", 1) - def update_frame(self): + def update_frame(self,keep_shutter_open=False): if self.labview: epics_put("XOMNYI-XEYE-ACQDONE:0", 0) - # start live + + if not self.labview: + self.flomni.flomnigui_show_xeyealign() + if not dev.cam_xeye.live_mode: + dev.cam_xeye.live_mode = True + epics_put("XOMNYI-XEYE-ACQ:0", 1) if self.labview: # wait for start live while epics_get("XOMNYI-XEYE-ACQDONE:0") == 0: time.sleep(0.5) print("waiting for live view to start...") + fshopen() if self.labview: @@ -62,10 +68,13 @@ class XrayEyeAlign: time.sleep(0.5) # stop live view - epics_put("XOMNYI-XEYE-ACQ:0", 0) - time.sleep(0.1) - fshclose() - print("got new frame") + if not keep_shutter_open: + epics_put("XOMNYI-XEYE-ACQ:0", 0) + time.sleep(0.1) + fshclose() + print("got new frame") + else: + print("Staying in live view, shutter is and remains open!") def tomo_rotate(self, val: float): # pylint: disable=undefined-variable @@ -91,12 +100,19 @@ class XrayEyeAlign: def send_message(self, msg: str): epics_put("XOMNYI-XEYE-MESSAGE:0.DESC", msg) - def align(self): + def align(self,keep_shutter_open=False): + if not keep_shutter_open: + print("This routine can be called with paramter keep_shutter_open=True to keep the shutter always open") + self.send_message("Getting things ready. Please wait...") + # reset shift xy and fov params self._reset_init_values() self.flomni.lights_off() + self.flomni.flomnigui_show_xeyealign() + self.flomni.flomnigui_raise() + self.tomo_rotate(0) epics_put("XOMNYI-XEYE-ANGLE:0", 0) @@ -123,7 +139,7 @@ class XrayEyeAlign: umv(dev.fsamx, fsamx_in - 0.25) self.flomni.ffzp_in() - self.update_frame() + self.update_frame(keep_shutter_open) # enable submit buttons self.movement_buttons_enabled = False @@ -157,7 +173,7 @@ class XrayEyeAlign: umv(dev.fsamx, fsamx_in - 0.25) if self.labview: - self.update_frame() + self.update_frame(keep_shutter_open) epics_put("XOMNYI-XEYE-RECBG:0", 1) while epics_get("XOMNYI-XEYE-RECBG:0") == 1: time.sleep(0.5) @@ -167,7 +183,7 @@ class XrayEyeAlign: time.sleep(0.5) self.flomni.feedback_enable_with_reset() - self.update_frame() + self.update_frame(keep_shutter_open) self.send_message("Adjust sample height and submit center") epics_put("XOMNYI-XEYE-SUBMIT:0", 0) self.movement_buttons_enabled = True @@ -180,7 +196,7 @@ class XrayEyeAlign: umv(dev.rtx, 0) self.tomo_rotate(k * 45) epics_put("XOMNYI-XEYE-ANGLE:0", self.get_tomo_angle()) - self.update_frame() + self.update_frame(keep_shutter_open) self.send_message("Submit sample center") epics_put("XOMNYI-XEYE-SUBMIT:0", 0) epics_put("XOMNYI-XEYE-ENAMVX:0", 1) @@ -204,7 +220,7 @@ class XrayEyeAlign: if k > 0: epics_put(f"XOMNYI-XEYE-STAGEPOSX:{k}", dev.rtx.readback.get() / 1000) time.sleep(3) - self.update_frame() + self.update_frame(keep_shutter_open) if k < 2: # allow movements, store movements to calculate center @@ -215,7 +231,7 @@ class XrayEyeAlign: time.sleep(2) epics_put("XOMNYI-XEYE-MVY:0", 0) self.flomni.feedback_enable_with_reset() - self.update_frame() + self.update_frame(keep_shutter_open) time.sleep(0.2) self.write_output() @@ -226,8 +242,16 @@ class XrayEyeAlign: umv(dev.rtx, 0) - # free camera - epics_put("XOMNYI-XEYE-ACQ:0", 2) + # free camera + if self.labview: + epics_put("XOMNYI-XEYE-ACQ:0", 2) + if keep_shutter_open and not self.labview: + if self.flomni.OMNYTools.yesno("Close the shutter now?","y"): + fshclose() + epics_put("XOMNYI-XEYE-ACQ:0", 0) + if not self.labview: + self.flomni.flomnigui_idle() + print( f"The largest field of view from the xrayeyealign was \nfovx = {fovx:.0f} microns, fovy" diff --git a/csaxs_bec/bec_widgets/widgets/omny_alignment/omny_alignment.py b/csaxs_bec/bec_widgets/widgets/omny_alignment/omny_alignment.py index d39c93e..622bf3c 100644 --- a/csaxs_bec/bec_widgets/widgets/omny_alignment/omny_alignment.py +++ b/csaxs_bec/bec_widgets/widgets/omny_alignment/omny_alignment.py @@ -98,10 +98,10 @@ class OmnyAlignment(BECWidget, QWidget): logger.info(f"Live view is enabled: {enabled}") image: Image = self.ui.image if enabled: - image.image("cam200") + image.image("cam_xeye") return - image.disconnect_monitor("cam200") + image.disconnect_monitor("cam_xeye") @property diff --git a/csaxs_bec/bec_widgets/widgets/omny_alignment/omny_alignment.ui b/csaxs_bec/bec_widgets/widgets/omny_alignment/omny_alignment.ui index 0cd20ea..6572d2f 100644 --- a/csaxs_bec/bec_widgets/widgets/omny_alignment/omny_alignment.ui +++ b/csaxs_bec/bec_widgets/widgets/omny_alignment/omny_alignment.ui @@ -86,7 +86,7 @@ false - cam200 + cam_xeye 3 diff --git a/csaxs_bec/bec_widgets/widgets/xray_eye/x_ray_eye.py b/csaxs_bec/bec_widgets/widgets/xray_eye/x_ray_eye.py index 3b66431..2ba48e7 100644 --- a/csaxs_bec/bec_widgets/widgets/xray_eye/x_ray_eye.py +++ b/csaxs_bec/bec_widgets/widgets/xray_eye/x_ray_eye.py @@ -24,7 +24,7 @@ from qtpy.QtWidgets import ( ) logger = bec_logger.logger -CAMERA = ("cam_xeye_rgb", "image") +CAMERA = ("cam_xeye", "image") class XRayEye2DControl(BECWidget, QWidget): @@ -409,7 +409,7 @@ class XRayEye(BECWidget, QWidget): def cleanup(self): """Cleanup connections on widget close -> disconnect slots and stop live mode of camera.""" self.bec_dispatcher.disconnect_slot(self.device_updates, MessageEndpoints.device_readback("omny_xray_gui")) - getattr(self.dev,CAMERA).live_mode = False + getattr(self.dev,CAMERA[0]).live_mode = False super().cleanup() if __name__ == "__main__": diff --git a/csaxs_bec/device_configs/flomni_config.yaml b/csaxs_bec/device_configs/flomni_config.yaml index 1a3bfd1..0e39c95 100644 --- a/csaxs_bec/device_configs/flomni_config.yaml +++ b/csaxs_bec/device_configs/flomni_config.yaml @@ -393,7 +393,7 @@ cam_flomni_overview: readOnly: false readoutPriority: on_request -cam_xeye_mono: +cam_xeye: description: Camera flOMNI Xray eye ID1 deviceClass: csaxs_bec.devices.ids_cameras.ids_camera.IDSCamera deviceConfig: @@ -406,7 +406,7 @@ cam_xeye_mono: readOnly: false readoutPriority: async -cam_xeye_rgb: +cam_ids_rgb: description: Camera flOMNI Xray eye ID203 deviceClass: csaxs_bec.devices.ids_cameras.ids_camera.IDSCamera deviceConfig: -- 2.49.1