Smargon, added in self.__pos and __pos_aero for simualted mode. Fixed intiializing script.
Build and Publish / build (push) Successful in 17s
Build and Publish / Build and Deploy Docs (push) Successful in 38s

This commit is contained in:
2026-04-02 15:40:34 +02:00
parent 85e67f2f5c
commit 9758f7c800
+19 -16
View File
@@ -1,5 +1,5 @@
from enum import Enum
from time import sleep, time
from time import sleep, time, perf_counter
import requests
@@ -30,10 +30,10 @@ class Smargon(object):
self.__base = "http://x10sa-smargopolo.psi.ch:3000"
elif bl == MXBeamline.SIMULATED:
self.__simulated = True
self.__pos = self.SMARGON_HOME
self.__pos_aero = self.AERO_HOME
else:
raise Exception("unknown beamline")
self.__pos = self.SMARGON_HOME
self.__pos_aero = self.AERO_HOME
def gonget(self, thing: str) -> dict:
"""issue a GET for some API component on the smargopolo server
@@ -99,7 +99,8 @@ class Smargon(object):
@property
def mode(self) -> SmargonMode:
return SmargonMode.INITIALIZING
mode = self.gonget(f"mode")
return SmargonMode(mode)
@mode.setter
def mode(self, mode: SmargonMode):
@@ -107,10 +108,18 @@ class Smargon(object):
return
self.gonput(f"mode?mode={mode}")
def initialize(self):
self.mode = SmargonMode.UNINITIALIZED
def initialize(self, timeout: float = 360.0):
self.mode = SmargonMode.UNINITIALIZED.value
sleep(0.1)
self.mode = SmargonMode.INITIALIZING
self.mode = SmargonMode.INITIALIZING.value
start = perf_counter()
mode = self.mode.value
while mode != SmargonMode.READY.value:
sleep(0.1)
if abs(perf_counter() - start) > timeout:
raise TimeoutError("Timed out waiting for Smargon to initialize")
mode = self.mode.value
return True
def enable_correction(self):
if self.__simulated:
@@ -207,8 +216,6 @@ class Smargon(object):
while time() < timeout:
if target.eq(self.readback, tol):
break
if time() > timeout:
raise TimeoutError("Timed out waiting for Smargon to reach target")
sleep(poll_time)
def wait_aerotech(self, timeout=60.0, tol=0.01, poll_time=0.01):
@@ -224,11 +231,7 @@ class Smargon(object):
if __name__ == "__main__":
smargon = Smargon(MXBeamline.X10SA)
x = smargon.readback_aerotech
print(x)
y = smargon.target_aerotech
smargon.target_aerotech = AerotechCoordinate(at_mm=Coordinate(x=0, y=0, z=0))
print(y)
smargon.wait_aerotech()
print(f"aerotech reached {smargon.readback_aerotech}")
print(smargon.mode)
smargon.initialize(timeout=30.0)
print(smargon.mode)