diff --git a/csaxs_bec/bec_ipython_client/plugins/omny/omny_sample_transfer_mixin.py b/csaxs_bec/bec_ipython_client/plugins/omny/omny_sample_transfer_mixin.py index a9300cf..c279e31 100644 --- a/csaxs_bec/bec_ipython_client/plugins/omny/omny_sample_transfer_mixin.py +++ b/csaxs_bec/bec_ipython_client/plugins/omny/omny_sample_transfer_mixin.py @@ -23,12 +23,24 @@ class OMNYTransferError(Exception): pass class OMNYSampleTransferMixin: + + def __init__(self) -> None: + self.shuttle_was_aligned = {} + self.shuttle_was_aligned[1]=False + self.shuttle_was_aligned[2]=False + self.shuttle_was_aligned[3]=False + self.shuttle_was_aligned[4]=False + self.shuttle_was_aligned[5]=False + self.shuttle_was_aligned[6]=False + + + @staticmethod def _get_user_param_safe(device, var): - param = dev[device].user_parameter - if not param or param.get(var) is None: - raise ValueError(f"Device {device} has no user parameter definition for {var}.") - return param.get(var) + param = dev[device].user_parameter + if not param or param.get(var) is None: + raise ValueError(f"Device {device} has no user parameter definition for {var}.") + return param.get(var) def _otransfer_shuttle_aligner_down(self): if not dev.oshuttlealign.get_motor_limit_switch()[1]: @@ -88,132 +100,132 @@ class OMNYSampleTransferMixin: pass def _otransfer_shuttle_align(self): - self._otransfer_gripper_to_park_z() - self._otransfer_oparkz_safe_shuttle_operation() - self._otransfer_shuttle_aligner_down() + _active_shuttle_pos = self._oparkz_slot_check() + if self.shuttle_was_aligned[_active_shuttle_pos]==True: + print("shuttle is already aligned.") + else: + self._otransfer_gripper_to_park_z() + self._otransfer_oparkz_safe_shuttle_operation() + self._otransfer_shuttle_aligner_down() - #todo - #global _otransfer_shuttle_was_aligned - #if (_otransfer_shuttle_was_aligned==0) { + #make sure shuttle closed + self._otransfer_ensure_shuttle_closed() + self._omnycam_parking() - #make sure shuttle closed - self._otransfer_ensure_shuttle_closed() - self._omnycam_parking() + print("Aligning the shuttle. Please wait.") + #ensure safety threads are running + dev.oshuttleopen.controller.socket_put_confirmed("XQ#SAFETY") - print("Aligning the shuttle") - #ensure safety threads are running - dev.oshuttleopen.controller.socket_put_confirmed("XQ#SAFETY") + #ensure aligner is in down position + #if (!_ogalil_high_limit_set(1,7)) + #{ + #print("Strange, the aligner is not in the down position. Moving down.") + #_ogalil_drive_to_limit(1,7,1) + #} + #sleep(0.1) - #ensure aligner is in down position - #if (!_ogalil_high_limit_set(1,7)) - #{ - #print("Strange, the aligner is not in the down position. Moving down.") - #_ogalil_drive_to_limit(1,7,1) - #} - #sleep(0.1) + ################################### + # + # This is a routine for broken hardware + # + # The positive movement moves the aligner down. From the geometry + # of the setup, the negative limit switch will be activated after the + # positive limit switch, even in a positive movement + # We have to use this property because the positive switch is stuck. + ################################### - ################################### - # - # This is a routine for broken hardware - # - # The positive movement moves the aligner down. From the geometry - # of the setup, the negative limit switch will be activated after the - # positive limit switch, even in a positive movement - # We have to use this property because the positive switch is stuck. - ################################### - - # ensure we are in negative switch (with aligner down) - if not dev.oshuttlealign.get_motor_limit_switch()[0]: - print("Not in correct start position for alignment.") - dev.oshuttlealign.controller.socket_put_confirmed("MO") - if self.OMNYTools.yesno("Shall I try to move it to the correct start position? Do this only once!"): - print("starting...") - dev.oshuttlealign.controller.socket_put_confirmed("SHH") - dev.oshuttlealign.controller.socket_put_confirmed("PRH=200") - time.sleep(0.01) - dev.oshuttlealign.controller.socket_put_confirmed("LDH=1") - dev.oshuttlealign.controller.socket_put_confirmed("BGH") - time.sleep(1) + # ensure we are in negative switch (with aligner down) + if not dev.oshuttlealign.get_motor_limit_switch()[0]: + print("Not in correct start position for alignment.") dev.oshuttlealign.controller.socket_put_confirmed("MO") - dev.oshuttlealign.controller.socket_put_confirmed("LDH=0") - else: - raise OMNYTransferError("issue with aligner") - - # now start aligner movement + if self.OMNYTools.yesno("Shall I try to move it to the correct start position? Do this only once!"): + print("starting...") + dev.oshuttlealign.controller.socket_put_confirmed("SHH") + dev.oshuttlealign.controller.socket_put_confirmed("PRH=200") + time.sleep(0.01) + dev.oshuttlealign.controller.socket_put_confirmed("LDH=1") + dev.oshuttlealign.controller.socket_put_confirmed("BGH") + time.sleep(1) + dev.oshuttlealign.controller.socket_put_confirmed("MO") + dev.oshuttlealign.controller.socket_put_confirmed("LDH=0") + else: + raise OMNYTransferError("issue with aligner") + + # now start aligner movement - # disable negative switch - dev.oshuttlealign.controller.socket_put_confirmed("LDH=2") + # disable negative switch + dev.oshuttlealign.controller.socket_put_confirmed("LDH=2") - # move negative direction (ie up) and check out of negative switch - dev.oshuttlealign.controller.socket_put_confirmed("SHH") - dev.oshuttlealign.controller.socket_put_confirmed("SPH=3000") - dev.oshuttlealign.controller.socket_put_confirmed("ACH=60000") - dev.oshuttlealign.controller.socket_put_confirmed("DCH=60000") + # move negative direction (ie up) and check out of negative switch + dev.oshuttlealign.controller.socket_put_confirmed("SHH") + dev.oshuttlealign.controller.socket_put_confirmed("SPH=3000") + dev.oshuttlealign.controller.socket_put_confirmed("ACH=60000") + dev.oshuttlealign.controller.socket_put_confirmed("DCH=60000") - dev.oshuttlealign.controller.socket_put_confirmed("PRH=-5000") - time.sleep(0.01) - dev.oshuttlealign.controller.socket_put_confirmed("BGH") - while(self._otransfer_wait_aligner_movement()==True): - time.sleep(0.2) + dev.oshuttlealign.controller.socket_put_confirmed("PRH=-5000") + time.sleep(0.01) + dev.oshuttlealign.controller.socket_put_confirmed("BGH") + while(self._otransfer_wait_aligner_movement()==True): + time.sleep(0.2) - if dev.oshuttlealign.get_motor_limit_switch()[0]: - dev.oshuttlealign.controller.socket_put_confirmed("MOH") - raise OMNYTransferError("Aligner did not move or switch error.") + if dev.oshuttlealign.get_motor_limit_switch()[0]: + dev.oshuttlealign.controller.socket_put_confirmed("MOH") + raise OMNYTransferError("Aligner did not move or switch error.") - # enable negative switch again - # but disable forward switch (is broken) - dev.oshuttlealign.controller.socket_put_confirmed("LDH=1") + # enable negative switch again + # but disable forward switch (is broken) + dev.oshuttlealign.controller.socket_put_confirmed("LDH=1") - # movements for alignment and down again - dev.oshuttlealign.controller.socket_put_confirmed("PRH=-19500") - time.sleep(0.01) - dev.oshuttlealign.controller.socket_put_confirmed("BGH") - while(self._otransfer_wait_aligner_movement()==True): - time.sleep(0.2) - time.sleep(0.5) - dev.oshuttlealign.controller.socket_put_confirmed("PRH=3000") - time.sleep(0.01) - dev.oshuttlealign.controller.socket_put_confirmed("BGH") - while(self._otransfer_wait_aligner_movement()==True): - time.sleep(0.2) - time.sleep(0.5) - dev.oshuttlealign.controller.socket_put_confirmed("PRH=-3000") - time.sleep(0.01) - dev.oshuttlealign.controller.socket_put_confirmed("BGH") - time.sleep(0.01) - while(self._otransfer_wait_aligner_movement()==True): - time.sleep(0.2) - time.sleep(0.5) - dev.oshuttlealign.controller.socket_put_confirmed("PRH=23500") - time.sleep(0.01) - dev.oshuttlealign.controller.socket_put_confirmed("BGH") - time.sleep(0.01) - while(self._otransfer_wait_aligner_movement()==True): - time.sleep(0.2) - #_ogalil_put_confirmed( 1,"MOH") - time.sleep(0.2) - - # move down (positive movement) and check for negative (backward motion) switch - searchwrongendswitch=0 - #_ogalil_put_confirmed( 1,"SHH") - - while searchwrongendswitch<22 and dev.oshuttlealign.get_motor_limit_switch()[0] == False: - dev.oshuttlealign.controller.socket_put_confirmed("PRH=200") + # movements for alignment and down again + dev.oshuttlealign.controller.socket_put_confirmed("PRH=-19500") + time.sleep(0.01) + dev.oshuttlealign.controller.socket_put_confirmed("BGH") + while(self._otransfer_wait_aligner_movement()==True): + time.sleep(0.2) + time.sleep(0.5) + dev.oshuttlealign.controller.socket_put_confirmed("PRH=3000") + time.sleep(0.01) + dev.oshuttlealign.controller.socket_put_confirmed("BGH") + while(self._otransfer_wait_aligner_movement()==True): + time.sleep(0.2) + time.sleep(0.5) + dev.oshuttlealign.controller.socket_put_confirmed("PRH=-3000") time.sleep(0.01) dev.oshuttlealign.controller.socket_put_confirmed("BGH") time.sleep(0.01) while(self._otransfer_wait_aligner_movement()==True): time.sleep(0.2) - searchwrongendswitch+=1 - if dev.oshuttlealign.get_motor_limit_switch()[0]: - print("Aligner is back down.") + time.sleep(0.5) + dev.oshuttlealign.controller.socket_put_confirmed("PRH=23500") + time.sleep(0.01) + dev.oshuttlealign.controller.socket_put_confirmed("BGH") + time.sleep(0.01) + while(self._otransfer_wait_aligner_movement()==True): + time.sleep(0.2) + #_ogalil_put_confirmed( 1,"MOH") + time.sleep(0.2) - dev.oshuttlealign.controller.socket_put_confirmed("MOH") - #todo - #_otransfer_shuttle_was_aligned=1 + # move down (positive movement) and check for negative (backward motion) switch + searchwrongendswitch=0 + #_ogalil_put_confirmed( 1,"SHH") - if not dev.oshuttlealign.get_motor_limit_switch()[0]: - raise OMNYTransferError("The shuttle aligner did not move back.") + while searchwrongendswitch<22 and dev.oshuttlealign.get_motor_limit_switch()[0] == False: + dev.oshuttlealign.controller.socket_put_confirmed("PRH=200") + time.sleep(0.01) + dev.oshuttlealign.controller.socket_put_confirmed("BGH") + time.sleep(0.01) + while(self._otransfer_wait_aligner_movement()==True): + time.sleep(0.2) + searchwrongendswitch+=1 + if dev.oshuttlealign.get_motor_limit_switch()[0]: + print("Aligner is back down.") + + dev.oshuttlealign.controller.socket_put_confirmed("MOH") + + self.shuttle_was_aligned[_active_shuttle_pos]=True + + if not dev.oshuttlealign.get_motor_limit_switch()[0]: + raise OMNYTransferError("The shuttle aligner did not move back.") def _otransfer_shield_open(self, pin_position): if(pin_position>0 and pin_position<7): @@ -241,6 +253,9 @@ class OMNYSampleTransferMixin: while self._otransfer_wait_opener_movement()==True: time.sleep(0.1) dev.oshuttleopen.controller.socket_put_confirmed("MOG") + print("Shuttle is open.") + else: + print("Shuttle is open already.") if not self._otransfer_is_shuttle_open(): raise OMNYTransferError("Did not manage to open the lid") @@ -420,9 +435,6 @@ class OMNYSampleTransferMixin: raise OMNYTransferError("System is in transfer mode.") def otransfer_park_slot(self,slot_number:int): - #todo - #global _otransfer_shuttle_was_aligned - #_otransfer_shuttle_was_aligned=0 if slot_number < 2 or slot_number > 6: raise OMNYTransferError(f"Invalid slot number {slot_number} specified. Valid numbers range from 2 to 6.") if slot_number == 2: @@ -442,15 +454,15 @@ class OMNYSampleTransferMixin: raise OMNYTransferError(f"Invalid slot number {slot_number} specified. Valid numbers range from 2 to 6.") #if the valve of the loadlock is not closed, ask before movement #todo if(epics_get("XOMNY-ES1-LL1VG1:POSITION")!="CLOSED") { - user_input = input("Please confirm that the leica transfer is in back position [y/n].") - if user_input != "y": - raise OMNYTransferError + if self.OMNYTools.yesno("Please confirm that the leica transfer is in back position."): + raise OMNYTransferError("Leica shuttle is not in back position.") else: self._oparkz_leica_slot(slot_number) def _oparkz_leica_slot(self, slot_number: int): if slot_number < 2 or slot_number > 6: raise OMNYTransferError(f"Invalid slot number {slot_number} specified. Valid numbers range from 2 to 6.") + self.shuttle_was_aligned[slot_number]=False if slot_number == 2: self._oparkz_drive_and_check(-6-29*3-42-.05) elif slot_number == 3: @@ -527,7 +539,10 @@ class OMNYSampleTransferMixin: #make sure shuttle closed - self._otransfer_ensure_shuttle_closed() + if pin_position>6 or pin_position==0: + if dev.otransx.get().readback > -2: + self._otransfer_gripper_to_park_z() + self._otransfer_ensure_shuttle_closed() zoffsettransfer=0 xoffsettransfer=0 @@ -559,7 +574,8 @@ class OMNYSampleTransferMixin: if pin_position in range(1,10): #if gripper is at ST, this will move the gripper close to the parking #lot prior opening the shuttle - self._otransfer_gripper_to_park_z() + if dev.otransx.get().readback < -2: + self._otransfer_gripper_to_park_z() self._otransfer_shuttle_align() self._otransfer_shield_open(pin_position) _otransy_approach_height=otrans_pin_positions[pin_position][1] #vertical position diff --git a/csaxs_bec/devices/omny/galil/galil_ophyd.py b/csaxs_bec/devices/omny/galil/galil_ophyd.py index 6dbba48..175b3f3 100644 --- a/csaxs_bec/devices/omny/galil/galil_ophyd.py +++ b/csaxs_bec/devices/omny/galil/galil_ophyd.py @@ -59,6 +59,13 @@ class GalilController(Controller): "all_axes_referenced", ] + OKBLUE = '\033[94m' + OKCYAN = '\033[96m' + OKGREEN = '\033[92m' + WARNING = '\033[93m' + FAIL = '\033[91m' + ENDC = '\033[0m' + @threadlocked def socket_put(self, val: str) -> None: self.sock.put(f"{val}\r".encode()) @@ -277,14 +284,27 @@ class GalilController(Controller): if axis is not None: if self.sock.host == "mpc3217.psi.ch": #case of omny. possibly consider moving to ogalil + motor_on = self.is_motor_on(axis.axis_Id) + if motor_on == True: + motor_on = self.WARNING + "ON" + self.ENDC + else: + motor_on = "OFF" + + folerr_status = self.folerr_status(axis.axis_Id_numeric) + if folerr_status == True: + folerr_status = self.WARNING + "True" + self.ENDC + else: + folerr_status = "False" + position = axis.readback.read().get(axis.name).get("value") + position = f'{position:.3f}' t.add_row( [ f"{axis.axis_Id_numeric}/{axis.axis_Id}", axis.name, self.axis_is_referenced(axis.axis_Id_numeric), - self.is_motor_on(axis.axis_Id), + motor_on, self.get_motor_limit_switch(axis.axis_Id), - axis.readback.read().get(axis.name).get("value"), + position, self.motor_temperature(axis.axis_Id_numeric), self.folerr_status(axis.axis_Id_numeric), ] diff --git a/csaxs_bec/devices/omny/galil/ogalil_ophyd.py b/csaxs_bec/devices/omny/galil/ogalil_ophyd.py index 771712e..1318bed 100644 --- a/csaxs_bec/devices/omny/galil/ogalil_ophyd.py +++ b/csaxs_bec/devices/omny/galil/ogalil_ophyd.py @@ -98,6 +98,13 @@ class OMNYGalilController(GalilController): "_ogalil_folerr_not_ignore", ] + OKBLUE = '\033[94m' + OKCYAN = '\033[96m' + OKGREEN = '\033[92m' + WARNING = '\033[93m' + FAIL = '\033[91m' + ENDC = '\033[0m' + def on(self) -> None: """Open a new socket connection to the controller""" self._ogalil_switchsocket_switch_all_on()