BEC: check_state and current_state methods
This commit is contained in:
@@ -7,6 +7,7 @@ from aare.common.exception_handler import (
|
||||
TellMountFailedException,
|
||||
)
|
||||
from aare.common.models import BeamlineStateEnum
|
||||
from aare.devices.bec_worker import BeamlineState
|
||||
from aare.devices.tell_client import TellEventValueEnum
|
||||
from aare.daq.operations.mounting.models import MountingContext, MountingResult
|
||||
|
||||
@@ -82,8 +83,9 @@ class MountingService:
|
||||
self.ctx.cfg.record_mount_success()
|
||||
|
||||
def _mount_handler(self, target) -> None:
|
||||
if not self.ctx.devs.bec_worker.check_is_state(BeamlineStateEnum.RobotSampleExchange):
|
||||
raise TellMountFailedException(f"Cannot mount sample, BEC is not in RobotSampleExchange state")
|
||||
if not self.ctx.devs.bec_worker.is_state(BeamlineStateEnum.RobotSampleExchange):
|
||||
self.logger.error(f"Cannot unmount sample, BEC is not in RobotSampleExchange state")
|
||||
self.logger.debug(f"Current state: {self.ctx.devs.bec_worker.current_state()}")
|
||||
|
||||
self._prepare_mount_hardware()
|
||||
|
||||
@@ -136,8 +138,11 @@ class MountingService:
|
||||
self.ctx.devs.tell.set_in_mount_position(True)
|
||||
|
||||
def _unmount_current_sample(self, timeout: float = 60.0):
|
||||
if not self.ctx.devs.bec_worker.check_is_state(BeamlineStateEnum.RobotSampleExchange):
|
||||
raise TellMountFailedException(f"Cannot mount sample, BEC is not in RobotSampleExchange state")
|
||||
if not self.ctx.devs.bec_worker.is_state(BeamlineState.ROBOT_SAMPLE_EXCHANGE):
|
||||
self.logger.error(f"Cannot unmount sample, BEC is not in RobotSampleExchange state")
|
||||
self.logger.debug(f"Current state: {self.ctx.devs.bec_worker.current_state()}")
|
||||
|
||||
#raise TellMountFailedException(f"Cannot mount sample, BEC is not in RobotSampleExchange state")
|
||||
self._prepare_mount_hardware()
|
||||
previous_sample = self.ctx.cfg.current_sample
|
||||
if previous_sample is not None:
|
||||
@@ -161,8 +166,10 @@ class MountingService:
|
||||
self.ctx.devs.tell.dry(wait=True)
|
||||
|
||||
def execute(self, *, target) -> MountingResult:
|
||||
if not self.ctx.devs.bec_worker.check_is_state(BeamlineStateEnum.RobotSampleExchange):
|
||||
raise TellMountFailedException(f"Cannot mount sample, BEC is not in RobotSampleExchange state")
|
||||
if not self.ctx.devs.bec_worker.is_state(BeamlineState.ROBOT_SAMPLE_EXCHANGE):
|
||||
self.logger.error(f"Cannot unmount sample, BEC is not in RobotSampleExchange state")
|
||||
self.logger.debug(f"Current state: {self.ctx.devs.bec_worker.current_state()}")
|
||||
# raise TellMountFailedException(f"Cannot mount sample, BEC is not in RobotSampleExchange state")
|
||||
|
||||
previous_sample = self.ctx.cfg.current_sample
|
||||
|
||||
|
||||
@@ -109,22 +109,29 @@ class BECClientWorker:
|
||||
|
||||
@log_timing(logger, "BEC move_to")
|
||||
def move_to(self, state:BeamlineState):
|
||||
start = time.perf_counter()
|
||||
logger.info(f"BEC move_to requested: {state.value}")
|
||||
if self.simulated:
|
||||
logger.debug(f"Simulating move to {state.value}")
|
||||
return True
|
||||
try:
|
||||
return self.planner.move_to(state)
|
||||
self.planner.move_to(state)
|
||||
if self.planner.is_state(state):
|
||||
logger.info(f"BEC move_to completed: {state.value} in {time.perf_counter() - start:.2f}s")
|
||||
return True
|
||||
else:
|
||||
logger.warning(f"Failed to move to {state.value} in {time.perf_counter() - start:.2f}s")
|
||||
return False
|
||||
except Exception as e:
|
||||
self._raise_bec_error(e, operation=f"planner.move_to:{state.value}")
|
||||
|
||||
def check_is_state(self, state: BeamlineState):
|
||||
def is_state(self, state: BeamlineState):
|
||||
if self.simulated:
|
||||
logger.debug(f"Simulating check_beamline_state: {state.value}")
|
||||
return True
|
||||
return self.planner.is_state(state)
|
||||
|
||||
def check_current_state(self):
|
||||
def current_state(self):
|
||||
if self.simulated:
|
||||
logger.debug(f"Simulating check_beamline_state")
|
||||
return BeamlineState.MAINTENANCE
|
||||
@@ -180,26 +187,27 @@ if __name__ == "__main__":
|
||||
import sys
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
det_value = 980
|
||||
print(f"moving detector to vale:{det_value}")
|
||||
start = time.perf_counter()
|
||||
# print(client.get_det_z())
|
||||
# client.det_z(value=det_value, timeout=10)
|
||||
# print(time.perf_counter() - start)
|
||||
# print(client.get_det_z)
|
||||
# det_value = 985
|
||||
# print(f"moving detector to vale:{det_value}")
|
||||
status = client.det_z(value=det_value)
|
||||
status.wait(timeout=5)
|
||||
print(status)
|
||||
print(client.get_det_z())
|
||||
#client.mono_pitch_scan_runner()
|
||||
#client.change_energy(12000)
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error: {e}")
|
||||
# client.planner.current_state()
|
||||
print(client.is_state(BeamlineState.ROBOT_SAMPLE_EXCHANGE))
|
||||
# try:
|
||||
# det_value = 980
|
||||
# print(f"moving detector to vale:{det_value}")
|
||||
# start = time.perf_counter()
|
||||
# # print(client.get_det_z())
|
||||
# # client.det_z(value=det_value, timeout=10)
|
||||
# # print(time.perf_counter() - start)
|
||||
# # print(client.get_det_z)
|
||||
# # det_value = 985
|
||||
# # print(f"moving detector to vale:{det_value}")
|
||||
# status = client.det_z(value=det_value)
|
||||
# status.wait(timeout=5)
|
||||
# print(status)
|
||||
# print(client.get_det_z())
|
||||
# #client.mono_pitch_scan_runner()
|
||||
# #client.change_energy(12000)
|
||||
#
|
||||
# except Exception as e:
|
||||
# print(f"Error: {e}")
|
||||
# # client.planner.current_state()
|
||||
# client.planner.move_to(BeamlineState.SAMPLE_ALIGNMENT)
|
||||
# time.sleep(2.0)
|
||||
# client.planner.current_state()
|
||||
|
||||
Reference in New Issue
Block a user