From c8a1add697ff4066ac53ad3ad42a036ff2725040 Mon Sep 17 00:00:00 2001 From: gac-x06da Date: Thu, 30 Jan 2025 15:56:01 +0100 Subject: [PATCH] More stable SmarGon movement --- pxiii_bec/devices/SmarGon.py | 30 ++++++++++++++++++++---------- pxiii_bec/scripts/scanwrappers.py | 10 ++++++---- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/pxiii_bec/devices/SmarGon.py b/pxiii_bec/devices/SmarGon.py index 79f5a25..94395d2 100644 --- a/pxiii_bec/devices/SmarGon.py +++ b/pxiii_bec/devices/SmarGon.py @@ -188,17 +188,15 @@ class SmarGonAxis(PVPositioner): """Move command that's masked by BEC""" return self.omove(position, wait, timeout, moved_cb) - def omove(self, position, wait=True, timeout=None, moved_cb=None): + def omove(self, position, wait=True, timeout=2.0, moved_cb=None): """Original move command without the BEC wrappers""" - status = self.setpoint.set(position, settle_time=0.1) + status = self.setpoint.set(position, settle_time=0.1).wait() if not wait: return status - status.wait() - def on_target(*, value, **_): - distance = abs(value - position) - print(distance) + distance = abs(value - self.setpoint._value) + print(f"[self.name] Distance: {distance}") return bool(distance < self._tol) status = SubscriptionStatus(self.readback, on_target, timeout=timeout, settle_time=0.1) @@ -214,8 +212,14 @@ class SmarGonAxis(PVPositioner): with mutex: r = requests.get(cmd, timeout=1, **kwargs) except TimeoutError: - with mutex: - r = requests.get(cmd, timeout=1, **kwargs) + try: + time.sleep(0.05) + with mutex: + r = requests.get(cmd, timeout=0.5, **kwargs) + except TimeoutError: + time.sleep(0.05) + with mutex: + r = requests.get(cmd, timeout=0.5, **kwargs) if not r.ok: raise RuntimeError( f"[{self.name}] Error getting {address}; reply was {r.status_code} => {r.reason}" @@ -229,8 +233,14 @@ class SmarGonAxis(PVPositioner): with mutex: r = requests.put(cmd, timeout=1, **kwargs) except TimeoutError: - with mutex: - r = requests.put(cmd, timeout=1, **kwargs) + try: + time.sleep(0.05) + with mutex: + r = requests.put(cmd, timeout=0.5, **kwargs) + except TimeoutError: + time.sleep(0.05) + with mutex: + r = requests.put(cmd, timeout=0.5, **kwargs) if not r.ok: raise RuntimeError( f"[{self.name}] Error putting {address}; reply was {r.status_code} => {r.reason}" diff --git a/pxiii_bec/scripts/scanwrappers.py b/pxiii_bec/scripts/scanwrappers.py index 88314aa..f012efd 100644 --- a/pxiii_bec/scripts/scanwrappers.py +++ b/pxiii_bec/scripts/scanwrappers.py @@ -1,7 +1,9 @@ from bec_widgets.cli.client_utils import BECGuiClient - +def bl_check_beam(): + """Check beamline status before scan""" + return True def ascan( @@ -22,8 +24,8 @@ def ascan( -------- ascan(dev.dccm_energy, 12,13, steps=21, exp_time=0.1, datasource=dev.dccm_xbpm) """ - # if not bl_check_beam(): - # raise RuntimeError("Beamline is not in ready state") + if not bl_check_beam(): + raise RuntimeError("Beamline is not in ready state") # # GUI setup # # Get or create gui @@ -35,7 +37,7 @@ def ascan( # window = val.widget # window.clear_all() # if window is None: - # window = gui.new("Current scan") + # window = gui.new("CurrentScan") # dock = window.add_dock(f"ScanDisplay {motor}") # plt1 = dock.add_widget('BECWaveformWidget')