From 080999cd8ff85cd4dee62db82e1496d19d787eed Mon Sep 17 00:00:00 2001 From: x01dc Date: Wed, 26 Nov 2025 13:28:03 +0100 Subject: [PATCH] replaced all epics put with direct gui access --- .../plugins/flomni/x_ray_eye_align.py | 148 ++++++++---------- 1 file changed, 68 insertions(+), 80 deletions(-) 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 837c7c1..b00bdfa 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 @@ -24,7 +24,7 @@ if TYPE_CHECKING: class XrayEyeAlign: # pixel calibration, multiply to get mm - labview=False + test_wo_movments=True PIXEL_CALIBRATION = 0.1 / 113 # .2 with binning def __init__(self, client, flomni: Flomni) -> None: @@ -48,33 +48,16 @@ class XrayEyeAlign: epics_put("XOMNYI-XEYE-SAVFRAME:0", 1) def update_frame(self,keep_shutter_open=False): - if self.labview: - epics_put("XOMNYI-XEYE-ACQDONE:0", 0) - - if not self.labview: - self.flomni.flomnigui_show_xeyealign() - if not dev.cam_xeye.live_mode: - dev.cam_xeye.live_mode = True + + 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) self.gui.on_live_view_enabled(True) - self.gui.sample_name = 'straigth after init' - 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...") dev.omnyfsh.fshopen() - - if self.labview: - epics_put("XOMNYI-XEYE-ACQDONE:0", 0) - - while epics_get("XOMNYI-XEYE-ACQDONE:0") == 0: - print("waiting for new frame...") - time.sleep(0.5) - time.sleep(0.5) # stop live view if not keep_shutter_open: @@ -82,34 +65,36 @@ class XrayEyeAlign: self.gui.on_live_view_enabled(False) time.sleep(0.1) dev.omnyfsh.fshclose() - print("got new frame") + print("Received new frame.") else: print("Staying in live view, shutter is and remains open!") def tomo_rotate(self, val: float): # pylint: disable=undefined-variable - umv(self.device_manager.devices.fsamroy, val) + if not self.test_wo_movments: + umv(self.device_manager.devices.fsamroy, val) def get_tomo_angle(self): return self.device_manager.devices.fsamroy.readback.get() def update_fov(self, k: int): self._xray_fov_xy[0] = max(epics_get(f"XOMNYI-XEYE-XWIDTH_X:{k}"), self._xray_fov_xy[0]) - self._xray_fov_xy[1] = max(0, self._xray_fov_xy[0]) + self._xray_fov_xy[1] = max(epics_get(f"XOMNYI-XEYE-YWIDTH_Y:{k}"), self._xray_fov_xy[1]) # @property # def movement_buttons_enabled(self): # return [epics_get("XOMNYI-XEYE-ENAMVX:0"), epics_get("XOMNYI-XEYE-ENAMVY:0")] # @movement_buttons_enabled.setter - def movement_buttons_enabled(self, enabled: bool): + def movement_buttons_enabled(self, enablex: bool, enabley: bool): # enabled = int(enabled) # epics_put("XOMNYI-XEYE-ENAMVX:0", enabled) # epics_put("XOMNYI-XEYE-ENAMVY:0", enabled) - self.gui.on_motors_enable(enabled,enabled) + self.gui.on_motors_enable(enablex,enabley) def send_message(self, msg: str): # epics_put("XOMNYI-XEYE-MESSAGE:0.DESC", msg) + print(f"In alginment GUI: {msg}") self.gui.user_message = msg def align(self,keep_shutter_open=False): @@ -119,10 +104,16 @@ class XrayEyeAlign: 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...") - #potential unresolved movement requests to zero - # epics_put("XOMNYI-XEYE-MVX:0", 0) - # epics_put("XOMNYI-XEYE-MVY:0", 0) - self.movement_buttons_enabled(False) + self.gui.enable_submit_button(False) + + #Initialize xray align device + #clear potential pending movement requests + epics_put("XOMNYI-XEYE-MVX:0", 0) + epics_put("XOMNYI-XEYE-MVY:0", 0) + #reset submit channel + epics_put("XOMNYI-XEYE-SUBMIT:0", 0) + + self.movement_buttons_enabled(False, False) # reset shift xy and fov params self._reset_init_values() @@ -131,18 +122,19 @@ class XrayEyeAlign: self.flomni.flomnigui_show_xeyealign() self.flomni.flomnigui_raise() + + if not self.test_wo_movments: + self.tomo_rotate(0) + #epics_put("XOMNYI-XEYE-ANGLE:0", 0) - self.tomo_rotate(0) - epics_put("XOMNYI-XEYE-ANGLE:0", 0) - - self.flomni.feye_in() + self.flomni.feye_in() self.flomni.laser_tracker_on() self.flomni.feedback_enable_with_reset() # disable movement buttons - self.movement_buttons_enabled(False) + self.movement_buttons_enabled(False,False) sample_name = self.flomni.sample_get_name(0) # epics_put("XOMNYI-XEYE-SAMPLENAME:0.DESC", sample_name) @@ -151,19 +143,17 @@ class XrayEyeAlign: # this makes sure we are in a defined state self.flomni.feedback_disable() - epics_put("XOMNYI-XEYE-PIXELSIZE:0", self.PIXEL_CALIBRATION) + #epics_put("XOMNYI-XEYE-PIXELSIZE:0", self.PIXEL_CALIBRATION) + if not self.test_wo_movments: + self.flomni.fosa_out() - self.flomni.fosa_out() + fsamx_in = self.flomni._get_user_param_safe("fsamx", "in") + umv(dev.fsamx, fsamx_in - 0.25) - fsamx_in = self.flomni._get_user_param_safe("fsamx", "in") - #umv(dev.fsamx, fsamx_in - 0.25) + self.flomni.ffzp_in() - self.flomni.ffzp_in() self.update_frame(keep_shutter_open) - # enable submit buttons - # self.movement_buttons_enabled(False) - epics_put("XOMNYI-XEYE-SUBMIT:0", 0) self.gui.enable_submit_button(True) epics_put("XOMNYI-XEYE-STEP:0", 0) #TODO convert later self.send_message("Submit center value of FZP.") @@ -171,6 +161,8 @@ class XrayEyeAlign: k = 0 while True: if epics_get("XOMNYI-XEYE-SUBMIT:0") == 1: + #reset submit channel + epics_put("XOMNYI-XEYE-SUBMIT:0", 0) val_x = epics_get(f"XOMNYI-XEYE-XVAL_X:{k}") / 2 * self.PIXEL_CALIBRATION # in mm self.alignment_values[k] = val_x print(f"Clicked position {k}: x {self.alignment_values[k]}") @@ -181,52 +173,49 @@ class XrayEyeAlign: if k == 0: # received center value of FZP self.send_message("please wait ...") - self.movement_buttons_enabled = False - epics_put("XOMNYI-XEYE-SUBMIT:0", -1) # disable submit button + self.movement_buttons_enabled(False, False) + #epics_put("XOMNYI-XEYE-SUBMIT:0", -1) # disable submit button + self.gui.enable_submit_button(False) self.flomni.feedback_disable() - fsamx_in = self.flomni._get_user_param_safe("fsamx", "in") - #(dev.fsamx, fsamx_in) + if not self.test_wo_movments: + fsamx_in = self.flomni._get_user_param_safe("fsamx", "in") + umv(dev.fsamx, fsamx_in) - self.flomni.foptics_out() + self.flomni.foptics_out() - self.flomni.feedback_disable() - #umv(dev.fsamx, fsamx_in - 0.25) - - if self.labview: - 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) - print("waiting for background frame...") - - #umv(dev.fsamx, fsamx_in) - time.sleep(0.5) + time.sleep(0.5) + self.flomni.feedback_enable_with_reset() 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 + self.send_message("Step 1/5: Adjust sample height and submit center") + self.gui.enable_submit_button(True) + #epics_put("XOMNYI-XEYE-SUBMIT:0", 0) + self.movement_buttons_enabled(True, True) elif 1 <= k < 5: # received sample center value at samroy 0 ... 315 self.send_message("please wait ...") - epics_put("XOMNYI-XEYE-SUBMIT:0", -1) - self.movement_buttons_enabled = False + self.gui.enable_submit_button(False) + #epics_put("XOMNYI-XEYE-SUBMIT:0", -1) + self.movement_buttons_enabled(False, False) umv(dev.rtx, 0) self.tomo_rotate(k * 45) epics_put("XOMNYI-XEYE-ANGLE:0", self.get_tomo_angle()) 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) + self.send_message(f"Step {k+1}/5: Submit sample center") + self.gui.enable_submit_button(True) + #epics_put("XOMNYI-XEYE-SUBMIT:0", 0) + #epics_put("XOMNYI-XEYE-ENAMVX:0", 1) + self.movement_buttons_enabled(True, False) self.update_fov(k) elif k == 5: # received sample center value at samroy 270 and done self.send_message("done...") - epics_put("XOMNYI-XEYE-SUBMIT:0", -1) # disable submit button - self.movement_buttons_enabled = False + self.gui.enable_submit_button(False) + #epics_put("XOMNYI-XEYE-SUBMIT:0", -1) # disable submit button + self.movement_buttons_enabled(False,False) self.update_fov(k) break @@ -248,38 +237,37 @@ class XrayEyeAlign: _xrayeyalignmvy = epics_get("XOMNYI-XEYE-MVY:0") if _xrayeyalignmvy != 0: self.flomni.feedback_disable() - umvr(dev.fsamy, _xrayeyalignmvy / 1000) + if not self.test_wo_movments: + umvr(dev.fsamy, _xrayeyalignmvy / 1000) time.sleep(2) epics_put("XOMNYI-XEYE-MVY:0", 0) self.flomni.feedback_enable_with_reset() self.update_frame(keep_shutter_open) - time.sleep(0.2) + time.sleep(0.1) self.write_output() fovx = self._xray_fov_xy[0] * self.PIXEL_CALIBRATION * 1000 / 2 fovy = self._xray_fov_xy[1] * self.PIXEL_CALIBRATION * 1000 / 2 + self.tomo_rotate(0) umv(dev.rtx, 0) - # free camera - if self.labview: - epics_put("XOMNYI-XEYE-ACQ:0", 2) - if keep_shutter_open and not self.labview: + if keep_shutter_open: if self.flomni.OMNYTools.yesno("Close the shutter now?","y"): dev.omnyfsh.fshclose() epics_put("XOMNYI-XEYE-ACQ:0", 0) print("setting 'XOMNYI-XEYE-ACQ:0'") - if not self.labview: - pass #self.flomni.flomnigui_idle() + + #self.flomni.flomnigui_idle() print( f"The largest field of view from the xrayeyealign was \nfovx = {fovx:.0f} microns, fovy" f" = {fovy:.0f} microns" ) - print("Use the matlab routine to FIT the current alignment...") + print("Check the fit in the GUI...") print("Then LOAD ALIGNMENT PARAMETERS by running flomni.read_alignment_offset()\n")