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 6979c81..55f4722 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 @@ -31,6 +31,11 @@ class XrayEyeAlign: test_wo_movements = False PIXEL_CALIBRATION = 0.1 / 113 # .2 with binning + # Sign for the automatic vertical-centering move in the height-centering + # branch of _align_impl (search for `_height_centered`). + + HEIGHT_CENTERING_SIGN = -1 + def __init__(self, client, flomni: Flomni) -> None: self.client = client self.flomni = flomni @@ -58,6 +63,11 @@ class XrayEyeAlign: def _reset_init_values(self): self.shift_xy = [0, 0] self._xray_fov_xy = [0, 0] + # Guards the height-centering branch below: True once the automatic + # vertical-centering move has been applied for this alignment run, + # so a second submission at step==1 is treated as the real angle-0 + # fit point instead of triggering another height correction. + self._height_centered = False def update_frame(self, keep_shutter_open=False): if self.flomni._flomnigui_check_attribute_not_exists("xeyegui"): @@ -106,7 +116,7 @@ class XrayEyeAlign: self.flomni.flomnigui_show_xeyealign() self.gui.set_dap_params_forwarding(True) self.gui.reset_zoom() - + try: self._align_impl(keep_shutter_open) finally: @@ -196,6 +206,12 @@ class XrayEyeAlign: print(f"Corrected position {k}: x {self.alignment_values[k]}") # reset submit channel dev.omny_xray_gui.submit.set(0) + + # Controls whether `k` advances to the next step below. Left + # True except for the height-centering submission, which + # reuses k==1 for a second, real submission afterwards. + advance_step = True + if k == 0: # received center value of FZP self.send_message("please wait ...") self.movement_buttons_enabled(False, False) @@ -222,10 +238,49 @@ class XrayEyeAlign: self.gui.set_crosshair_position(fzp_center_x, fzp_center_y) self.gui.show_crosshair() - self.send_message("Step 1/5: Adjust sample height and submit center") + self.send_message( + "Adjust sample height with the arrows if needed, then mark " + "the sample and submit - height will be centered automatically" + ) self.gui.enable_submit_button(True) self.movement_buttons_enabled(True, True) + elif k == 1 and not self._height_centered: + # First submission after the FZP center: a ROI mark of + # the sample, used only to auto-center fsamy against the + # FZP-center crosshair (not yet a real fit point - see + # HEIGHT_CENTERING_SIGN above for the open sign question). + self.send_message("please wait ...") + self.gui.enable_submit_button(False) + self.movement_buttons_enabled(False, False) + + fzp_center_y = dev.omny_xray_gui.yval_y_0.get() + mark_y = dev.omny_xray_gui.yval_y_1.get() + delta_y_mm = ( + self.HEIGHT_CENTERING_SIGN + * (fzp_center_y - mark_y) + / 2 + * self.PIXEL_CALIBRATION + ) + print( + f"Height centering: fzp_center_y={fzp_center_y}, mark_y={mark_y}, " + f"delta_fsamy={delta_y_mm:.5f} mm" + ) + + self.flomni.feedback_disable() + if not self.test_wo_movements and delta_y_mm != 0: + self.flomni.umvr_fsamy_tracked(delta_y_mm) + time.sleep(2) + self.flomni.feedback_enable_with_reset() + + self._height_centered = True + self.update_frame(keep_shutter_open) + + self.send_message("Step 1/5: Submit sample center") + self.gui.enable_submit_button(True) + self.movement_buttons_enabled(True, False) + advance_step = False + elif 1 <= k < 5: # received sample center value at samroy 0 ... 315 self.send_message("please wait ...") self.gui.enable_submit_button(False) @@ -248,8 +303,9 @@ class XrayEyeAlign: self.gui.hide_crosshair() break - k += 1 - dev.omny_xray_gui.step.set(k) + if advance_step: + k += 1 + dev.omny_xray_gui.step.set(k) _xrayeyalignmvx = dev.omny_xray_gui.mvx.get() if _xrayeyalignmvx != 0: