diff --git a/src/aare/daq/daq.py b/src/aare/daq/daq.py index e5af47a4..da666f06 100644 --- a/src/aare/daq/daq.py +++ b/src/aare/daq/daq.py @@ -1883,6 +1883,9 @@ class AareDAQ: self.__cfg.state_busy = False raise + def check_tell_mount_start_conditions(self) -> None: + self.__devs.tell.validate_mount_start_conditions() + def _execute_dry(self, park:bool=True, unmount:bool=False): self._create_mounting_service().dry(park=park, unmount=unmount) @@ -2663,7 +2666,8 @@ class AareDAQ: self.__cfg.try_set_busy(timeout=self.AUTOMATION_BUSY_TIMEOUT_S) self._validate_automation_state(context="after acquiring automation busy state") - + logger.info("Cancelling any pending jfjoch operations") + self.__jfjoch.cancel() self._set_progress_context( progress, current_sample_name=getattr(sample, "sample_name", "") or "", @@ -2822,7 +2826,7 @@ class AareDAQ: self._raise_if_critical_jfjoch_detector_error(e, command=e.endpoint or "unknown") raise - except (StateTransitionFailed, MaintenanceStateException) as e: + except (TransformationInvalidException, StateTransitionFailed, MaintenanceStateException) as e: logger.error(f"Critical automation state error: {e}") if progress.current_step is not None: current_kind = next( diff --git a/src/aare/devices/tell_client.py b/src/aare/devices/tell_client.py index 2f8e7e2d..91107449 100755 --- a/src/aare/devices/tell_client.py +++ b/src/aare/devices/tell_client.py @@ -103,10 +103,56 @@ class TellClient: :param value """ self.backend.eval("in_mount_position = " + str(value) + "&") + def _eval_bool(self, expr: str) -> bool: + value = self.backend.eval(expr) + return str(value).strip().lower() == "true" + def is_in_mount_position(self) -> bool: """checks to see if the robot is in the mount position and returns a boolean""" return self.backend.eval("in_mount_position&").lower() == "true" + def is_manual_mode(self) -> bool: + msg = self.backend.eval("is_manual_mode()&") + logger.debug(f"manual mode: {msg}") + return msg + + def is_door_closed(self) -> bool: + msg = self.backend.eval("is_door_closed()&") + logger.debug(f"door closed: {msg}") + return msg + + def is_remote_mode(self) -> bool: + return not self.is_manual_mode() + + def validate_mount_start_conditions(self) -> None: + reasons: list[str] = [] + logger.warning('tell validation not in place') + pass + # try: + system_check = self.get_system_check() + # if system_check not in (None, "", "OK"): + # reasons.append(f"system check failed: {system_check}") + # except Exception as e: + # reasons.append(f"system check failed: {e}") + + # try: + # if not self.is_remote_mode(): + # reasons.append("TELL is not in remote mode") + # except Exception as e: + # reasons.append(f"failed to check remote mode: {e}") + + # try: + # if not self.is_door_closed(): + # reasons.append("TELL doors are open") + # except Exception as e: + # reasons.append(f"failed to check door status: {e}") + + # if reasons: + # raise TellCommunicationError( + # message="Mount can't start: " + "; ".join(reasons), + # operation="mount_precheck", + # ) + def set_samples_info(self, info: List[PuckWithTellPosition]): """sets the samples in the robot dewar based on the given list of PuckWithTellPosition objects and runs set_sample_info in the background""" @@ -366,13 +412,18 @@ class TellClient: return None def get_system_check(self): - return self.backend.eval("system_check_msg()&") + msg = self.backend.eval("system_check()&") + logger.debug(f"SYSTEM CHECK: {msg}") + return msg def get_robot_state(self): - return self.backend.eval("robot.state&") + msg = self.backend.eval("robot.state&") + logger.debug(f"robot state: {msg}") + return msg def get_robot_status(self): status = self.backend.eval("robot.take()&") + logger.debug(f"robot status: {status}") #return eval(status) return ast.literal_eval(status) @@ -487,13 +538,25 @@ def make_tell_client(bl: MXBeamline) -> TellClient: if __name__ == "__main__": from aare.common.beamline import mx_beamline - import time + from datetime import datetime, timezone bl = mx_beamline() tell_client = make_tell_client(bl) #tell_client.toggle_blower() #tell_client.check_enable_motion() - print(tell_client.get_system_check()) - print(tell_client.get_robot_status()) - print(tell_client.get_setting('dry_mount_count')) + print("system check: ", tell_client.get_system_check()) + print("status ", tell_client.get_robot_status()) + print("dry mount count: ", tell_client.get_setting('dry_mount_counter')) + + ts = float(tell_client.get_setting('dry_timestamp')) + print("dry timestape: ", ts) + past = datetime.fromtimestamp(ts, tz=timezone.utc) + now = datetime.now(timezone.utc) + seconds_ago = int((now - past).total_seconds()) + print(seconds_ago) + print("door closer :", tell_client.backend.eval('is_door_closed()&')) + print("manual mode: ", tell_client.backend.eval('is_manual_mode()&')) + print("position :", tell_client.get_robot_status()["pos"]) + #print("release safety: ", tell_client.backend.eval('release_safety()&')) + # time.sleep(5) #tell_client.blower_off() \ No newline at end of file