diff --git a/src/aare/daq/workflows.py b/src/aare/daq/workflows.py index 094da900..dc7e2531 100644 --- a/src/aare/daq/workflows.py +++ b/src/aare/daq/workflows.py @@ -2,6 +2,7 @@ from aare.common.coordinate import Coordinate from aare.common.models import StagePositionEnum from aare.daq.devices import BeamlineDevices from aare.daq.config import BeamlineConfig, ABR_POS_MOUNT +from pxii_bec.macros.planner import BeamlineState def move_bsz(devs: BeamlineDevices, target: float): @@ -28,61 +29,88 @@ def wait_for_se_devices(devs: BeamlineDevices, cfg: BeamlineConfig): pass def common_2rse(devs: BeamlineDevices, cfg: BeamlineConfig): - print('move collimator and scintillator to 20') - devs.collimator = 20.0 - devs.scintillator = 20.0 - print('move smargon home') - devs.smargon_move_home() - print('try to move aerotech') - devs.aerotech_pos = ABR_POS_MOUNT - #print('move bl to park') - #devs.reflector_up = StagePositionEnum.PARK - print('move bs to park') - devs.beamstop_stage_up = StagePositionEnum.PARK - #print('move cryo to park') - #devs.__cryojet_pos = StagePositionEnum.PARK + if not devs.bec_worker: + print('move collimator and scintillator to 20') + devs.collimator = 20.0 + devs.scintillator = 20.0 + print('move smargon home') + devs.smargon_move_home() + print('try to move aerotech') + devs.aerotech_pos = ABR_POS_MOUNT + #print('move bl to park') + #devs.reflector_up = StagePositionEnum.PARK + print('move bs to park') + devs.beamstop_stage_up = StagePositionEnum.PARK + #print('move cryo to park') + #devs.__cryojet_pos = StagePositionEnum.PARK + else: + devs.bec_worker.planner.move_to(BeamlineState.ROBOT_SAMPLE_EXCHANGE) + print('move smargon home') + devs.smargon_move_home() + print('try to move aerotech') + devs.aerotech_pos = ABR_POS_MOUNT def m2se(devs: BeamlineDevices, cfg: BeamlineConfig): pass def sa2se(devs: BeamlineDevices, cfg: BeamlineConfig): - print('move collimator and scintillator to 20') - devs.collimator = 20.0 - devs.scintillator = 20.0 - print('move smargon home') - devs.smargon_move_home() - print('try to move aerotech') - devs.aerotech_pos = ABR_POS_MOUNT - print('move bl to park') - devs.reflector_up = StagePositionEnum.PARK - print('move bs to park') - devs.beamstop_stage_up = StagePositionEnum.PARK - #print('move cryo to park') - #devs.__cryojet_pos = StagePositionEnum.PARK + # print('move collimator and scintillator to 20') + # devs.collimator = 20.0 + # devs.scintillator = 20.0 + # print('move smargon home') + # devs.smargon_move_home() + # print('try to move aerotech') + # devs.aerotech_pos = ABR_POS_MOUNT + # print('move bl to park') + # devs.reflector_up = StagePositionEnum.PARK + # print('move bs to park') + # devs.beamstop_stage_up = StagePositionEnum.PARK + # #print('move cryo to park') + # #devs.__cryojet_pos = StagePositionEnum.PARK + try: + devs.bec_worker.planner.move_to(BeamlineState.MANUAL_SAMPLE_EXCHANGE) + devs.aerotech_pos = cfg.abr_meas_pos + except Exception as e: + devs.aerotech_pos = cfg.abr_meas_pos + raise def sa2rse(devs: BeamlineDevices, cfg: BeamlineConfig): common_2rse(devs, cfg) +def sa2xtal_snapshot(devs:BeamlineDevices, cfg:BeamlineConfig): + devs.bec_worker.planner.move_to(BeamlineState.XTAL_SNAPSHOT) + +def dc2xtal_snapshot(devs:BeamlineDevices, cfg:BeamlineConfig): + devs.bec_worker.planner.move_to(BeamlineState.XTAL_SNAPSHOT) + +def xtal_snapshot2dc(devs:BeamlineDevices, cfg:BeamlineConfig): + devs.bec_worker.planner.move_to(BeamlineState.DATA_COLLECTION) + +def xtal_snapshot2sa(devs:BeamlineDevices, cfg:BeamlineConfig): + devs.bec_worker.planner.move_to(BeamlineState.SAMPLE_ALIGNMENT) + def dc2rse(devs: BeamlineDevices, cfg: BeamlineConfig): common_2rse(devs, cfg) def se2sa(devs: BeamlineDevices, cfg: BeamlineConfig): - devs.reflector_up = StagePositionEnum.MEASURE + devs.bec_worker.planner.move_to(BeamlineState.SAMPLE_ALIGNMENT) devs.aerotech_pos = cfg.abr_meas_pos + devs.smargon_move_home() def rse2sa(devs: BeamlineDevices, cfg: BeamlineConfig): se2sa(devs, cfg) def sa2dc(devs: BeamlineDevices, cfg: BeamlineConfig): - pass + devs.bec_worker.move_to(BeamlineState.DATA_COLLECTION) def dc2sa(devs: BeamlineDevices, cfg: BeamlineConfig): - pass + devs.bec_worker.planner.move_to(BeamlineState.SAMPLE_ALIGNMENT) + devs.aerotech_pos = cfg.abr_meas_pos + devs.smargon_move_home() def sa2xrf(devs: BeamlineDevices, cfg: BeamlineConfig): """sample alignment to XrfCollection""" - pass - + devs.bec_worker.planner.move_to(BeamlineState.FLUX_MEASUREMENT) def xrf2sa(devs: BeamlineDevices, cfg: BeamlineConfig): """XrfCollection to sample alignment""" @@ -118,7 +146,7 @@ def ba2bl(devs: BeamlineDevices, cfg: BeamlineConfig): devs.scintillator = 20.0 def sa2dh(devs: BeamlineDevices, cfg: BeamlineConfig): - devs.scintillator = 20.0 + common_2rse(devs, cfg) if devs.tell.get_mounted_sample() is not None: try: # Best effort try to unmount @@ -128,8 +156,7 @@ def sa2dh(devs: BeamlineDevices, cfg: BeamlineConfig): devs.tell.dry(wait_cold=-1, wait=False) def dh2sa(devs: BeamlineDevices, cfg: BeamlineConfig): - devs.scintillator = 20.0 - devs.reflector_up = StagePositionEnum.MEASURE + devs.bec_worker.planner.move_to(BeamlineState.SAMPLE_ALIGNMENT) if __name__ == "__main__": from aare.common.beamline import mx_beamline diff --git a/src/aare/devices/bec_worker.py b/src/aare/devices/bec_worker.py index 836c7513..308e3be5 100644 --- a/src/aare/devices/bec_worker.py +++ b/src/aare/devices/bec_worker.py @@ -2,6 +2,7 @@ from bec_ipython_client import BECIPythonClient from bec_ipython_client.signals import OperationMode from bec_lib.service_config import ServiceConfig from bec_lib.procedures.helper import FrontendProcedureHelper, BackendProcedureHelper +from pxii_bec.macros.planner import BeamlineState from aare.common.beamline import MXBeamline, mx_beamline @@ -30,15 +31,23 @@ class BECClientWorker: service_config.config["log_writer"]["base_path"]='./logs' print(service_config.config) self.client = BECIPythonClient(config=service_config,mode=OperationMode.Procedure) - #self.client.config.update_session_with_file("/sls/x10sa/config/bec/production/bec/bec_lib/bec_lib/config_helper.py") self.client.start() + #self.client.config.update_session_with_file("/sls/x10sa/config/bec/production/bec/bec_lib/bec_lib/config_helper.py") self.dev = self.client.device_manager.devices self.scans = self.client.scans self.macros = self.client.macros self.load_user_macros() self.helper = FrontendProcedureHelper(self.client.connector) - # self.ProtectedDevices = OurBECDevices(BECDevices=self.dev) + try: + self.planner = self.__planner() + except Exception as e: + raise Exception(f"Error: {e}") + def __planner(self): + d = init_se_devices() + states = get_states() + deps = planner_deps() + return StateManager(states=states, deps=deps, devices=d) def run_macro(self, macro_name:str, *args, queue:str = "default", **kwargs): return self.client.proc.run_macro(macro_name, *args, queue=queue) @@ -54,6 +63,9 @@ class BECClientWorker: print(f"Error: {e}") return None + def move_to(self, state:BeamlineState): + return self.planner.move_to(state) + def show_all_devices(self): return self.dev.show_all @@ -105,18 +117,36 @@ if __name__ == "__main__": client = BECClientWorker(beamline) except Exception as e: print(f"Error: {e}") - import sys - sys.exit(1) + try: + client.shutdown_client() + except Exception as e: + import sys + sys.exit(1) client.show_all_devices() - client.list_all_macros() - client.load_user_macros() + client.planner.current_state() + client.planner.move_to(BeamlineState.SAMPLE_ALIGNMENT) + time.sleep(2.0) + client.planner.current_state() + client.move_to(BeamlineState.SAMPLE_ALIGNMENT) + time.sleep(2.0) + client.planner.current_state() + + # client.load_user_macros() #client.macros.mono_pitch_scan(False) - status=client.proc.run_macro("mono_pitch_scan", queue="test") - print(status) - status.wait() - status.cancel() - print(status) + # status = client.run_macro("planner.current_state", queue="default") + #client.planner.move_to('manual_sample_exchange') + # print(status) + # status.wait() + # print(status) + #try: + #status=client.proc.run_macro("mono_pitch_scan", queue="test") + #planner.move_to('manual_sample_exchange') + + # print(status) + # status.wait() + # status.cancel() + # print(status) #client.client.macros.mono_pictch_scan(False) # try: # # a=client.a2e_runner(160, "iln")