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 4ee6819..ea7f30b 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 @@ -5,6 +5,9 @@ from rich import box from rich.console import Console from rich.table import Table +from csaxs_bec.bec_ipython_client.plugins.cSAXS import epics_get, epics_put, fshopen, fshclose + + class OMNYTransferError(Exception): pass @@ -495,7 +498,7 @@ class OMNYSampleTransferMixin: def _otransfer_get_toppin_position(self) -> float: return(float(dev.otransy.controller.socket_put_and_receive("MGtoppin"))) - def _otransfer_move_gripper_to_pin_pos(self, pin_position: int): + def _otransfer_move_gripper_to_pin_pos(self, pin_position: int) -> float: #pos 0 ST / position in separate macro #pos 1 to 6 at sample shuttle @@ -683,615 +686,434 @@ class OMNYSampleTransferMixin: toppin = self._otransfer_get_toppin_position() print(f"TopPin position is {toppin:.3f} mm") if self._otransfer_get_toppin_position()>-25.4: - #continue programming here - # - # - # - # printf("THIS IS LARGER THAN THE CURRENT THRESHOLD OF -25.4. ARE YOU SURE THE PIN IS OK AND DOES NOT HAVE A DAMAGE IN THE BOTTOM?\n") - printf("All OK? Please confirm. Y/n?") - } + print("THIS IS LARGER THAN THE CURRENT THRESHOLD OF -25.4. ARE YOU SURE THE PIN IS OK AND DOES NOT HAVE A DAMAGE IN THE BOTTOM?") + user_input = input("All OK? Please confirm. y/n?") #we are mounting a sample - if (mntprgs == 1) { - printf("All OK? Please confirm. First confirmation = sample release. Y/n?") - } - if (mntprgs == 0) { - printf("All OK? Please confirm. Y/n?") - } + elif mntprgs == 1: + print("All OK? Please confirm. First confirmation = sample release. y/n?") + elif mntprgs == 0: + print("All OK? Please confirm. y/n?") - if(!yesno(1)) - exit - else - _ogalil_put_confirmed(0,"confirm=1") - } -} -}' + if user_input == "y": + dev.otransy.controller.socket_put_confirmed("confirm=1") + else: + raise OMNYTransferError("The sample mount progress was aborted by user.") -def _otransfer_check_sensor_connected '{ -local sensorvoltage -_ogalil_put(0,"MG@AN[8001]") -sensorvoltage = _ogalil_get(0) -local sensorvoltagetarget -sensorvoltagetarget = -2.94 -if(sensorvoltage > sensorvoltagetarget-0.5 && sensorvoltage < sensorvoltagetarget+0.5) -{ - #printf("Sensorvoltage is %.2f V. Sensor seems connected.\n",sensorvoltage) -} -else -{ - printf("Sensorvoltage is %.2f V. This indicates a sensor error.\n",sensorvoltage) - exit -} + def _otransfer_check_sensor_connected(self): + sensorvoltage = (float(dev.otransy.controller.socket_put_and_receive("MG@AN[8001]"))) + gripper_sensorvoltagetarget = self._get_user_param_safe(dev.otransy, "gripper_sensorvoltagetarget") + if not (sensorvoltage > gripper_sensorvoltagetarget-0.5 and sensorvoltage < gripper_sensorvoltagetarget): + raise OMNYTransferError(f"Sensorvoltage is {sensorvoltage:.2f} V. This indicates a sensor error.") -}' + def otransfer_get_sample(self, pin_position: int): + self._omnycam_parking() + user_input = ("Please confirm that currently there is no sample in the gripper. It would be dropped! y/n?") + if user_input != "y": + raise OMNYTransferError("Transfer process has been manually aborted.") + self._otransfer_check_sensor_connected() + if not self._otransfer_check_sample_available_at_position(pin_position,0): + raise OMNYTransferError(f"There is no sample available at position {pin_position}") -def otransfer_get_sample '{ -if ($# != 1 ) { -printf("Wrong number of arguments. otransfer_get_sample \n") -exit -} -_otransfer_gripper_get_sample($1) -}' +# global _otransy_approach_height +# global _ogalil_encoder_steps_per_mm -def _otransfer_gripper_get_sample(pin_position) '{ -if(pin_position!=int(pin_position)) -{ - printf("The position has to be an integer number.\n") - exit; -} -_omnycam_parking_overview -printf("Please confirm that currently there is no sample in the gripper. It would be dropped! Y/n?") -if(!yesno(1)) - exit; -_otransfer_check_sensor_connected -if(!_otransfer_check_sample_available_at_position(pin_position,0)) - exit; -global _otransy_approach_height -global _ogalil_encoder_steps_per_mm - -if(pin_position==0 || pin_position==100) -{ -# oeye_cam_in -self._omnycam_samples() -# if (_rt_status_feedback() == 0) { -# printf("May the feedback be disabled? Y/n?") -# if(!yesno(1)) -# exit; -#} -# rt_feedback_disable -} -else -{ -_omnycam_parking -} - -_otransfer_move_gripper_to_pin_pos(pin_position) - -_otransfer_controller_enable_mount_mode -_ogalil_put_confirmed(0,sprintf("getaprch=%.0f",_otransy_approach_height*_ogalil_encoder_steps_per_mm)) - -printf("Ready. Press Enter to start the unmount process now...") -if(yesno(1)) -{ -} - -_ogalil_put_confirmed(0,"XQ#GRGET") - -printf("The Unmount process started.\n") - - _otransfer_confirm - - _otransfer_controller_disable_mount_mode - #update database - _otransfer_check_sample_available_at_position(pin_position,1) - - _otransfer_shield_close(pin_position) - - -otransfer_storage -#_omnycam_standby -}' - -def _otransfer_stage_to_ST(pin_position) '{ -_otransfer_gripper_to_park_z - -_otransfer_ensure_shield_parking_closed - -if (A[oshield] < 15) -{ - printf("The sample stage shield is not closed, though it is supposed to be. Aborting.\n") - exit -} - -#if xray eye is in, move it out -if(A[oeyez]<-5) - oeye_cam_in - -#old gripper motor -#check ST position and move gripper to ST -#umv otransz -18 -#umv osamroy -25 osamy 2.7 osamx 0 otransx -213 -#umv otransz 0 -#umv otransx -458.5000 - -#move gripper to ST -#now much more direct because motor transz is shorter -#also incorporate simultaneous cam in movement - -if (_rt_status_feedback() == 0) { - printf("May the feedback be disabled? Y/n?") - if(!yesno(1)) - exit; -} - -rt_feedback_disable - -if(rt_at_omny_hutch==0) - fshon - -if (A[oeyez]<-20) -{ - printf("Eyez is too close to the sample stage for unknown reason. Aborting.\n") - exit -} - -#eye did not move up yet, so we do it here simultaneous to rest in steps -if(A[oeyey] < -50) -{ - _ogalil_put( 2,"axspeed[7]=10000") - umv otransz 0 otransx -100 oeyey -45 oeyez -2 -} -else -{ - umv otransz 0 otransx -100 oeyez -2 -} - -if (fabs(A[oeyez]+2)>0.1) -{ - printf("The oeye is too close in z for transfer. ERROR! Aborting.\n") - exit -} - -#if the osa is out of the shield, we already move the shield with the other stages -if(A[oosaz]<0.1 && A[oosax] < -1.5) - { - if(A[oeyey] < -40) - { - umv osamroy -25 osamy 2.7 osamx 0 otransx -350 oeyex 0 oeyey -15 - } + if pin_position==0 or pin_position==100: + # oeye_cam_in + self._omnycam_samples() + # if (_rt_status_feedback() == 0) { + # printf("May the feedback be disabled? Y/n?") + # if(!yesno(1)) + # exit; + #} + # rt_feedback_disable else - { - umv osamroy -25 osamy 2.7 osamx 0 otransx -350 oeyex 0 - } - umv oshield 0 otransx -458.1545+0.05 oeyey -4.8 - umv oshield -12 otransz -45.6494 - } -else - { - umv osamroy -25 osamy 2.7 osamx 0 otransx -458.1545+0.05 oeyex 0 oeyey -4.8 - } -oeye_cam_in - -_otransfer_shield_open(pin_position) -umv otransz -45.6494 - -}' - -def _otransfer_stage_to_FZP '{ - -printf("This routine needs checking after park pos of gripper and new transfer stages changed.\n") -exit - -printf("Please confirm that the npoint piezo controller is off. y/n.") -if(!yesno(1)) - exit - -_otransfer_gripper_to_park_z - -#put overview camera in -oeye_cam_in -umv otransz 0 otransx -100 oeyez -2 -umv osamroy -25 osamy 2.7 osamx 0 otransx -458.1567 oeyex 0 - -_oshield_ST_open -#this moves the osa out of the shield -#such then it can be moved out of the way -umv oosax 3.2 oosay 0.6 - -set_lm ofzpz -2.5 78 -umv ofzpz 78.6018 ofzpy 7.8604 ofzpx -0.8485 - -umv otransz -68.0006 - -# positions from manual change -#Sat Dec 04 10:52:31 2021 -# otransx otransy otransz ofzpx ofzpy ofzpz -#User -# High 33.0000 1.0000 11.0000 2.0000 3.0000 -2.5000 -# Current -458.1567 -17.8210 -68.0006 -0.8485 7.8604 78.6018 -# Low -459.0000 -41.0000 -70.5000 -2.0000 -1.0000 80.0000 -#Dial -# High 33.0000 1.0000 11.0000 2.0000 3.0000 2.5000 -# Current -458.1567 -17.8210 -68.0006 -0.8485 7.8604 -78.6018 -# Low -459.0000 -41.0000 -70.5000 -2.0000 -1.0000 -80.0000 + self._omnycam_parking() -}' + _otransy_approach_height = self._otransfer_move_gripper_to_pin_pos(pin_position) + self._otransfer_controller_enable_mount_mode() + -def _otransfer_stage_to_OSA '{ + _ogalil_encoder_steps_per_mm = 51200 + dev.otransy.controller.socket_put_confirmed(f"getaprch={_otransy_approach_height*_ogalil_encoder_steps_per_mm:.0f}") + + input("Ready. Press Enter to start the mount process now...") + + dev.otransy.controller.socket_put_confirmed("XQ#GRGET") + + print("The Unmount process started.\n") + self._otransfer_confirm() + + self._otransfer_controller_disable_mount_mode() + #update database + self._otransfer_check_sample_available_at_position(pin_position,1) + self._otransfer_shield_close(pin_position) + + self.otransfer_storage() -printf("This routine needs checking after park pos of gripper changed and new transfer stages.\n") -exit -if(A[ofzpz]>40) { -printf("The FZP stage is too close in z direction. Please move it to at least 60 mm or less upstream.\n") -exit -} -_otransfer_gripper_to_park_z + def _otransfer_stage_to_ST(self,pin_position): + self._otransfer_gripper_to_park_z() -#put overview camera in -oeye_cam_in + self._otransfer_ensure_shield_parking_closed() -umv otransz -18 -umv otransx -213 -umv otransz 0 -set_lm otransx -469 33 -umv otransx -467.0612 -_oshield_ST_open -#this moves the osa out of the shield -#such then it can be moved here -umv oosax 3.2 oosay 0.6 oosaz 0 -umv otransz -55.6013 -if(fabs(A[ofzpz]-77.7)>0.1) -{ - printf("FZP did not reach target position. Potentially the motor is too hot.\n") - exit -} + dev.oshield.read(cached=False) + oshield_current = dev.oshield.get().readback + if oshield_current < 15: + raise OMNYTransferError("The sample stage shield is not closed, though it is supposed to be. Aborting.") -}' + #if xray eye is in, move it out + oeyez_current = dev.oeyez.get().readback + if oeyez_current<-5: + self.oeye_cam_in() -def otransfer_storage '{ + #old gripper motor + #check ST position and move gripper to ST + #umv otransz -18 + #umv osamroy -25 osamy 2.7 osamx 0 otransx -213 + #umv otransz 0 + #umv otransx -458.5000 -local k + #move gripper to ST + #now much more direct because motor transz is shorter + #also incorporate simultaneous cam in movement -printf_red ("\nStatus of the parking station:\n\n") -printf (" 1 2 3 4 5 6\n") -for (k=1;k<7;k++) { -if (epics_get(sprintf("XOMNY-SAMPLE_DB_parking:%d.VAL",k)) == 1) - printf("%6s",epics_get(sprintf("XOMNY-SAMPLE_DB_parking:%d.DESC",k))) -else - printf(" ") -} -printf("\n\n ") -_oparkz_slot_check() + feedback_status = self.device_manager.devices.rtx.controller.feedback_is_running() + if feedback_status == True: + #feedback is running + user_input = input("May the feedback be disabled? y/n?") + if user_input != "y": + raise OMNYTransferError("Manual abort of sample transfer, need to disable feedback has not been confirmed.") -printf_blue ("\n\n--------------------------------------\n") -printf_red ("\nStatus of shuttle A") -for (k=1;k<7;k++) { -if (epics_get(sprintf("XOMNY-SAMPLE_DB_parking:%d.DESC",k)) == "A") - printf(" - installed at parking position %d", k) -} - printf("\n") + self.device_manager.devices.rtx.controller.feedback_disable() -for (k=1;k<7;k=k+2) { - printf("%25s",epics_get(sprintf("XOMNY-SAMPLE_DB_shuttle_A:%d.DESC",k))) - printf(" %d %d ", k, k+1) - printf("%-25s",epics_get(sprintf("XOMNY-SAMPLE_DB_shuttle_A:%d.DESC",k+1))) - printf("\n") -} -printf_red ("\nStatus of shuttle B") -for (k=1;k<7;k++) { -if (epics_get(sprintf("XOMNY-SAMPLE_DB_parking:%d.DESC",k)) == "B") - printf(" - installed at parking position %d", k) -} - printf("\n") + fshclose() -for (k=1;k<7;k=k+2) { - printf("%25s",epics_get(sprintf("XOMNY-SAMPLE_DB_shuttle_B:%d.DESC",k))) - printf(" %d %d ", k, k+1) - printf("%-25s",epics_get(sprintf("XOMNY-SAMPLE_DB_shuttle_B:%d.DESC",k+1))) - printf("\n") -} + if oeyez_current<-20: + raise OMNYTransferError("Eyez is too close to the sample stage for unknown reason. Aborting.") -printf_red ("\nStatus of shuttle C") -for (k=1;k<7;k++) { -if (epics_get(sprintf("XOMNY-SAMPLE_DB_parking:%d.DESC",k)) == "C") - printf(" - installed at parking position %d", k) -} - printf("\n") + #eye did not move up yet, so we do it here simultaneous to rest in steps + if oeyez_current < -50: + dev.oeyeyz.controller.socket_put_confirmed("axspeed[7]=10000") + umv(dev.otransz, 0, dev.otransx, -100, dev.oeyey, -45, dev.oeyez, -2) + else: + umv(dev.otransz, 0, dev.otransx, -100, dev.oeyez, -2) -for (k=1;k<7;k=k+2) { - printf("%25s",epics_get(sprintf("XOMNY-SAMPLE_DB_shuttle_C:%d.DESC",k))) - printf(" %d %d ", k, k+1) - printf("%-25s",epics_get(sprintf("XOMNY-SAMPLE_DB_shuttle_C:%d.DESC",k+1))) - printf("\n") -} -printf_blue ("\n--------------------------------------\n") + oeyez_current = dev.oeyez.get().readback -printf_red ("\nStatus of OMNY positions:\n\n") + if fabs(oeyez_current+2)>0.1: + raise OMNYTransferError("The oeye is too close in z for transfer. ERROR!") -printf(" Gripper ") -if (epics_get("XOMNY-SAMPLE_DB_omny:110.VAL") > 0) { - text_bf; - printf(" \"%s\" which is a ", epics_get("XOMNY-SAMPLE_DB_omny:110.DESC")); - if (epics_get("XOMNY-SAMPLE_DB_omny:110.VAL")==1) - printf("sample pin\n") - if (epics_get("XOMNY-SAMPLE_DB_omny:110.VAL")==2) - printf("FZP\n") - if (epics_get("XOMNY-SAMPLE_DB_omny:110.VAL")==3) - printf("OSA\n") - text_non_bf;} -else - printf(" no sample in gripper \n"); + #if the osa is out of the shield, we already move the shield with the other stages + + oosax_current = dev.oosax.get().readback + oosaz_current = dev.oosaz.get().readback -printf(" OMNY stage ") -if (epics_get("XOMNY-SAMPLE_DB_omny:0.VAL") == 1) { - text_bf; printf(" %s \n", epics_get("XOMNY-SAMPLE_DB_omny:0.DESC")); text_non_bf;} -else - printf(" free \n"); -printf("\n Fixed positions\n") -local array fixedpos[10] -fixedpos[0]=10 -fixedpos[1]=11 -fixedpos[2]=12 -fixedpos[3]=13 -fixedpos[4]=14 -fixedpos[5]=32 -fixedpos[6]=33 -fixedpos[7]=34 -fixedpos[8]=100 -fixedpos[9]=101 -for (k=0;k<10;k=k+1) { - printf(" Position %3d: ", fixedpos[k]) - if (epics_get(sprintf("XOMNY-SAMPLE_DB_omny:%d.VAL",fixedpos[k])) == 1) { - printf(" %s \n", epics_get(sprintf("XOMNY-SAMPLE_DB_omny:%d.DESC",fixedpos[k])))} - else - printf(" free \n"); -} + if oosaz_current<0.1 and oosax_current < -1.5: + oeyey_current = dev.oeyey.get().readback + if oeyey_current < -40: + umv(dev.osamroy, -25, dev.osamy, 2.7, dev.osamx, 0, dev.otransx, -350, dev.oeyex, 0, dev.oeyey, -15) + else: + umv(dev.osamroy, -25, dev.osamy, 2.7, dev.osamx, 0, dev.otransx, -350, dev.oeyex, 0) + umv(dev.oshield, 0, dev.otransx, -458.1545+0.05, dev.oeyey, -4.8) + umv(dev.oshield, -12, otransz, -45.6494) + else: + umv(dev.osamroy, -25, dev.osamy, 2.7, dev.osamx, 0, dev.otransx, -458.1545+0.05, dev.oeyex, 0, dev.oeyey, -4.8) + + self.oeye_cam_in() -printf("\n Special shuttles\n") - printf(" FZP shuttle: %s\n", epics_get("XOMNY-SAMPLE_DB_shuttle_FZP:0.DESC")) - printf(" OSA shuttle p0: %s\n", epics_get("XOMNY-SAMPLE_DB_shuttle_OSA:0.DESC")) - printf(" OSA shuttle p1: %s\n", epics_get("XOMNY-SAMPLE_DB_shuttle_OSA:1.DESC")) + self._otransfer_shield_open(pin_position) + umv(dev.otransz, -45.6494) -printf("\nTo change a position status: otransfer_modify_samples <0 for free, 1 for used>\n") -printf("To change the loading status of the parking stage use otransfer_modify_parking \n") -}' + def _otransfer_stage_to_FZP(self): -def _otransfer_modify_sample(_ocontainer, _oposition, _ostatus, _oname) '{ -#_ocontainer is A, B, C for the pin containers -#it can also be FZP, OSA and omny + raise OMNYTransferError("This routine needs commissioning after park pos of gripper and new transfer stages changed.\n") -if(_ocontainer=="omny") -{ -#free a position -if (_ostatus==0) -{ - epics_put(sprintf("XOMNY-SAMPLE_DB_%s:%d.VAL", _ocontainer, _oposition),0) - epics_put(sprintf("XOMNY-SAMPLE_DB_%s:%d.DESC", _ocontainer, _oposition),"-") -} + # printf("Please confirm that the npoint piezo controller is off. y/n.") + # if(!yesno(1)) + # exit -#sample at position -if (_ostatus>0) -{ - epics_put(sprintf("XOMNY-SAMPLE_DB_%s:%d.VAL",_ocontainer, _oposition),_ostatus) - epics_put(sprintf("XOMNY-SAMPLE_DB_%s:%d.DESC", _ocontainer, _oposition), _oname) -} -} -else -{ -#free a position -if (_ostatus==0) -{ - epics_put(sprintf("XOMNY-SAMPLE_DB_shuttle_%s:%d.VAL", _ocontainer, _oposition),0) - epics_put(sprintf("XOMNY-SAMPLE_DB_shuttle_%s:%d.DESC", _ocontainer, _oposition),"-") -} + # _otransfer_gripper_to_park_z -#sample at position -if (_ostatus>0) -{ - epics_put(sprintf("XOMNY-SAMPLE_DB_shuttle_%s:%d.VAL",_ocontainer, _oposition),_ostatus) - epics_put(sprintf("XOMNY-SAMPLE_DB_shuttle_%s:%d.DESC", _ocontainer, _oposition), _oname) -} -} + # #put overview camera in + # oeye_cam_in + # umv otransz 0 otransx -100 oeyez -2 + # umv osamroy -25 osamy 2.7 osamx 0 otransx -458.1567 oeyex 0 -}' + # _oshield_ST_open + # #this moves the osa out of the shield + # #such then it can be moved out of the way + # umv oosax 3.2 oosay 0.6 -def _otransfer_modify_parking(_oparkposition, _ocontainer) '{ -#_ocontainer is A, B, C for the pin containers -#it can also be FZP, and OSA + # set_lm ofzpz -2.5 78 + # umv ofzpz 78.6018 ofzpy 7.8604 ofzpx -0.8485 -_otransfer_check_parking(_ocontainer) + # umv otransz -68.0006 -#free a position -if (_ocontainer=="0") -{ - epics_put(sprintf("XOMNY-SAMPLE_DB_parking:%d.VAL", _oparkposition),0) - epics_put(sprintf("XOMNY-SAMPLE_DB_parking:%d.DESC", _oparkposition),"-") -} -else -{ - epics_put(sprintf("XOMNY-SAMPLE_DB_parking:%d.VAL", _oparkposition),1) - epics_put(sprintf("XOMNY-SAMPLE_DB_parking:%d.DESC", _oparkposition), _ocontainer) -} + # # positions from manual change + # #Sat Dec 04 10:52:31 2021 + # # otransx otransy otransz ofzpx ofzpy ofzpz + # #User + # # High 33.0000 1.0000 11.0000 2.0000 3.0000 -2.5000 + # # Current -458.1567 -17.8210 -68.0006 -0.8485 7.8604 78.6018 + # # Low -459.0000 -41.0000 -70.5000 -2.0000 -1.0000 80.0000 + # #Dial + # # High 33.0000 1.0000 11.0000 2.0000 3.0000 2.5000 + # # Current -458.1567 -17.8210 -68.0006 -0.8485 7.8604 -78.6018 + # # Low -459.0000 -41.0000 -70.5000 -2.0000 -1.0000 -80.0000 -}' -def _otransfer_check_sample_available_at_position(_osampleposition,_picked_it) '{ -#called with _picked_it == 0 prior transfer. This checks that the gripper is empty and that there -#is a sample to get from that position -#called with _picked_it == 1 after the gripper action. then the storage is modified accordingly to the action + # }' -local samplename + def _otransfer_stage_to_OSA(self): -#check that gripper is empty -if (epics_get("XOMNY-SAMPLE_DB_omny:110.VAL")>0) -{ - printf("There is sample \"%s\" in the gripper. Aborting.\n", epics_get("XOMNY-SAMPLE_DB_omny:110.DESC")) - exit -} + raise OMNYTransferError("This routine needs commissioning after park pos of gripper and new transfer stages changed.\n") -# _osampleposition 1 to 6 are in shuttles -if ((_osampleposition>0 && _osampleposition<7)) { - local activeparkingposition - local installedshuttle - activeparkingposition = _oparkz_slot_check() - if(activeparkingposition==10) - exit - installedshuttle = epics_get(sprintf("XOMNY-SAMPLE_DB_parking:%d.DESC", activeparkingposition)) - #is there a samle shuttle at this position? - if(installedshuttle == "A" || installedshuttle == "B" || installedshuttle == "C") - { - #is there a sample available? - if (epics_get(sprintf("XOMNY-SAMPLE_DB_shuttle_%s:%d.VAL",installedshuttle,_osampleposition))==1) - { - if(_picked_it==1) - { - samplename = epics_get(sprintf("XOMNY-SAMPLE_DB_shuttle_%s:%d.DESC",installedshuttle,_osampleposition)) - _otransfer_modify_sample(installedshuttle, _osampleposition, 0, "-") - _otransfer_modify_sample("omny",110,1,samplename) - } - return(1) - } - else - { - printf("There is no sample availabe at that position.\n") - return(0) - } - } - else - { - printf("There is no sample shuttle installed at the current parkz position.\n") + # if(A[ofzpz]>40) { + # printf("The FZP stage is too close in z direction. Please move it to at least 60 mm or less upstream.\n") + # exit + # } + + # _otransfer_gripper_to_park_z + + # #put overview camera in + # oeye_cam_in + + # umv otransz -18 + # umv otransx -213 + # umv otransz 0 + # set_lm otransx -469 33 + # umv otransx -467.0612 + # _oshield_ST_open + # #this moves the osa out of the shield + # #such then it can be moved here + # umv oosax 3.2 oosay 0.6 oosaz 0 + + # umv otransz -55.6013 + # if(fabs(A[ofzpz]-77.7)>0.1) + # { + # printf("FZP did not reach target position. Potentially the motor is too hot.\n") + # exit + # } + + # }' + + def otransfer_storage(self): + dev.omny_samples.show_all() + + + # def _otransfer_modify_sample(_ocontainer, _oposition, _ostatus, _oname): + # #_ocontainer is A, B, C for the pin containers + # #it can also be FZP, OSA and omny + + # if _ocontainer=="omny": + # if _oposition == 0: + + + + # #free a position + # if _ostatus==0: + # epics_put(sprintf("XOMNY-SAMPLE_DB_%s:%d.VAL", _ocontainer, _oposition),0) + # epics_put(sprintf("XOMNY-SAMPLE_DB_%s:%d.DESC", _ocontainer, _oposition),"-") + # #sample at position + # if _ostatus>0: + # epics_put(sprintf("XOMNY-SAMPLE_DB_%s:%d.VAL",_ocontainer, _oposition),_ostatus) + # epics_put(sprintf("XOMNY-SAMPLE_DB_%s:%d.DESC", _ocontainer, _oposition), _oname) + # else: + # #free a position + # if _ostatus==0: + # dev.omny_samples.unset_sample_slot(_ocontainer, _oposition) + # #sample at position + # if _ostatus>0: + # dev.omny_samples.set_sample_slot(_ocontainer, _oposition, _oname) + + +# def _otransfer_modify_parking(self, _oparkposition, _ocontainer): +# #_ocontainer is A, B, C for the pin containers +# #it can also be FZP, and OSA + +# self._otransfer_check_parking(_ocontainer) + +# #free a position +# if (_ocontainer=="0") +# { +# epics_put(sprintf("XOMNY-SAMPLE_DB_parking:%d.VAL", _oparkposition),0) +# epics_put(sprintf("XOMNY-SAMPLE_DB_parking:%d.DESC", _oparkposition),"-") +# } +# else +# { +# epics_put(sprintf("XOMNY-SAMPLE_DB_parking:%d.VAL", _oparkposition),1) +# epics_put(sprintf("XOMNY-SAMPLE_DB_parking:%d.DESC", _oparkposition), _ocontainer) +# } + +# }' + + def _otransfer_check_sample_available_at_position(self, _osampleposition, _picked_it): + #called with _picked_it == 0 prior transfer. This checks that the gripper is empty and that there + #is a sample to get from that position + #called with _picked_it == 1 after the gripper action. then the storage is modified accordingly to the action + + #check that gripper is empty + if dev.omny_samples.is_sample_in_gripper(): + raise OMNYTransferError("There is a sample in the gripper. Aborting.") + + # _osampleposition 1 to 6 are in shuttles + if _osampleposition>0 and _osampleposition<7: + activeparkingposition = self._oparkz_slot_check() + if(activeparkingposition==10): + raise OMNYTransferError("parking is not at a position for sample transfer") + installedshuttle = dev.omny_samples.get_shuttle_name_slot(activeparkingposition) + #is there a samle shuttle at this position? + if installedshuttle == "A" or installedshuttle == "B" or installedshuttle == "C": + #is there a sample available? + if dev.omny_samples.is_sample_slot_used(installedshuttle,_osampleposition): + if(_picked_it==1): + samplename = dev.omny_samples.get_sample_name(installedshuttle, _osampleposition) + #remove sample from slot and put to gripper + dev.omny_samples.unset_sample_slot(installedshuttle, _osampleposition) + dev.omny_samples.set_sample_in_gripper(samplename) + return(1) + else: + print("There is no sample availabe at that position.") + return(0) + else: + print("There is no sample shuttle installed at the current parkz position.") + return(0) + + # # _osampleposition 7 for FZPs + # if (_osampleposition==7) { + # local activeparkingposition + # local installedshuttle + # activeparkingposition = _oparkz_slot_check() + # if(activeparkingposition==10) + # exit + # installedshuttle = epics_get(sprintf("XOMNY-SAMPLE_DB_parking:%d.DESC", activeparkingposition)) + # #is there a samle shuttle at this position? + # if(installedshuttle == "FZP") + # { + # #is there an FZP available? + # if (epics_get("XOMNY-SAMPLE_DB_shuttle_FZP:0.VAL")==1) + # { + # if(_picked_it==1) + # { + # samplename = epics_get(sprintf("XOMNY-SAMPLE_DB_shuttle_FZP:0.DESC")) + # _otransfer_modify_sample(installedshuttle, 0, 0, "-") + # _otransfer_modify_sample("omny",110,2,samplename) + # } + # return(1) + # } + # else + # { + # printf("There is no FZP available.\n") + # return(0) + # } + # } + # else + # { + # printf("There is no FZP shuttle installed at the current parkz position.\n") + # return(0) + # } + # } + # # _osampleposition 8, 9 for OSAs + # if (_osampleposition==8||_osampleposition==9) { + # local activeparkingposition + # local installedshuttle + # activeparkingposition = _oparkz_slot_check() + # if(activeparkingposition==10) + # exit + # installedshuttle = epics_get(sprintf("XOMNY-SAMPLE_DB_parking:%d.DESC", activeparkingposition)) + # #is there a samle shuttle at this position? + # if(installedshuttle == "OSA") + # { + # #is there an OSA available? + # if ((epics_get("XOMNY-SAMPLE_DB_shuttle_OSA:0.VAL")==1 && _osampleposition == 8) \\ + # || (epics_get("XOMNY-SAMPLE_DB_shuttle_OSA:1.VAL")==1 && _osampleposition == 9)) + # { + # if(_picked_it==1) + # { + # samplename = epics_get(sprintf("XOMNY-SAMPLE_DB_shuttle_OSA:%d.DESC",(_osampleposition-8))) + # _otransfer_modify_sample(installedshuttle, (_osampleposition-8), 0, "-") + # _otransfer_modify_sample("omny",110,3,samplename) + # } + # return(1) + # } + # else + # { + # printf("There is no OSA available.\n") + # return(0) + # } + # } + # else + # { + # printf("There is no OSA shuttle installed at the current parkz position.\n") + # return(0) + # } + # } + + # _osampleposition for fixed positions + elif (_osampleposition>9 and _osampleposition<15) or (_osampleposition>31 and _osampleposition<35) or _osampleposition==100 or _osampleposition==101: + if dev.omny_samples.is_sample_slot_used('O',_osampleposition): + if(_picked_it==1): + samplename = dev.omny_samples.get_sample_name('O', _osampleposition) + dev.omny_samples.unset_sample_slot('O', _osampleposition) + dev.omny_samples.set_sample_in_gripper(samplename) + #FZP was picked + #if (_osampleposition == 10 || _osampleposition == 11 || _osampleposition == 100) + # _otransfer_modify_sample("omny",110,2,samplename) + #OSA was picked + #if (_osampleposition == 101) + # _otransfer_modify_sample("omny",110,2,samplename) + #pin was picked + #if (_osampleposition == 0 || _osampleposition == 12 || _osampleposition == 13 || _osampleposition == 14 || \\ + # _osampleposition == 32 || _osampleposition == 33 || _osampleposition == 34) + # _otransfer_modify_sample("omny",110,1,samplename) + return(1) + else: + printf("There is nothing to get from this position.") + return(0) + #sample stage + elif _osampleposition==0: + if dev.omny_samples.is_sample_in_samplestage(): + if(_picked_it==1): + samplename = dev.omny_samples.get_sample_name_in_samplestage() + dev.omny_samples.unset_sample_in_samplestage() + dev.omny_samples.set_sample_in_gripper(samplename) + #FZP was picked + #if (_osampleposition == 10 || _osampleposition == 11 || _osampleposition == 100) + # _otransfer_modify_sample("omny",110,2,samplename) + #OSA was picked + #if (_osampleposition == 101) + # _otransfer_modify_sample("omny",110,2,samplename) + #pin was picked + #if (_osampleposition == 0 || _osampleposition == 12 || _osampleposition == 13 || _osampleposition == 14 || \\ + # _osampleposition == 32 || _osampleposition == 33 || _osampleposition == 34) + # _otransfer_modify_sample("omny",110,1,samplename) + return(1) + else: + printf("There is no sample in the sample stage.") + return(0) + + return(0) - } -} -# _osampleposition 7 for FZPs -if (_osampleposition==7) { - local activeparkingposition - local installedshuttle - activeparkingposition = _oparkz_slot_check() - if(activeparkingposition==10) - exit - installedshuttle = epics_get(sprintf("XOMNY-SAMPLE_DB_parking:%d.DESC", activeparkingposition)) - #is there a samle shuttle at this position? - if(installedshuttle == "FZP") - { - #is there an FZP available? - if (epics_get("XOMNY-SAMPLE_DB_shuttle_FZP:0.VAL")==1) - { - if(_picked_it==1) - { - samplename = epics_get(sprintf("XOMNY-SAMPLE_DB_shuttle_FZP:0.DESC")) - _otransfer_modify_sample(installedshuttle, 0, 0, "-") - _otransfer_modify_sample("omny",110,2,samplename) - } - return(1) - } - else - { - printf("There is no FZP available.\n") - return(0) - } - } - else - { - printf("There is no FZP shuttle installed at the current parkz position.\n") - return(0) - } -} -# _osampleposition 8, 9 for OSAs -if (_osampleposition==8||_osampleposition==9) { - local activeparkingposition - local installedshuttle - activeparkingposition = _oparkz_slot_check() - if(activeparkingposition==10) - exit - installedshuttle = epics_get(sprintf("XOMNY-SAMPLE_DB_parking:%d.DESC", activeparkingposition)) - #is there a samle shuttle at this position? - if(installedshuttle == "OSA") - { - #is there an OSA available? - if ((epics_get("XOMNY-SAMPLE_DB_shuttle_OSA:0.VAL")==1 && _osampleposition == 8) \\ - || (epics_get("XOMNY-SAMPLE_DB_shuttle_OSA:1.VAL")==1 && _osampleposition == 9)) - { - if(_picked_it==1) - { - samplename = epics_get(sprintf("XOMNY-SAMPLE_DB_shuttle_OSA:%d.DESC",(_osampleposition-8))) - _otransfer_modify_sample(installedshuttle, (_osampleposition-8), 0, "-") - _otransfer_modify_sample("omny",110,3,samplename) - } - return(1) - } - else - { - printf("There is no OSA available.\n") - return(0) - } - } - else - { - printf("There is no OSA shuttle installed at the current parkz position.\n") - return(0) - } -} -# _osampleposition for fixed positions -if ((_osampleposition==0)||(_osampleposition>9&&_osampleposition<15)||(_osampleposition>31&&_osampleposition<35)||_osampleposition==100||_osampleposition==101) -{ - if (epics_get(sprintf("XOMNY-SAMPLE_DB_omny:%d.VAL", _osampleposition))==1) - { - if(_picked_it==1) - { - samplename = epics_get(sprintf("XOMNY-SAMPLE_DB_omny:%d.DESC", _osampleposition)) - _otransfer_modify_sample("omny", _osampleposition, 0, "-") - #FZP was picked - if (_osampleposition == 10 || _osampleposition == 11 || _osampleposition == 100) - _otransfer_modify_sample("omny",110,2,samplename) - #OSA was picked - if (_osampleposition == 101) - _otransfer_modify_sample("omny",110,2,samplename) - #pin was picked - if (_osampleposition == 0 || _osampleposition == 12 || _osampleposition == 13 || _osampleposition == 14 || \\ - _osampleposition == 32 || _osampleposition == 33 || _osampleposition == 34) - _otransfer_modify_sample("omny",110,1,samplename) - } - return(1) - } - else - { - printf("There is nothing to get from this position.\n") - return(0) - } + def _otransfer_check_free_slot_available_at_position(self, _osampleposition, _put_it): + #called with _put_it == 0 prior transfer. This checks that the gripper has a sample and that there + #is a free sample position available that position + #called with _put_it == 1 after the gripper action. then the storage is modified accordingly to the action -} + #check that gripper has a sample empty + if not dev.omny_samples.is_sample_in_gripper(): + raise OMNYTransferError("There is no sample in the gripper.") -return(0) - -}' - -def _otransfer_check_free_slot_available_at_position(_osampleposition,_put_it) '{ -#called with _put_it == 0 prior transfer. This checks that the gripper has a sample and that there -#is a free sample position available that position -#called with _put_it == 1 after the gripper action. then the storage is modified accordingly to the action - -local samplename -local sampletype - -#check that gripper has a sample empty -if (epics_get("XOMNY-SAMPLE_DB_omny:110.VAL")==0) -{ - printf("There is no sample in the gripper. Aborting.\n") - exit -} - -#sample pin -if (epics_get("XOMNY-SAMPLE_DB_omny:110.VAL")==1) + #sample pin + if (epics_get("XOMNY-SAMPLE_DB_omny:110.VAL")==1) if ((_osampleposition>-1 && _osampleposition<7) || (_osampleposition>11 && _osampleposition<15) || (_osampleposition>31 && _osampleposition<35)) { } else @@ -1299,24 +1121,24 @@ if (epics_get("XOMNY-SAMPLE_DB_omny:110.VAL")==1) printf("There is a sample pin in the gripper, which is not compatible with position %d\n", _osampleposition) exit } -#FZP holder -if (epics_get("XOMNY-SAMPLE_DB_omny:110.VAL")==2) - if (_osampleposition == 7 || _osampleposition == 10 || _osampleposition == 11 || _osampleposition == 100) - { } - else - { - printf("There is a FZP holder in the gripper, which is not compatible with position %d\n", _osampleposition) - exit - } -#OSA holder -if (epics_get("XOMNY-SAMPLE_DB_omny:110.VAL")==3) - if (_osampleposition == 8 || _osampleposition == 9 || _osampleposition == 101 ) - { } - else - { - printf("There is an OSA holder in the gripper, which is not compatible with position %d\n", _osampleposition) - exit - } + # #FZP holder + # if (epics_get("XOMNY-SAMPLE_DB_omny:110.VAL")==2) + # if (_osampleposition == 7 || _osampleposition == 10 || _osampleposition == 11 || _osampleposition == 100) + # { } + # else + # { + # printf("There is a FZP holder in the gripper, which is not compatible with position %d\n", _osampleposition) + # exit + # } + # #OSA holder + # if (epics_get("XOMNY-SAMPLE_DB_omny:110.VAL")==3) + # if (_osampleposition == 8 || _osampleposition == 9 || _osampleposition == 101 ) + # { } + # else + # { + # printf("There is an OSA holder in the gripper, which is not compatible with position %d\n", _osampleposition) + # exit + # } # _osampleposition 1 to 6 are in shuttles diff --git a/csaxs_bec/device_configs/omny_config.yaml b/csaxs_bec/device_configs/omny_config.yaml index 724b104..25197fc 100644 --- a/csaxs_bec/device_configs/omny_config.yaml +++ b/csaxs_bec/device_configs/omny_config.yaml @@ -108,6 +108,7 @@ otransy: readoutPriority: baseline userParameter: up_position: -1.2 + gripper_sensorvoltagetarget: -2.94 otransz: description: Transfer Z deviceClass: csaxs_bec.devices.omny.galil.ogalil_ophyd.OMNYGalilMotor diff --git a/csaxs_bec/devices/omny/omny_sample_storage.py b/csaxs_bec/devices/omny/omny_sample_storage.py index 201064a..5414969 100644 --- a/csaxs_bec/devices/omny/omny_sample_storage.py +++ b/csaxs_bec/devices/omny/omny_sample_storage.py @@ -30,6 +30,7 @@ class OMNYSampleStorage(Device): "is_shuttle_slot_used", "search_shuttle_in_slot", "show_all", + "help", ] SUB_VALUE = "value" _default_sub = SUB_VALUE @@ -137,20 +138,28 @@ class OMNYSampleStorage(Device): elif container == "C": getattr(self.sample_shuttle_C_placed, f"sample{slot_nr}").set(1) getattr(self.sample_shuttle_C_names, f"sample{slot_nr}").set(name) + elif container == "O": + getattr(self.sample_placed, f"sample{slot_nr}").set(1) + getattr(self.sample_names, f"sample{slot_nr}").set(name) - def unset_sample_slot(self, shuttle: str, slot_nr: int) -> bool: + + def unset_sample_slot(self, container: str, slot_nr: int) -> bool: if slot_nr > 20: raise OMNYSampleStorageError(f"Invalid slot number {slot_nr}.") - if shuttle == "A": + if container == "A": getattr(self.sample_shuttle_A_placed, f"sample{slot_nr}").set(0) getattr(self.sample_shuttle_A_names, f"sample{slot_nr}").set("-") - if shuttle == "B": + elif container == "B": getattr(self.sample_shuttle_B_placed, f"sample{slot_nr}").set(0) getattr(self.sample_shuttle_B_names, f"sample{slot_nr}").set("-") - if shuttle == "C": + elif container == "C": getattr(self.sample_shuttle_C_placed, f"sample{slot_nr}").set(0) getattr(self.sample_shuttle_C_names, f"sample{slot_nr}").set("-") + elif container == "O": + getattr(self.sample_placed, f"sample{slot_nr}").set(0) + getattr(self.sample_names, f"sample{slot_nr}").set("-") + def set_shuttle_slot(self, container: str, slot_nr: int) -> bool: if slot_nr > 6: @@ -280,3 +289,17 @@ class OMNYSampleStorage(Device): row.extend(["free"]) t.add_row(row) print(t) + + print("Use dev.omny_samples.help() for assistance.") + + def help(self): + print("Help for OMNY sample storage:") + print(" To get an overview use dev.omny_samples.show_all()") + print(" Modify a slot:") + print(" dev.omny_samples.unset_sample_slot('system',position)") + print(" dev.omny_samples.set_sample_slot('system',position,'name')") + print(" system in A, B, C, O") + print(" set_sample_in_gripper('name') / unset_sample_in_gripper()") + print(" set_sample_in_samplestage('name'), unset_sample_in_samplestage()") + print(" set_shuttle_slot(container, slot_nr) / unset_shuttle_slot(slot_nr)") + print(" dev.omny_samples.set_shuttle_slot('A',2)")