From 2f238a2cc3922b091e3f6fa0f8f175d4925b7708 Mon Sep 17 00:00:00 2001 From: x12sa Date: Mon, 12 Oct 2026 17:49:34 +0200 Subject: [PATCH] fix(lamni): interferometer position readout, scan-center drift and central stop moves - show_interferometer_positions() now calls the controller's positions method (was calling show_feedback_status) and the method is exposed via USER_ACCESS; loop status is taken from J2 like feedback_status() instead of misreading the J4 status field (reported True with feedback off). - lamni_new_scan_center_interferometer: a first-iteration drift above 150 um is now discarded instead of being skipped in the first move but still added in the second iteration. - loptics_in()/loptics_out() now also move the central stop; lcs_in() moves lcsx/lcsy to their configured "in" position and lcs_out() moves lcsy to its configured "out" position (was hardcoded 3). Co-Authored-By: Claude Opus 5.5 --- .../bec_ipython_client/plugins/LamNI/lamni.py | 2 +- .../plugins/LamNI/lamni_optics_mixin.py | 31 ++++++++++++++++--- csaxs_bec/devices/omny/rt/rt_lamni_ophyd.py | 3 +- csaxs_bec/scans/lamni_components.py | 13 +++++--- 4 files changed, 38 insertions(+), 11 deletions(-) diff --git a/csaxs_bec/bec_ipython_client/plugins/LamNI/lamni.py b/csaxs_bec/bec_ipython_client/plugins/LamNI/lamni.py index b795c602..f8768076 100644 --- a/csaxs_bec/bec_ipython_client/plugins/LamNI/lamni.py +++ b/csaxs_bec/bec_ipython_client/plugins/LamNI/lamni.py @@ -778,7 +778,7 @@ class LamNI( self.device_manager.devices.rtx.controller.show_feedback_status() def show_interferometer_positions(self): - self.device_manager.devices.rtx.controller.show_feedback_status() + return self.device_manager.devices.rtx.controller.show_interferometer_positions() def show_signal_strength(self): self.device_manager.devices.rtx.controller.show_signal_strength_interferometer() diff --git a/csaxs_bec/bec_ipython_client/plugins/LamNI/lamni_optics_mixin.py b/csaxs_bec/bec_ipython_client/plugins/LamNI/lamni_optics_mixin.py index d2dee00b..fb097d43 100644 --- a/csaxs_bec/bec_ipython_client/plugins/LamNI/lamni_optics_mixin.py +++ b/csaxs_bec/bec_ipython_client/plugins/LamNI/lamni_optics_mixin.py @@ -403,9 +403,10 @@ class LamNIOpticsMixin: ) def loptics_in(self): - """Move in the LamNI optics (FZP + OSA).""" + """Move in the LamNI optics (FZP + OSA + central stop).""" self.lfzp_in() self.losa_in() + self.lcs_in() def _check_eye_out_and_optics_in(self, tol=0.003): """True if the setup is in measurement configuration: X-ray eye OUT, @@ -452,10 +453,11 @@ class LamNIOpticsMixin: return eye_out and optics_in and osa_in def loptics_out(self): - """Move out the LamNI optics.""" + """Move out the LamNI optics (central stop + OSA + FZP).""" if "rtx" in dev and dev.rtx.enabled: dev.rtx.controller.feedback_disable() + self.lcs_out() self.losa_out() loptx_out = self._get_user_param_safe("loptx", "out") lopty_out = self._get_user_param_safe("lopty", "out") @@ -469,10 +471,31 @@ class LamNIOpticsMixin: print(f"Interferometer feedback re-established ({time.time() - _t0:.1f} s).") def lcs_in(self): - pass + lcsx_in = self._get_user_param_safe("lcsx", "in") + lcsy_in = self._get_user_param_safe("lcsy", "in") + + current_lcsx = dev.lcsx.readback.get() + current_lcsy = dev.lcsy.readback.get() + + tol = 0.003 + + need_move_cs = not np.isclose(current_lcsx, lcsx_in, atol=tol) or not np.isclose( + current_lcsy, lcsy_in, atol=tol + ) + + if need_move_cs: + umv(dev.lcsx, lcsx_in, dev.lcsy, lcsy_in) + else: + print("Central stop is already at the IN position.") def lcs_out(self): - umv(dev.lcsy, 3) + # only lcsy has an "out" position; lcsx stays where it is + lcsy_out = self._get_user_param_safe("lcsy", "out") + + if not np.isclose(dev.lcsy.readback.get(), lcsy_out, atol=0.003): + umv(dev.lcsy, lcsy_out) + else: + print("Central stop is already at the OUT position.") def losa_in(self): losax_in = self._get_user_param_safe("losax", "in") diff --git a/csaxs_bec/devices/omny/rt/rt_lamni_ophyd.py b/csaxs_bec/devices/omny/rt/rt_lamni_ophyd.py index c9c70f87..22ea1cf4 100644 --- a/csaxs_bec/devices/omny/rt/rt_lamni_ophyd.py +++ b/csaxs_bec/devices/omny/rt/rt_lamni_ophyd.py @@ -53,6 +53,7 @@ class RtLamniController(Controller): "show_signal_strength_interferometer", "show_analog_signals", "show_feedback_status", + "show_interferometer_positions", ] def __init__( @@ -293,7 +294,7 @@ class RtLamniController(Controller): def show_interferometer_positions(self) -> dict: return_table = (self.socket_put_and_receive("J4")).split(",") - loop_status = bool(int(float(return_table[0]))) + loop_status = self.feedback_is_running() pos_y = float(return_table[1]) pos_x = float(return_table[2]) diff --git a/csaxs_bec/scans/lamni_components.py b/csaxs_bec/scans/lamni_components.py index 71f0f6d7..27c23d79 100644 --- a/csaxs_bec/scans/lamni_components.py +++ b/csaxs_bec/scans/lamni_components.py @@ -87,6 +87,13 @@ class LamNIComponents(ScanComponents): logger.info(f"Current uncompensated drift of setup is x={x_drift:.3f}, y={y_drift:.3f}") + # a drift this large is not trusted (e.g. interferometer reset or error); + # drop it so the second iteration does not apply it either + if np.abs(y_drift) > 150 or np.abs(x_drift) > 150: + logger.info("Drift exceeds 150 microns, ignoring it.") + x_drift = 0.0 + y_drift = 0.0 + move_x = ( x_stage + lsamx_center + self.lamni_to_stage_coordinates(x_drift, y_drift)[0] / 1000 ) @@ -100,11 +107,7 @@ class LamNIComponents(ScanComponents): self._dev.lsamx.read_only = False self._dev.lsamy.read_only = False - if ( - np.abs(y_drift) > 150 - or np.abs(x_drift) > 150 - or (coarse_move_req_y < 0.003 and coarse_move_req_x < 0.003) - ): + if coarse_move_req_y < 0.003 and coarse_move_req_x < 0.003: logger.info("No drift correction.") else: logger.info(