Tell: added error hadnling and check_smart_magent_mounted class

This commit is contained in:
2025-10-27 17:03:05 +01:00
parent 7eb838fd17
commit f7f5a7aa1f
+55
View File
@@ -24,6 +24,13 @@ from mxlibs3.pshell_client import PShellClient
logger = setup_logger(__name__, "/tmp/mxlogs")
class ManualMountException(Exception):
pass
class SmartMagnetFaultException(Exception):
pass
class TellMountFailedException(Exception):
pass
@@ -599,6 +606,54 @@ class TellClient:
def is_busy(self):
return "busy" == self.get_state().lower()
def check_smart_magnet_mounted(self, timeout: float = 10.0, idle_time: float = 1.0, interval: float = 0.1):
initial_state = self.pshell.eval("smart_magnet.state&")
logger.debug(f"checking smart magnet_initial state: {initial_state}")
if initial_state == "Paused":
self.pshell.eval("smart_magnet.set_supress(False)&")
self.pshell.eval("smart_magnet.set_resting_current()&")
elif initial_state == "Fault":
logger.error(f"tell smart magnet is in unknown state {initial_state}")
raise SmartMagnetFaultException
#time.sleep(1.0)
state = self.pshell.eval("smart_magnet.state&")
try:
# sample_present = bool(self.pshell.eval(
# f"smart_magnet.check_mounted(idle_time={str(idle_time)}, timeout={str(timeout)}, interval={str(interval)})"))
#logger.debug(f"sample present: {sample_present} of type {type(sample_present)}")
#time.sleep(1.0)
if state == "Busy":
logger.debug('state busy')
self.pshell.eval("smart_magnet.set_supress(True)&")
self.pshell.eval("smart_magnet.state&")
sample_present = True
elif state == "Ready":
logger.debug('No sample detected, ready to mount')
sample_present = False
elif state == "Paused":
logger.debug("Smart magnet detection is paused")
return None
else:
self.pshell.eval("smart_magnet.set_supress(True)&")
logger.error(f"Tell smart magnet is in unknown state {state}")
raise SmartMagnetFaultException
if sample_present:
print(self.get_mounted_sample())
if self.get_mounted_sample() is None:
logger.warning("Check mount: A manually mounted sample is detected.")
logger.warning("Remove before mounting with the robot.")
raise ManualMountException
return True
elif self.get_mounted_sample():
logger.error("Check mount: No sample detected, but robot thinks is mounted")
raise SmartMagnetFaultException
return False
except Exception as e:
logger.error(f"check_smart_magnet_mounted failed: {e}")
raise e
#sample_present = False
def is_true(value):
"""check if argument is semantically true"""