From 55aa7128e2a6033b4ea67d3fd63c4527d4ef880c Mon Sep 17 00:00:00 2001 From: Holler Mirko Date: Wed, 6 Nov 2024 16:56:53 +0100 Subject: [PATCH] work on omny gui, initial status progress bar --- .../plugins/omny/gui_tools.py | 165 + .../bec_ipython_client/plugins/omny/omny.py | 334 ++- .../plugins/omny/omny_alignment_mixin.py | 3 +- .../plugins/omny/omny_general_tools.py | 114 +- .../plugins/omny/omny_optics_mixin.py | 218 +- .../plugins/omny/omny_rt.py | 153 +- .../omny/omny_sample_transfer_mixin.py | 2666 +++++++++-------- .../plugins/omny/x_ray_eye_align.py | 2 +- 8 files changed, 1966 insertions(+), 1689 deletions(-) create mode 100644 csaxs_bec/bec_ipython_client/plugins/omny/gui_tools.py diff --git a/csaxs_bec/bec_ipython_client/plugins/omny/gui_tools.py b/csaxs_bec/bec_ipython_client/plugins/omny/gui_tools.py new file mode 100644 index 0000000..c63e4ad --- /dev/null +++ b/csaxs_bec/bec_ipython_client/plugins/omny/gui_tools.py @@ -0,0 +1,165 @@ +import time +import numpy as np +import sys +import termios +import tty +import fcntl +import os +import builtins + +from rich import box +from rich.console import Console +from rich.table import Table + +from bec_widgets.cli.client import BECDockArea + + +# from csaxs_bec.bec_ipython_client.plugins.cSAXS import epics_get, epics_put, fshopen, fshclose + +if builtins.__dict__.get("bec") is not None: + bec = builtins.__dict__.get("bec") + dev = builtins.__dict__.get("dev") + umv = builtins.__dict__.get("umv") + umvr = builtins.__dict__.get("umvr") + + +class OMNYGuiToolsError(Exception): + pass + + +class OMNYGuiTools: + + + def __init__(self, client): + self.gui = getattr(client, "gui", None) + self.fig200 = None + self.fig201 = None + self.fig202 = None + self.fig203 = None + self.progressbar = None + + def omnygui_start_gui(self): + if self.gui is None or self.gui.gui_is_alive() is False: + self.gui = BECDockArea() + self.gui.show() # Dieses Kommado braucht in etwa ~3s. Dabei gibt aber einen print + self.fig200 = None + self.fig201 = None + self.fig202 = None + self.fig203 = None + + def omnygui_stop_gui(self): + self.gui.close() + + def _omnycam_parking(self): + self.gui_show_omnycam_parking() + + def omnygui_show_omnycam_parking(self): + self.omnygui_start_gui() + if self.fig200 is None: + self._omnycam_clear() + self.fig200 = self.gui.add_dock(name="omnycam200").add_widget("BECImageWidget") + if self._omnycam_check_device_exists(dev.cam200): + fig = self.fig200.image("cam200") + fig.set_rotation(deg_90=3) + self.fig200.lock_aspect_ratio(True) + else: + print("Cannot open cam200. Device does not exist.") + self.fig203 = self.gui.add_dock(name="omnycam203").add_widget("BECImageWidget") + if self._omnycam_check_device_exists(dev.cam203): + fig = self.fig203.image("cam203") + fig.set_rotation(deg_90=3) + self.fig203.lock_aspect_ratio(True) + else: + print("Cannot open cam203. Device does not exist.") + try: + self.gui.remove_dock(name="default_figure") + except: + pass + + def omnygui_remove_all_docks(self): + try: + self.gui.remove_dock(name="omnycam200") + except: + pass + try: + self.gui.remove_dock(name="omnycam201") + except: + pass + try: + self.gui.remove_dock(name="omnycam202") + except: + pass + try: + self.gui.remove_dock(name="omnycam203") + except: + pass + try: + self.gui.remove_dock(name="progress") + except: + pass + self.fig200 = None + self.fig201 = None + self.fig202 = None + self.fig203 = None + self.progressbar = None + + def _omnycam_clear(self): + self.omnygui_remove_all_docks() + + def _omnycam_check_device_exists(self, device): + try: + device + except: + return False + else: + return True + + def _omnycam_samplestage(self): + self.gui_show_omnycam_samplestage() + + def omnygui_show_omnycam_samplestage(self): + self.start_gui() + if self.fig201 is None: + self._omnycam_clear() + self.fig201 = self.gui.add_dock(name="omnycam201").add_widget("BECImageWidget") + if self._omnycam_check_device_exists(dev.cam201): + fig = self.fig201.image("cam201") + fig.set_rotation(deg_90=3) + self.fig201.lock_aspect_ratio(True) + else: + print("Cannot open cam201. Device does not exist.") + self.fig202 = self.gui.add_dock(name="omnycam202").add_widget("BECImageWidget") + if self._omnycam_check_device_exists(dev.cam202): + fig = self.fig202.image("cam202") + fig.set_rotation(deg_90=3) + self.fig202.lock_aspect_ratio(True) + else: + print("Cannot open cam202. Device does not exist.") + try: + self.gui.remove_dock(name="default_figure") + except: + pass + + def omnygui_show_progress(self): + if self.progressbar is None: + # Add a new dock with a RingProgressBar widget + self.progressbar = self.gui.add_dock(name="progress").add_widget("RingProgressBar") + # Customize the size of the progress ring + self.progressbar.set_line_widths(20) + # Disable automatic updates and manually set the self.progressbar value + self.progressbar.enable_auto_updates(False) + # Set precision for the self.progressbar display + self.progressbar.set_precision(1) # Display self.progressbar with one decimal places + # Setting multiple rigns with different values + self.progressbar.set_number_of_bars(3) + # Set the values of the rings to 50, 75, and 25 from outer to inner ring + self.progressbar.set_value([50, 75, 25]) + try: + self.gui.remove_dock(name="default_figure") + except: + pass + + def _omnygui_update_progress(self): + if self.progressbar is not None: + projection = self.progress["projection"] + self.progressbar.set_value([projection, 75, 25]) \ No newline at end of file diff --git a/csaxs_bec/bec_ipython_client/plugins/omny/omny.py b/csaxs_bec/bec_ipython_client/plugins/omny/omny.py index 0deb207..60c1232 100644 --- a/csaxs_bec/bec_ipython_client/plugins/omny/omny.py +++ b/csaxs_bec/bec_ipython_client/plugins/omny/omny.py @@ -15,12 +15,13 @@ from csaxs_bec.bec_ipython_client.plugins.cSAXS import cSAXSBeamlineChecks from csaxs_bec.bec_ipython_client.plugins.omny.omny_optics_mixin import OMNYOpticsMixin from csaxs_bec.bec_ipython_client.plugins.omny.omny_alignment_mixin import OMNYAlignmentMixin from csaxs_bec.bec_ipython_client.plugins.omny.omny_general_tools import OMNYTools -from csaxs_bec.bec_ipython_client.plugins.omny.omny_sample_transfer_mixin import OMNYSampleTransferMixin +from csaxs_bec.bec_ipython_client.plugins.omny.gui_tools import OMNYGuiTools +from csaxs_bec.bec_ipython_client.plugins.omny.omny_sample_transfer_mixin import ( + OMNYSampleTransferMixin, +) from csaxs_bec.bec_ipython_client.plugins.omny.omny_rt import OMNY_rt_client from csaxs_bec.bec_ipython_client.plugins.omny.x_ray_eye_align import XrayEyeAlign -from bec_widgets.cli.client import BECDockArea as _BECDockArea - logger = bec_logger.logger @@ -63,83 +64,100 @@ class OMNYInitStagesMixin: dev.oeyex.enabled = True dev.oeyez.enabled = True dev.oeyey.enabled = True - def _omny_find_reference_loop(self, direction_endswitch, device, auto_retry=0): retry_counter = 0 limits = device.get_motor_limit_switch() if not limits[0] and not limits[1]: - raise OMNYInitError("Expect to be in a limit switch when calling the method find reference loop.") + raise OMNYInitError( + "Expect to be in a limit switch when calling the method find reference loop." + ) if limits[0] and limits[1]: raise OMNYInitError("Both limit switches are triggered. This indicates an error.") if limits[0]: direction_endswitch_start = "reverse" - if limits[1]: + if limits[1]: direction_endswitch_start = "forward" if direction_endswitch_start != direction_endswitch: raise OMNYInitError("Expect current endswitch to match the call of the method.") if device.axis_is_referenced(): raise OMNYInitError("This axis is already referenced") - + while not device.axis_is_referenced(): self._check_for_folerr_and_reset(device) device.find_reference(raise_error=0) time.sleep(1) if not device.axis_is_referenced(): if auto_retry == 0: - if self.OMNYTools.yesno("Did not reference successfully. Try again to move to endswitch and find reference?"): + if self.OMNYTools.yesno( + "Did not reference successfully. Try again to move to endswitch and find reference?" + ): self._check_for_folerr_and_reset(device) device.drive_axis_to_limit(direction_endswitch_start) time.sleep(1) elif auto_retry > 0: if retry_counter < auto_retry: - self.OMNYTools.printgreen(f"Did not reference successfully. Try again to move to endswitch and find reference. Attempt {retry_counter+1} out of max {auto_retry}") + self.OMNYTools.printgreen( + f"Did not reference successfully. Try again to move to endswitch and find reference. Attempt {retry_counter+1} out of max {auto_retry}" + ) self._check_for_folerr_and_reset(device) device.drive_axis_to_limit(direction_endswitch_start) time.sleep(1) retry_counter += 1 temperature = device.get_motor_temperature() while temperature > 100: - self.OMNYTools.printgreen(f"The temperature of the motor is {temperature}, and larger than the threshold of 100 degC. Waiting 60 s for cool down.") + self.OMNYTools.printgreen( + f"The temperature of the motor is {temperature}, and larger than the threshold of 100 degC. Waiting 60 s for cool down." + ) time.sleep(60) temperature = device.get_motor_temperature() if retry_counter == auto_retry: - self.OMNYTools.printgreen("Maximum automatic init retries reached. Setting auto to 0 offering manual continuation.") + self.OMNYTools.printgreen( + "Maximum automatic init retries reached. Setting auto to 0 offering manual continuation." + ) auto_retry = 0 def _check_for_folerr_and_reset(self, device): - #if device.folerr_status(): + # if device.folerr_status(): # user_input = (f"There is a following error in axis {device}. Reset and ignore to continue? y/n") # if user_input == "y": - #for now we just reset and ignore. because it might just occur at the beginning of move to ES + # for now we just reset and ignore. because it might just occur at the beginning of move to ES device._ogalil_folerr_reset_and_ignore() time.sleep(0.3) def omny_init_stages(self, autoconfirm=0, autoretry=0): - if self.OMNYTools.yesno("Starting initialization of OMNY stages.","y",autoconfirm=autoconfirm): + if self.OMNYTools.yesno( + "Starting initialization of OMNY stages.", "y", autoconfirm=autoconfirm + ): self.OMNYTools.printgreen("starting...") else: return - + # #maybe replace 2 by something # axis_id = dev.fheater._config["deviceConfig"].get("axis_Id") # axis_id_numeric = self.axis_id_to_numeric(axis_id) if not dev.oshield.controller.axis_is_referenced(2): - if self.OMNYTools.yesno("The smaract stage of the cryo shield has to be referenced first. Continue?","y"): + if self.OMNYTools.yesno( + "The smaract stage of the cryo shield has to be referenced first. Continue?", "y" + ): self.omny_init_smaract() else: return if self.check_all_axes_of_OMNY_referenced(): - if self.OMNYTools.yesno("All axes are referenced already. Reset and reference again?","n"): + if self.OMNYTools.yesno( + "All axes are referenced already. Reset and reference again?", "n" + ): self.OMNYTools.printgreen("ok then...") else: return if np.fabs(dev.oshield.get().readback) > 0.1: - if self.OMNYTools.yesno("oshield is not around pos 0. Can the OSA be moved to -z limit then -x limit. Risk of collition!"): + if self.OMNYTools.yesno( + "oshield is not around pos 0. Can the OSA be moved to -z limit then -x limit. Risk of collition!" + ): dev.oosaz.drive_axis_to_limit("forward") dev.oosax.drive_axis_to_limit("forward") else: @@ -147,110 +165,115 @@ class OMNYInitStagesMixin: umv(dev.oshield, 0) - dev.ofzpx.controller.socket_put_confirmed("XQ#CRESET") dev.osamx.controller.socket_put_confirmed("XQ#CRESET") dev.osamy.controller.socket_put_confirmed("XQ#CRESET") time.sleep(1) - if self.OMNYTools.yesno("drive fzp to -Z,-X,+Y limit and reference?","y",autoconfirm=autoconfirm): + if self.OMNYTools.yesno( + "drive fzp to -Z,-X,+Y limit and reference?", "y", autoconfirm=autoconfirm + ): dev.ofzpz.drive_axis_to_limit("forward") self.OMNYTools.printgreen("ofzpz reached limit") dev.ofzpy.drive_axis_to_limit("forward") self.OMNYTools.printgreen("ofzpy reached limit") dev.ofzpx.drive_axis_to_limit("reverse") self.OMNYTools.printgreen("ofzpx reached limit") - #dev.ofzpz.find_reference() - self._omny_find_reference_loop("forward", dev.ofzpz,auto_retry=autoretry) + # dev.ofzpz.find_reference() + self._omny_find_reference_loop("forward", dev.ofzpz, auto_retry=autoretry) self.OMNYTools.printgreen("ofzpz referenced") - #dev.ofzpy.find_reference() - self._omny_find_reference_loop("forward", dev.ofzpy,auto_retry=autoretry) + # dev.ofzpy.find_reference() + self._omny_find_reference_loop("forward", dev.ofzpy, auto_retry=autoretry) self.OMNYTools.printgreen("ofzpy referenced") - #dev.ofzpx.find_reference() - self._omny_find_reference_loop("reverse", dev.ofzpx,auto_retry=autoretry) + # dev.ofzpx.find_reference() + self._omny_find_reference_loop("reverse", dev.ofzpx, auto_retry=autoretry) self.OMNYTools.printgreen("ofzpx referenced") - #ranges: - #X -4.9 to 7.2 - #Y -3.5 to 7.9 - #Z -3 to 95.6 + # ranges: + # X -4.9 to 7.2 + # Y -3.5 to 7.9 + # Z -3 to 95.6 else: return - if self.OMNYTools.yesno("drive otransy stage to +Y limit?","y"): + if self.OMNYTools.yesno("drive otransy stage to +Y limit?", "y"): dev.otransy.drive_axis_to_limit("forward") self.OMNYTools.printgreen("otrany reached limit") else: return - self.OMNYTools.printgreen("For the next step the gripper has to be at a good z position. Risk of collision!") + self.OMNYTools.printgreen( + "For the next step the gripper has to be at a good z position. Risk of collision!" + ) if self.OMNYTools.yesno("drive otransx stage to +X limit and find reference?"): dev.otransx.drive_axis_to_limit("forward") self.OMNYTools.printgreen("otransx reached limit") - #dev.otransx.find_reference() - self._omny_find_reference_loop("forward", dev.otransx,auto_retry=autoretry) + # dev.otransx.find_reference() + self._omny_find_reference_loop("forward", dev.otransx, auto_retry=autoretry) self.OMNYTools.printgreen("otransx referenced") else: return - if self.OMNYTools.yesno("drive otransz stage to +Z limit and reference?","y",autoconfirm=autoconfirm): + if self.OMNYTools.yesno( + "drive otransz stage to +Z limit and reference?", "y", autoconfirm=autoconfirm + ): dev.otransz.drive_axis_to_limit("forward") self.OMNYTools.printgreen("otransz reached limit") - #dev.otransz.find_reference() - self._omny_find_reference_loop("forward", dev.otransz,auto_retry=autoretry) + # dev.otransz.find_reference() + self._omny_find_reference_loop("forward", dev.otransz, auto_retry=autoretry) self.OMNYTools.printgreen("otransz referenced") else: return - #get xeye out of the way - if self.OMNYTools.yesno("drive oeyey to +Y limit?","y"): + # get xeye out of the way + if self.OMNYTools.yesno("drive oeyey to +Y limit?", "y"): dev.oeyey.drive_axis_to_limit("forward") self.OMNYTools.printgreen("oeyey reached limit") else: return - if self.OMNYTools.yesno("drive oeyex to -X limit?","y",autoconfirm=autoconfirm): + if self.OMNYTools.yesno("drive oeyex to -X limit?", "y", autoconfirm=autoconfirm): dev.oeyex.drive_axis_to_limit("reverse") self.OMNYTools.printgreen("oeyex reached limit") else: return - if self.OMNYTools.yesno("drive oeyez to +Z limit?","y",autoconfirm=autoconfirm): + if self.OMNYTools.yesno("drive oeyez to +Z limit?", "y", autoconfirm=autoconfirm): dev.oeyez.drive_axis_to_limit("forward") self.OMNYTools.printgreen("oeyez reached limit") else: return - if self.OMNYTools.yesno("reference oeyex, then oeyez?","y",autoconfirm=autoconfirm): - #dev.oeyex.find_reference() - self._omny_find_reference_loop("reverse", dev.oeyex,auto_retry=autoretry) + if self.OMNYTools.yesno("reference oeyex, then oeyez?", "y", autoconfirm=autoconfirm): + # dev.oeyex.find_reference() + self._omny_find_reference_loop("reverse", dev.oeyex, auto_retry=autoretry) self.OMNYTools.printgreen("oeyex referenced") - #dev.oeyez.find_reference() - self._omny_find_reference_loop("forward", dev.oeyez,auto_retry=autoretry) + # dev.oeyez.find_reference() + self._omny_find_reference_loop("forward", dev.oeyez, auto_retry=autoretry) self.OMNYTools.printgreen("oeyez referenced") else: return - if self.OMNYTools.yesno("find reference mark of oeyey?","y",autoconfirm=autoconfirm): - #print("oeyey now in limit") + if self.OMNYTools.yesno("find reference mark of oeyey?", "y", autoconfirm=autoconfirm): + # print("oeyey now in limit") dev.oeyez.drive_axis_to_limit("forward") dev.oeyey.controller.socket_put_confirmed("indspeed[7]=2000") - #dev.oeyey.find_reference() - self._omny_find_reference_loop("forward", dev.oeyey,auto_retry=autoretry) + # dev.oeyey.find_reference() + self._omny_find_reference_loop("forward", dev.oeyey, auto_retry=autoretry) self.OMNYTools.printgreen("oeyey is now referenced") - #ensure closed shuttle and shuttle aligner down + # ensure closed shuttle and shuttle aligner down if not dev.oshuttleopen.get_motor_limit_switch()[0]: dev.oshuttleopen.drive_axis_to_limit("reverse") - + if not dev.oshuttleopen.get_motor_limit_switch()[0]: raise OMNYInitError("Failed to drive shuttle opener to reverse limit") else: self.OMNYTools.printgreen("shuttle opener is down, i.e. in safe position to continue.") - #move shuttle aligner down - #self._otransfer_shuttle_aligner_down() - #the above is ins sample transfer mixin. can it be accessible from here? so code below + # move shuttle aligner down + # self._otransfer_shuttle_aligner_down() + # the above is ins sample transfer mixin. can it be accessible from here? so code below if not dev.oshuttlealign.get_motor_limit_switch()[1]: dev.oshuttlealign.drive_axis_to_limit("forward") @@ -259,131 +282,142 @@ class OMNYInitStagesMixin: else: self.OMNYTools.printgreen("shuttle aligner is down, i.e. in safe position to continue.") - if self.OMNYTools.yesno("drive parking stage to +Z limit and reference?","y",autoconfirm=autoconfirm): + if self.OMNYTools.yesno( + "drive parking stage to +Z limit and reference?", "y", autoconfirm=autoconfirm + ): dev.oparkz.drive_axis_to_limit("forward") self.OMNYTools.printgreen("oparkz is in limit") - #dev.oparkz.find_reference() - self._omny_find_reference_loop("forward", dev.oparkz,auto_retry=autoretry) + # dev.oparkz.find_reference() + self._omny_find_reference_loop("forward", dev.oparkz, auto_retry=autoretry) self.OMNYTools.printgreen("oparkz is referenced") else: return - if self.OMNYTools.yesno("OK, tricky part. Can the OSA be moved to -z limit then -x limit. Risk of collition!"): + if self.OMNYTools.yesno( + "OK, tricky part. Can the OSA be moved to -z limit then -x limit. Risk of collition!" + ): dev.oosaz.drive_axis_to_limit("forward") dev.oosax.drive_axis_to_limit("forward") else: - raise OMNYInitError("Automatic init not possible in this case. Please initialize manually.") + raise OMNYInitError( + "Automatic init not possible in this case. Please initialize manually." + ) - if self.OMNYTools.yesno("drive otrackz to -Z limit?","y",autoconfirm=autoconfirm): + if self.OMNYTools.yesno("drive otrackz to -Z limit?", "y", autoconfirm=autoconfirm): dev.otrackz.drive_axis_to_limit("forward") self.OMNYTools.printgreen("otrackz is in limit") else: return - if self.OMNYTools.yesno("drive osamx to +X limit?","y",autoconfirm=autoconfirm): + if self.OMNYTools.yesno("drive osamx to +X limit?", "y", autoconfirm=autoconfirm): dev.osamx.drive_axis_to_limit("forward") self.OMNYTools.printgreen("osamx is in limit") else: return - if self.OMNYTools.yesno("drive oosay to +Y limit?","y",autoconfirm=autoconfirm): + if self.OMNYTools.yesno("drive oosay to +Y limit?", "y", autoconfirm=autoconfirm): dev.oosay.drive_axis_to_limit("forward") self.OMNYTools.printgreen("oosay is in limit") else: return - if self.OMNYTools.yesno("find reference mark of osamx?","y",autoconfirm=autoconfirm): - self._omny_find_reference_loop("forward", dev.osamx,auto_retry=autoretry) - #dev.osamx.find_reference() + if self.OMNYTools.yesno("find reference mark of osamx?", "y", autoconfirm=autoconfirm): + self._omny_find_reference_loop("forward", dev.osamx, auto_retry=autoretry) + # dev.osamx.find_reference() self.OMNYTools.printgreen("osamx is referenced") - #osamx range limit -2 to 7 good for cryolink + # osamx range limit -2 to 7 good for cryolink - #if osamz is ever needed, here is how it could be initialized (in spec code) - #if (!_ogalil_axis_is_referenced_mne(osamx) || fabs(A[osamx]) > 0.1 ) - #{ - #printf("The osamx stage is not referenced or is not at the reference position. Aborting.\n") - #exit - #} - #drive osamz to -Z limit - #+Z direction is critical because of cryolink connection - #if(!yesno("drive osamz to -Z limit and perform reference search?",1)) + # if osamz is ever needed, here is how it could be initialized (in spec code) + # if (!_ogalil_axis_is_referenced_mne(osamx) || fabs(A[osamx]) > 0.1 ) + # { + # printf("The osamx stage is not referenced or is not at the reference position. Aborting.\n") # exit - #osamz to limit - #_ogalil_drive_to_limit_mne(osamz,1) - #_ogalil_find_reference_mark_mne(osamz) - #set_lm osamz -.5 .5 + # } + # drive osamz to -Z limit + # +Z direction is critical because of cryolink connection + # if(!yesno("drive osamz to -Z limit and perform reference search?",1)) + # exit + # osamz to limit + # _ogalil_drive_to_limit_mne(osamz,1) + # _ogalil_find_reference_mark_mne(osamz) + # set_lm osamz -.5 .5 else: return - - if self.OMNYTools.yesno("drive osamy to -Y limit?","y"): + if self.OMNYTools.yesno("drive osamy to -Y limit?", "y"): dev.osamy.drive_axis_to_limit("reverse") self.OMNYTools.printgreen("osamy is in limit") else: return - if self.OMNYTools.yesno("perform reference search of oosax?","y"): + if self.OMNYTools.yesno("perform reference search of oosax?", "y"): self._omny_find_reference_loop("forward", dev.oosax) - #dev.oosax.find_reference() + # dev.oosax.find_reference() self.OMNYTools.printgreen("oosax is referenced") else: return - if self.OMNYTools.yesno("find reference mark of oosay?","y"): + if self.OMNYTools.yesno("find reference mark of oosay?", "y"): self._omny_find_reference_loop("forward", dev.oosay) - #dev.oosay.find_reference() + # dev.oosay.find_reference() self.OMNYTools.printgreen("oosay is referenced") else: return - if self.OMNYTools.yesno("find reference mark of osamy?","y"): + if self.OMNYTools.yesno("find reference mark of osamy?", "y"): self._omny_find_reference_loop("reverse", dev.osamy) - #dev.osamy.find_reference() + # dev.osamy.find_reference() self.OMNYTools.printgreen("osamy is referenced") else: return - if self.OMNYTools.yesno("find reference mark of oosaz?","y"): + if self.OMNYTools.yesno("find reference mark of oosaz?", "y"): self._omny_find_reference_loop("forward", dev.oosaz) - #dev.oosaz.find_reference() + # dev.oosaz.find_reference() self.OMNYTools.printgreen("oosaz is referenced") else: return - if self.OMNYTools.yesno("find endswitch and reference mark of osamroy?","y",autoconfirm=autoconfirm): + if self.OMNYTools.yesno( + "find endswitch and reference mark of osamroy?", "y", autoconfirm=autoconfirm + ): dev.osamroy.drive_axis_to_limit("reverse") self.OMNYTools.printgreen("osamroy is in limit") - self._omny_find_reference_loop("reverse", dev.osamroy,auto_retry=autoretry) - #dev.osamroy.find_reference() + self._omny_find_reference_loop("reverse", dev.osamroy, auto_retry=autoretry) + # dev.osamroy.find_reference() self.OMNYTools.printgreen("osamroy is referenced") else: return - if self.OMNYTools.yesno("find reference mark of transfer Y?",autoconfirm=autoconfirm): - self._omny_find_reference_loop("forward", dev.otransy,auto_retry=autoretry) - #dev.otransy.find_reference() + if self.OMNYTools.yesno("find reference mark of transfer Y?", autoconfirm=autoconfirm): + self._omny_find_reference_loop("forward", dev.otransy, auto_retry=autoretry) + # dev.otransy.find_reference() self.OMNYTools.printgreen("otransy is referenced") else: return - if self.OMNYTools.yesno("find endswitches and reference marks of tracking stage system?","y",autoconfirm=autoconfirm): + if self.OMNYTools.yesno( + "find endswitches and reference marks of tracking stage system?", + "y", + autoconfirm=autoconfirm, + ): dev.otracky.drive_axis_to_limit("forward") self.OMNYTools.printgreen("otracky is in limit") - self._omny_find_reference_loop("forward", dev.otracky,auto_retry=autoretry) - #dev.otracky.find_reference() + self._omny_find_reference_loop("forward", dev.otracky, auto_retry=autoretry) + # dev.otracky.find_reference() self.OMNYTools.printgreen("otracky is referenced") - self._omny_find_reference_loop("forward", dev.otrackz,auto_retry=autoretry) - #dev.otrackz.find_reference() + self._omny_find_reference_loop("forward", dev.otrackz, auto_retry=autoretry) + # dev.otrackz.find_reference() self.OMNYTools.printgreen("otrackz is referenced") else: return - #all three controllers + # all three controllers dev.ofzpx.controller._ogalil_folerr_not_ignore() dev.osamx.controller._ogalil_folerr_not_ignore() dev.osamy.controller._ogalil_folerr_not_ignore() - #adjust acceleration of tracking stages + # adjust acceleration of tracking stages dev.osamy.controller.socket_put_confirmed("ACE=11264") dev.osamy.controller.socket_put_confirmed("ACB=11264") dev.osamy.controller.socket_put_confirmed("DCE=11264") @@ -395,22 +429,24 @@ class OMNYInitStagesMixin: self._setalllimitsomny() def omny_init_smaract(self): - #_smar_rt_set_max_closed_loop_frequency(0,0,3000) - #_smar_rt_set_max_closed_loop_frequency(0,1,3000) - #_smar_rt_set_max_closed_loop_frequency(0,2,3000) + # _smar_rt_set_max_closed_loop_frequency(0,0,3000) + # _smar_rt_set_max_closed_loop_frequency(0,1,3000) + # _smar_rt_set_max_closed_loop_frequency(0,2,3000) dev.oshield.controller.find_reference_mark(1, 0, 1000, 1) time.sleep(2) dev.oshield.controller.find_reference_mark(0, 0, 1000, 1) time.sleep(2) if not dev.otransy.get_motor_limit_switch()[1]: - if self.OMNYTools.yesno("drive otransy stage to +Y limit?","y"): + if self.OMNYTools.yesno("drive otransy stage to +Y limit?", "y"): dev.otransy.drive_axis_to_limit("forward") self.OMNYTools.printgreen("otransy reached limit") else: self.OMNYTools.printgreen("otransy is in upper limit, i.e. safe condition") - if self.OMNYTools.yesno("Problematic part: Can the OSA be moved to -z limit then -x limit. Risk of collition!"): + if self.OMNYTools.yesno( + "Problematic part: Can the OSA be moved to -z limit then -x limit. Risk of collition!" + ): dev.oosaz.drive_axis_to_limit("forward") dev.oosax.drive_axis_to_limit("forward") else: @@ -423,14 +459,14 @@ class OMNYInitStagesMixin: dev.ocsx.limits = [-2, 4.3] dev.ocsy.limits = [-1, 3] - dev.oshield.controller.set_closed_loop_move_speed(0,2) - dev.oshield.controller.set_closed_loop_move_speed(1,2) - dev.oshield.controller.set_closed_loop_move_speed(2,2) + dev.oshield.controller.set_closed_loop_move_speed(0, 2) + dev.oshield.controller.set_closed_loop_move_speed(1, 2) + dev.oshield.controller.set_closed_loop_move_speed(2, 2) - #enable sensor for repeatable open loop motion + # enable sensor for repeatable open loop motion dev.oshield.controller.socket_put_and_receive("SSE1") - if self.OMNYTools.yesno("Move CS out of the beam path?","y"): + if self.OMNYTools.yesno("Move CS out of the beam path?", "y"): umv(dev.ocsx, 4.3, dev.ocsy, 2) self.OMNYTools.printgreen("Finished initialization of OMNY smaract system") @@ -454,7 +490,7 @@ class OMNYInitStagesMixin: dev.otransx.limits = [-459.0000, 33.0000] dev.otransy.limits = [-41.0000, 1.0000] dev.otransz.limits = [-70.5000, 11.0000] - dev.oparkz .limits = [-165.0000, 1.0000] + dev.oparkz.limits = [-165.0000, 1.0000] dev.otracky.limits = [-3.0000, -7.0000] dev.otrackz.limits = [-2.0000, 1.0000] dev.ocsy.limits = [-2.0000, 2.0000] @@ -487,33 +523,29 @@ class OMNYInitStagesMixin: dev.otracky.limits = [-7, -3] dev.otrackz.limits = [-2, 1] - otracky_start_pos = self.OMNYTools._get_user_param_safe("otracky","start_pos") - otrackz_start_pos = self.OMNYTools._get_user_param_safe("otrackz","start_pos") + otracky_start_pos = self.OMNYTools._get_user_param_safe("otracky", "start_pos") + otrackz_start_pos = self.OMNYTools._get_user_param_safe("otrackz", "start_pos") umv(dev.otracky, otracky_start_pos, dev.otrackz, otrackz_start_pos) - #adjust acceleration and speed of osamx + # adjust acceleration and speed of osamx dev.osamx.controller.socket_put_confirmed("SPA=100") dev.osamx.controller.socket_put_confirmed("ACA=1878") dev.osamx.controller.socket_put_confirmed("DCA=187") - #adjust acceleration of tracking stages + # adjust acceleration of tracking stages dev.osamy.controller.socket_put_confirmed("ACE=11264") - dev.osamy.controller.socket_put_confirmed("ACB=11264") dev.osamy.controller.socket_put_confirmed("DCE=11264") dev.osamy.controller.socket_put_confirmed("DCB=11264") - def check_all_axes_of_OMNY_referenced(self) -> bool: - if ( - dev.ofzpx.controller.all_axes_referenced()): + if dev.ofzpx.controller.all_axes_referenced(): self.OMNYTools.printgreen("All axes of OMNY are referenced.") return True else: return False - class OMNY( OMNYInitStagesMixin, OMNYSampleTransferMixin, @@ -521,6 +553,7 @@ class OMNY( OMNYOpticsMixin, cSAXSBeamlineChecks, OMNY_rt_client, + OMNYGuiTools, ): def __init__(self, client): super().__init__() @@ -543,33 +576,22 @@ class OMNY( self.corr_pos_y_2 = [] self.corr_angle_y_2 = [] self.progress = {} + self.progress["subtomo"] = 0 + self.progress["subtomo_projection"] = 0 + self.progress["subtomo_total_projections"] = 0 + self.progress["projection"] = 0 + self.progress["total_projections"] = 0 + self.progress["angle"] = 0 + self.progress["tomo_type"] = 0 self.OMNYTools = OMNYTools(self.client) OMNY_rt_client.__init__(self) self.align = XrayEyeAlign(self.client, self) - self.gui = getattr(client, 'gui',None) - self.fig = None - - - def start_gui(self): - if self.gui is None: - self.gui = _BECDockArea() - self.gui.show() - - def stop_gui(self): - if self.gui is not None: - self.fig = None - self.gui.close() - self.gui = None - - def add_image_dock(self): - self.fig = self.gui.add_dock(name="cam1").add_widget("BECImageWidget") - self.fig.image("cam200") - self.fig.set_rotation(3) - #self.gui.remove_dock(dock_name="Waveform Dock") + OMNYGuiTools.__init__(self, self.client) def start_x_ray_eye_alignment(self): if self.OMNYTools.yesno( - "Starting Xrayeye alignment. Deleting any potential existing alignment for this sample.","y" + "Starting Xrayeye alignment. Deleting any potential existing alignment for this sample.", + "y", ): self.align = XrayEyeAlign(self.client, self) try: @@ -1319,7 +1341,7 @@ class OMNY( ) print(f"\nSample name: {self.sample_name}\n") - if self.OMNYTools.yesno("Are these parameters correctly set for your scan?","y"): + if self.OMNYTools.yesno("Are these parameters correctly set for your scan?", "y"): print("... excellent!") else: self.tomo_countingtime = self._get_val(" s", self.tomo_countingtime, float) @@ -1347,16 +1369,18 @@ class OMNY( print(f"The angular step in a subtomogram it will be {self.tomo_angle_stepsize}") if self.tomo_type == 2: - code = self._get_val("This mode causes significant wear in OMNY. Enter authorization code.",0,str,) + code = self._get_val( + "This mode causes significant wear in OMNY. Enter authorization code.", 0, str + ) if code == "x12sa": self.golden_ratio_bunch_size = self._get_val( "Number of projections sorted per bunch (minimum 100)", self.golden_ratio_bunch_size, int, ) - if self.golden_ratio_bunch_size<100: + if self.golden_ratio_bunch_size < 100: print("Minimum of 100 selected.") - self.golden_ratio_bunch_size=100 + self.golden_ratio_bunch_size = 100 self.golden_max_number_of_projections = self._get_val( "Stop after number of projections (zero for endless)", self.golden_max_number_of_projections, @@ -1368,11 +1392,15 @@ class OMNY( int, ) else: - print("Wrong authorization code. Tomo type 1 selected: 2 sub-tomograms selected.") + print( + "Wrong authorization code. Tomo type 1 selected: 2 sub-tomograms selected." + ) self.tomo_type = 1 if self.tomo_type == 3: - code = self._get_val("This mode causes significant wear in OMNY. Enter authorization code.",0,str,) + code = self._get_val( + "This mode causes significant wear in OMNY. Enter authorization code.", 0, str + ) if code == "x12sa": numprj = self._get_val( "Number of projections per sub-tomogram (minimum 100)", @@ -1394,7 +1422,9 @@ class OMNY( int, ) else: - print("Wrong authorization code. Tomo type 1 selected: 2 sub-tomograms selected.") + print( + "Wrong authorization code. Tomo type 1 selected: 2 sub-tomograms selected." + ) self.tomo_type = 1 @staticmethod @@ -1452,7 +1482,7 @@ class OMNY( f"{'Stitching:':<{padding}}{stitching:>{padding}}\n", f"{'Number of individual sub-tomograms:':<{padding}}{8:>{padding}}\n", f"{'Angular step within sub-tomogram:':<{padding}}{self.tomo_angle_stepsize:>{padding}.2f}\n", - "Add current temperature and pressure status" + "Add current temperature and pressure status", ] content = "".join(content) user_target = os.path.expanduser(f"~/Data10/documentation/tomo_scan_ID_{self.tomo_id}.pdf") diff --git a/csaxs_bec/bec_ipython_client/plugins/omny/omny_alignment_mixin.py b/csaxs_bec/bec_ipython_client/plugins/omny/omny_alignment_mixin.py index ae6e1b2..ae1f433 100644 --- a/csaxs_bec/bec_ipython_client/plugins/omny/omny_alignment_mixin.py +++ b/csaxs_bec/bec_ipython_client/plugins/omny/omny_alignment_mixin.py @@ -8,6 +8,7 @@ from rich.table import Table from typeguard import typechecked from bec_lib import bec_logger + logger = bec_logger.logger @@ -192,7 +193,7 @@ class OMNYAlignmentMixin: print( f"Loading default mirror correction from file {correction_file} containing {int_num_elements} elements." ) - #print(corr_pos) + # print(corr_pos) return corr_pos, corr_angle def read_additional_correction_x(self, correction_file: str): diff --git a/csaxs_bec/bec_ipython_client/plugins/omny/omny_general_tools.py b/csaxs_bec/bec_ipython_client/plugins/omny/omny_general_tools.py index d4c308d..aaebcaf 100644 --- a/csaxs_bec/bec_ipython_client/plugins/omny/omny_general_tools.py +++ b/csaxs_bec/bec_ipython_client/plugins/omny/omny_general_tools.py @@ -11,7 +11,7 @@ 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 +# from csaxs_bec.bec_ipython_client.plugins.cSAXS import epics_get, epics_put, fshopen, fshclose if builtins.__dict__.get("bec") is not None: bec = builtins.__dict__.get("bec") @@ -20,21 +20,21 @@ if builtins.__dict__.get("bec") is not None: umvr = builtins.__dict__.get("umvr") - class OMNYToolsError(Exception): pass + class OMNYTools: - HEADER = '\033[95m' - OKBLUE = '\033[94m' - OKCYAN = '\033[96m' - OKGREEN = '\033[92m' - WARNING = '\033[93m' - FAIL = '\033[91m' - ENDC = '\033[0m' - BOLD = '\033[1m' - UNDERLINE = '\033[4m' + HEADER = "\033[95m" + OKBLUE = "\033[94m" + OKCYAN = "\033[96m" + OKGREEN = "\033[92m" + WARNING = "\033[93m" + FAIL = "\033[91m" + ENDC = "\033[0m" + BOLD = "\033[1m" + UNDERLINE = "\033[4m" def __init__(self, client) -> None: self.client = client @@ -45,19 +45,19 @@ class OMNYTools: 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 printgreen(self,string:str): + + def printgreen(self, string: str): print(self.OKGREEN + string + self.ENDC) - def printgreenbold(self,string:str): + def printgreenbold(self, string: str): print(self.BOLD + self.OKGREEN + string + self.ENDC) - def yesno(self,message :str,default="none",autoconfirm=0) -> bool: + def yesno(self, message: str, default="none", autoconfirm=0) -> bool: if autoconfirm and default == "y": - self.printgreen (message + " Automatically confirming default: yes") + self.printgreen(message + " Automatically confirming default: yes") return True elif autoconfirm and default == "n": - self.printgreen (message + " Automatically confirming default: no") + self.printgreen(message + " Automatically confirming default: no") return False if default == "y": message_ending = " [Y]/n? " @@ -66,20 +66,25 @@ class OMNYTools: else: message_ending = " y/n? " while True: - user_input = input(self.OKBLUE + message + message_ending + self.ENDC) - if (user_input == "Y" or user_input == "y" or user_input == "yes" or user_input == "Yes") or (default == "y" and user_input == ""): + user_input = input(self.OKBLUE + message + message_ending + self.ENDC) + if ( + user_input == "Y" or user_input == "y" or user_input == "yes" or user_input == "Yes" + ) or (default == "y" and user_input == ""): return True - if (user_input == "N" or user_input == "n" or user_input == "no" or user_input == "No") or (default == "n" and user_input == ""): + if ( + user_input == "N" or user_input == "n" or user_input == "no" or user_input == "No" + ) or (default == "n" and user_input == ""): return False else: print("Please expicitely confirm y or n.") - - def tweak_cursor(self,dev1, step1:float, dev2="none", step2:float="0", special_command = "none"): + def tweak_cursor( + self, dev1, step1: float, dev2="none", step2: float = "0", special_command="none" + ): if dev1 not in dev.enabled_devices: print(f"Device 1 {dev} is not in enabled devices.") return - if dev2 not in dev.enabled_devices and dev2 != "none": + if dev2 not in dev.enabled_devices and dev2 != "none": print(f"Device 2 {dev} is not in enabled devices.") return # Save the current terminal settings @@ -91,49 +96,49 @@ class OMNYTools: # Set stdin to non-blocking mode old_flags = fcntl.fcntl(fd, fcntl.F_GETFL) fcntl.fcntl(fd, fcntl.F_SETFL, old_flags | os.O_NONBLOCK) - print("Tweak Cursor."+self.BOLD+self.OKBLUE+"Press (q) to quit!\r"+self.ENDC) + print("Tweak Cursor." + self.BOLD + self.OKBLUE + "Press (q) to quit!\r" + self.ENDC) while True: try: # Read single character input key = sys.stdin.read(1) - if key == 'q': + if key == "q": print("\n\rExiting tweak mode\r") break - elif key == '\x1b': # Escape sequences for arrow keys + elif key == "\x1b": # Escape sequences for arrow keys next1, next2 = sys.stdin.read(2) - if next1 == '[': - if next2 == 'A': - #print("up") - if(dev2 != "none"): - umvr(dev2,step2) - if(special_command != "none"): + if next1 == "[": + if next2 == "A": + # print("up") + if dev2 != "none": + umvr(dev2, step2) + if special_command != "none": special_command() - elif next2 == 'B': - #print(" down") - if(dev2 != "none"): - umvr(dev2,-step2) - if(special_command != "none"): + elif next2 == "B": + # print(" down") + if dev2 != "none": + umvr(dev2, -step2) + if special_command != "none": special_command() - elif next2 == 'C': - #print("right") - umvr(dev1,step1) - if(special_command != "none"): + elif next2 == "C": + # print("right") + umvr(dev1, step1) + if special_command != "none": special_command() - elif next2 == 'D': - #print("left") - umvr(dev1,-step1) - if(special_command != "none"): + elif next2 == "D": + # print("left") + umvr(dev1, -step1) + if special_command != "none": special_command() - elif key == '+': - step1 = step1*2 - if(dev2 != "none"): - step2 = step2*2 + elif key == "+": + step1 = step1 * 2 + if dev2 != "none": + step2 = step2 * 2 print(f"\rDouble step size. New step size: {step1}, {step2}\r") - elif key == '-': - step1 = step1/2 - if(dev2 != "none"): - step2 = step2/2 + elif key == "-": + step1 = step1 / 2 + if dev2 != "none": + step2 = step2 / 2 print(f"\rHalf step size. New step size: {step1}, {step2}\r") except IOError: # No input available, keep looping @@ -146,6 +151,3 @@ class OMNYTools: # Restore the terminal to its original state termios.tcsetattr(fd, termios.TCSADRAIN, old_term) fcntl.fcntl(fd, fcntl.F_SETFL, old_flags) - - - diff --git a/csaxs_bec/bec_ipython_client/plugins/omny/omny_optics_mixin.py b/csaxs_bec/bec_ipython_client/plugins/omny/omny_optics_mixin.py index f5c3460..fb16ae8 100644 --- a/csaxs_bec/bec_ipython_client/plugins/omny/omny_optics_mixin.py +++ b/csaxs_bec/bec_ipython_client/plugins/omny/omny_optics_mixin.py @@ -7,9 +7,11 @@ from rich.table import Table from csaxs_bec.bec_ipython_client.plugins.cSAXS import epics_put, fshclose + class OMNYError(Exception): pass + class OMNYOpticsMixin: @staticmethod def _get_user_param_safe(device, var): @@ -18,10 +20,9 @@ class OMNYOpticsMixin: raise ValueError(f"Device {device} has no user parameter definition for {var}.") return param.get(var) - def ooptics_in(self): self.ofzp_in() - #ocs_in + # ocs_in self.oosa_in() if "rtx" in dev and dev.rtx.enabled: @@ -29,14 +30,16 @@ class OMNYOpticsMixin: self.align.update_frame() - user_input = input("Is the direct beam gone on the xray eye? Do you see the cone of the FZP?") + user_input = input( + "Is the direct beam gone on the xray eye? Do you see the cone of the FZP?" + ) if user_input == "y": printf("Next oeye_out...\n") else: raise OMNYError("Failed to properly move in the Xray optics") def _oeyey_mv(self, position): - #direction dependent speeds + # direction dependent speeds if dev.oeyez.get().readback < position: dev.oeyez.controller.socket_put_confirmed("axspeed[7]=15000") else: @@ -55,29 +58,30 @@ class OMNYOpticsMixin: raise OMNYError("The optics were not moved in. Please do so prior to eyey_out") self.OMNYTools.printgreen("Oeye is out.") - def oeye_cam_in(self): if dev.oeyez.get().readback < -80: umv(dev.oeyez, -50) - if np.fabs(dev.oeyey.get().readback+4.8) > 0.1: + if np.fabs(dev.oeyey.get().readback + 4.8) > 0.1: self._oeyey_mv(-4.8) - if np.fabs(dev.oeyez.get().readback+2) > 0.1 or np.fabs(dev.oeyex.get().readback) > 0.1: + if np.fabs(dev.oeyez.get().readback + 2) > 0.1 or np.fabs(dev.oeyex.get().readback) > 0.1: umv(dev.oeyez, -2, dev.oeyex, 0) - #if still too close in z -- safety check - if np.fabs(dev.oeyez.get().readback+2) > 0.1: + # if still too close in z -- safety check + if np.fabs(dev.oeyez.get().readback + 2) > 0.1: raise OMNYError("The oeye is too close in z for transfer. ERROR! Aborting.") self.OMNYTools.printgreen("Oeye is at cam position.") - def _oeye_xray_is_in(self) -> bool: omny_oeye_xray_inx = self._get_user_param_safe("oeyex", "xray_in") omny_oeye_xray_iny = self._get_user_param_safe("oeyey", "xray_in") omny_oeye_currentx = dev.oeyex.get().readback omny_oeye_currenty = dev.oeyey.get().readback - - if np.fabs(omny_oeye_currentx - omny_oeye_xray_inx)<0.1 and np.fabs(omny_oeye_currenty - omny_oeye_xray_iny)<0.1: + + if ( + np.fabs(omny_oeye_currentx - omny_oeye_xray_inx) < 0.1 + and np.fabs(omny_oeye_currenty - omny_oeye_xray_iny) < 0.1 + ): return True else: return False @@ -86,64 +90,64 @@ class OMNYOpticsMixin: if self._oeye_xray_is_in(): pass else: - #todo + # todo # self._otransfer_gripper_safe_xray_in_operation() - #if(!_oshield_is_ST_closed()) - #{ + # if(!_oshield_is_ST_closed()) + # { # printf("The shield of the sample stage is not closed. Aborting.\n") # exit - #} + # } omny_oeye_xray_inx = self._get_user_param_safe("oeyex", "xray_in") omny_oeye_xray_iny = self._get_user_param_safe("oeyey", "xray_in") omny_oeye_xray_inz = self._get_user_param_safe("oeyez", "xray_in") self._oeyey_mv(omny_oeye_xray_iny) omny_oeye_currenty = dev.oeyey.get().readback - if np.fabs(omny_oeye_currenty-omny_oeye_xray_iny)>0.1: + if np.fabs(omny_oeye_currenty - omny_oeye_xray_iny) > 0.1: raise OMNYError("The oeye did not move up.\n") umv(dev.oeyex, omny_oeye_xray_inx, dev.oeyez, omny_oeye_xray_inz) self.OMNYTools.printgreen("Oeye is at X-ray position.") - - #some notes for the vis microscope: - #initial position for the vis light microscope - #do not open the shield when the microscope is at the vis mic position - #found eoeyx -45.13, z -84.9, y 0.64 - #for a samy position of 2.8 with delta off - #the osa position should be in z around 7.4. in x it seems better - #around -0.6, where potentially xrays dont pass anymore + + # some notes for the vis microscope: + # initial position for the vis light microscope + # do not open the shield when the microscope is at the vis mic position + # found eoeyx -45.13, z -84.9, y 0.64 + # for a samy position of 2.8 with delta off + # the osa position should be in z around 7.4. in x it seems better + # around -0.6, where potentially xrays dont pass anymore # def _oosa_check_y(self): omny_oosa_currenty = dev.oosay.get().readback - if np.fabs(omny_oosa_currenty-0.9)>0.05: + if np.fabs(omny_oosa_currenty - 0.9) > 0.05: umv(dev.oosay, 0.9) omny_oosa_currenty = dev.oosay.get().readback - if np.fabs(omny_oosa_currenty-0.9)>0.05: + if np.fabs(omny_oosa_currenty - 0.9) > 0.05: raise OMNYError("oosay is not around 0.9. Aborting.") def _oosa_to_move_corridor(self): self._oosa_check_y() - dev.oosax.limits = [-3, 3.7] #risk collision with shield + dev.oosax.limits = [-3, 3.7] # risk collision with shield umv(dev.oosax, -2) dev.oosax.read(cached=False) omny_oosa_currentx = dev.oosax.get().readback - if np.fabs(omny_oosa_currentx+2)>0.1: + if np.fabs(omny_oosa_currentx + 2) > 0.1: raise OMNYError("oosax did not reach target position. Not moving in z.\n") def oosa_in(self): self._oosa_check_y() dev.oshield.read(cached=False) omny_oshield_current = dev.oshield.get().readback - if omny_oshield_current<15: + if omny_oshield_current < 15: self._oshield_ST_close() - if self.near_field==False: + if self.near_field == False: x_in_pos = self._get_user_param_safe("oosax", "far_field_in") y_in_pos = self._get_user_param_safe("oosay", "far_field_in") z_in_pos = self._get_user_param_safe("oosaz", "far_field_in") print("OSA movement in far-field mode.") dev.oosaz.read(cached=False) omny_oosa_currentz = dev.oosaz.get().readback - if omny_oosa_currentz<6.4: + if omny_oosa_currentz < 6.4: self._oosa_to_move_corridor() dev.oosaz.limits = [6.4, 6.6] umv(dev.oosaz, z_in_pos) @@ -151,30 +155,30 @@ class OMNYOpticsMixin: umv(dev.oosay, y_in_pos) #### For the 30 nm FZP 220 um we use this part # umv oosaz 6.5 - # umv oosax 3.2453 + # umv oosax 3.2453 # umv oosay 0.386015 - if self.near_field==True: + if self.near_field == True: x_in_pos = self._get_user_param_safe("oosax", "near_field_in") y_in_pos = self._get_user_param_safe("oosay", "near_field_in") z_in_pos = self._get_user_param_safe("oosaz", "near_field_in") print("OSA movement in near-field mode.") dev.oosaz.read(cached=False) omny_oosa_currentz = dev.oosaz.get().readback - if omny_oosa_currentz>0: + if omny_oosa_currentz > 0: self._oosa_to_move_corridor() dev.oosaz.limits = [-0.4, -0.6] - umv(dev.oosaz, z_in_pos) + umv(dev.oosaz, z_in_pos) umv(dev.oosax, x_in_pos) omny_osamy_current = dev.osamy.get().readback - if omny_osamy_current<3.25: - umv(dev.oosay, y_in_pos) + if omny_osamy_current < 3.25: + umv(dev.oosay, y_in_pos) else: raise OMNYError("Failed to move oosa in. osamy position is too large.") self.OMNYTools.printgreen("OSA is in.") - #todo + # todo # _omny_interferometer_align_tracking # rt_feedback_enable @@ -182,33 +186,33 @@ class OMNYOpticsMixin: self._oosa_check_y() dev.oshield.read(cached=False) omny_oshield_current = dev.oshield.get().readback - if omny_oshield_current<15: + if omny_oshield_current < 15: self._oshield_ST_close() omny_oosaz_current = dev.oosaz.get().readback - if self.near_field==False: + if self.near_field == False: print("OSA movement in far-field mode.") - if omny_oosaz_current<6.4: + if omny_oosaz_current < 6.4: self._oosa_to_move_corridor() dev.oosaz.limits = [6.4, 6.6] umv(dev.oosaz, 6.5) umv(dev.oosax, -2) - if self.near_field==True: + if self.near_field == True: print("OSA movement in near-field mode.") - if omny_oosaz_current>0: + if omny_oosaz_current > 0: self._oosa_to_move_corridor() dev.oosaz.limits = [-0.4, -0.6] umv(dev.oosaz, -0.45) umv(dev.oosax, -2) - #todo _omny_interferometer_align_tracking + # todo _omny_interferometer_align_tracking self.OMNYTools.printgreen("OSA is out.") def oosa_move_out_of_shield(self): - #todo: _omnycam_samplestage + # todo: _omnycam_samplestage self._oosa_check_y() self._oosa_to_move_corridor() omny_osamx_current = dev.osamx.get().readback - if np.fabs(omny_osamx_current)>0.2: + if np.fabs(omny_osamx_current) > 0.2: umv(dev.osamx, 0) omny_oosaz_current = dev.oosaz.get().readback if omny_oosaz_current > 0.1: @@ -217,94 +221,84 @@ class OMNYOpticsMixin: self.OMNYTools.printgreen("OSA is out of shield.") - def ofzp_out(self): if "rtx" in dev and dev.rtx.enabled: dev.rtx.controller.feedback_disable() y_out_pos = self._get_user_param_safe("ofzpy", "out") - if np.fabs(dev.ofzpy.get().readback-y_out_pos)>0.02: + if np.fabs(dev.ofzpy.get().readback - y_out_pos) > 0.02: umv(dev.ofzpy, y_out_pos) self.OMNYTools.printgreen("FZP at out position") - def ofzp_in(self): if "rtx" in dev and dev.rtx.enabled: dev.rtx.controller.feedback_disable() x_in_pos = self._get_user_param_safe("ofzpx", "in") y_in_pos = self._get_user_param_safe("ofzpy", "in") - if np.fabs(dev.ofzpy.get().readback-y_in_pos)>0.02: + if np.fabs(dev.ofzpy.get().readback - y_in_pos) > 0.02: umv(dev.ofzpy, y_in_pos) - if np.fabs(dev.ofzpx.get().readback-x_in_pos)>0.02: + if np.fabs(dev.ofzpx.get().readback - x_in_pos) > 0.02: umv(dev.ofzpx, x_in_pos) self.OMNYTools.printgreen("FZP at in position") - #220 mu FZP at ofzpz 31.8025 for eiger probe (about 2.4 mm propagation after focus) + # 220 mu FZP at ofzpz 31.8025 for eiger probe (about 2.4 mm propagation after focus) # umv(dev.ofzpy, 0.7944) # if np.fabs(dev.ofzpx.get().readback+0.4317)>0.05: # umv(dev.ofzpx, -0.4317) - #note the 220 fzp also works for near field 6.2 kev by just moving back osa and fzp - #ofzpz 24.8 leads to a 9.5 mm propagation distance. - #With the 220 mu FZP this gives 100 nm pixel recons - #for the oosa macro set near_field=1 - #170 mu FZP at 6.2 kev for large beam at ofzpz 31.8025 of about 58 mu diameter - #120 mu FZP at ofzpz 28.1991 + # note the 220 fzp also works for near field 6.2 kev by just moving back osa and fzp + # ofzpz 24.8 leads to a 9.5 mm propagation distance. + # With the 220 mu FZP this gives 100 nm pixel recons + # for the oosa macro set near_field=1 + # 170 mu FZP at 6.2 kev for large beam at ofzpz 31.8025 of about 58 mu diameter + # 120 mu FZP at ofzpz 28.1991 - #250 mu FZP 60 nm at 5.65 keV - #ofzpz 29.7 for propagation distance 2.2 - #umv ofzpx -0.4457 - #umv ofzpy 0.193630 + # 250 mu FZP 60 nm at 5.65 keV + # ofzpz 29.7 for propagation distance 2.2 + # umv ofzpx -0.4457 + # umv ofzpy 0.193630 - #150 um fzp, 60 nm, ofzpz 33.8 at 8.9 kev for propagation of 1.7 mm after focus - #umv ofzpx -0.756678 - #umv ofzpy 0.193515 + # 150 um fzp, 60 nm, ofzpz 33.8 at 8.9 kev for propagation of 1.7 mm after focus + # umv ofzpx -0.756678 + # umv ofzpy 0.193515 + # 250 um 30 nm FZP upper right + # small abberrations, seems to give good results in weak objects + # ofzpx -0.609240 + # umv ofzpy 0.118265 + # 250 um 30 nm FZP lower right very aberated + # ofzpx -0.881935 + # umv ofzpy 0.537050 - #250 um 30 nm FZP upper right - #small abberrations, seems to give good results in weak objects - #ofzpx -0.609240 - #umv ofzpy 0.118265 - #250 um 30 nm FZP lower right very aberated - #ofzpx -0.881935 - #umv ofzpy 0.537050 + # ofzpz 28.4027 + # 5.30 mm prop at 8.9 keV, 45 nm pixel in near field - #ofzpz 28.4027 - #5.30 mm prop at 8.9 keV, 45 nm pixel in near field + # ofzpz 33.103 + # 0.6 mm prop at 8.9 kev far field 7 m flight tube at foptz - - #ofzpz 33.103 - #0.6 mm prop at 8.9 kev far field 7 m flight tube at foptz - - - #ofzpz 49.4 is reachable just without interferometer swap - #which at 6.2 keV and 250 um diam, 30 nm should gives a propagation of 0.8 after focus - #and a beam size of 6 microns diamter + # ofzpz 49.4 is reachable just without interferometer swap + # which at 6.2 keV and 250 um diam, 30 nm should gives a propagation of 0.8 after focus + # and a beam size of 6 microns diamter ###coordinates 30 nm FZP for comparing them - #not sure if that is really correct - #FZP 1 - FZP 2 + # not sure if that is really correct + # FZP 1 - FZP 2 # FZP 5 - #FZP 4 - FZP 1 + # FZP 4 - FZP 1 - - - #FZP + # FZP ##upper right - #umv ofzpx -0.6154 ofzpy 0.1183 - #umv ocsx -0.6070 ocsy 0.0540 - - #lower right - #umv ofzpx -0.8341 ofzpy 0.5683 - #umv ocsx -0.3880 ocsy -0.3960 - - #lower left - #umv ofzpx -0.3876 ofzpy 0.7902 - #umv ocsx -0.8380 ocsy -0.6180 - - #upper left - #umv ofzpx -0.1678 ofzpy 0.3403 - #umv ocsx -1.0550 ocsy -0.1680 + # umv ofzpx -0.6154 ofzpy 0.1183 + # umv ocsx -0.6070 ocsy 0.0540 + # lower right + # umv ofzpx -0.8341 ofzpy 0.5683 + # umv ocsx -0.3880 ocsy -0.3960 + # lower left + # umv ofzpx -0.3876 ofzpy 0.7902 + # umv ocsx -0.8380 ocsy -0.6180 + # upper left + # umv ofzpx -0.1678 ofzpy 0.3403 + # umv ocsx -1.0550 ocsy -0.1680 def ofzp_info(self, mokev_val=-1, ofzpz_val=-1): print(f"{ofzpz_val}") @@ -319,8 +313,10 @@ class OMNYOpticsMixin: return if ofzpz_val == -1: ofzpz_val = dev.ofzpz.readback.get() - distance = 66+2.4+31.8025-ofzpz_val - print(f"\nThe sample is in a distance of \033[1m{distance:.1f} mm\033[0m from the 60 nm FZP.\n") + distance = 66 + 2.4 + 31.8025 - ofzpz_val + print( + f"\nThe sample is in a distance of \033[1m{distance:.1f} mm\033[0m from the 60 nm FZP.\n" + ) print(f"At the current energy of {mokev_val:.4f} keV we have following options:\n") diameters = [80e-6, 100e-6, 120e-6, 150e-6, 170e-6, 200e-6, 220e-6, 250e-6] @@ -345,9 +341,11 @@ class OMNYOpticsMixin: console.print(table) - #30 nm with additional spacer - distance = 53.84+0.6+33.1-ofzpz_val - print(f"\nThe sample is in a distance of \033[1m{distance:.1f} mm\033[0m from the 30 nm FZP.\n") + # 30 nm with additional spacer + distance = 53.84 + 0.6 + 33.1 - ofzpz_val + print( + f"\nThe sample is in a distance of \033[1m{distance:.1f} mm\033[0m from the 30 nm FZP.\n" + ) diameters = [150e-6, 250e-6] @@ -372,8 +370,8 @@ class OMNYOpticsMixin: console.print(table) print( - "This function can be called with explicit energy and ofzpz position.\n Example: omny.ffzp_info(mokev_val=6.2, ofzpz_val=33.2)" - ) + "This function can be called with explicit energy and ofzpz position.\n Example: omny.ffzp_info(mokev_val=6.2, ofzpz_val=33.2)" + ) # from flomni # oosaz_val = dev.oosaz.readback.get() diff --git a/csaxs_bec/bec_ipython_client/plugins/omny/omny_rt.py b/csaxs_bec/bec_ipython_client/plugins/omny/omny_rt.py index 61502c0..901b0a1 100644 --- a/csaxs_bec/bec_ipython_client/plugins/omny/omny_rt.py +++ b/csaxs_bec/bec_ipython_client/plugins/omny/omny_rt.py @@ -13,22 +13,26 @@ from rich.table import Table from csaxs_bec.bec_ipython_client.plugins.cSAXS import epics_get, epics_put, fshopen, fshclose + class OMNY_rt_clientError(Exception): pass + class OMNY_rt_client: def __init__(self): self.mirror_channel = -1 - self.mirror_amplitutde_increase=0 + self.mirror_amplitutde_increase = 0 self.mirror_parameters = {} - for j in range(1,9): + for j in range(1, 9): self.mirror_parameters[j] = dev.rtx.controller.get_mirror_parameters(j) @staticmethod def _get_user_param_safe(device, var): param = dev[device].user_parameter if not param or param.get(var) is None: - raise OMNY_rt_clientError(f"Device {device} has no user parameter definition for {var}.") + raise OMNY_rt_clientError( + f"Device {device} has no user parameter definition for {var}." + ) return param.get(var) def _omny_interferometer_openloop_steps(self, channel, steps, amplitude): @@ -38,7 +42,7 @@ class OMNY_rt_client: self._tweak_interferometer() def _tweak_interferometer(self): - self.mirror_channel=-1 + self.mirror_channel = -1 # Save the current terminal settings fd = sys.stdin.fileno() @@ -60,71 +64,123 @@ class OMNY_rt_client: try: # Read single character input key = sys.stdin.read(1) - - if key == 'q': - self.mirror_amplitutde_increase=0 - self.mirror_channel=-1 + + if key == "q": + self.mirror_amplitutde_increase = 0 + self.mirror_channel = -1 print("\n\rExiting tweak mode\r") break - elif key == '\x1b': # Escape sequences for arrow keys + elif key == "\x1b": # Escape sequences for arrow keys next1, next2 = sys.stdin.read(2) - if next1 == '[': - printit=True - if next2 == 'A': - #print("up") + if next1 == "[": + printit = True + if next2 == "A": + # print("up") if self.mirror_channel != -1: - self._omny_interferometer_openloop_steps(4, -self.mirror_parameters[self.mirror_channel]["opt_steps2_neg"], self.mirror_parameters[self.mirror_channel]["opt_amplitude2_neg"]+self.mirror_amplitutde_increase) - elif next2 == 'B': - #print(" down") + self._omny_interferometer_openloop_steps( + 4, + -self.mirror_parameters[self.mirror_channel][ + "opt_steps2_neg" + ], + self.mirror_parameters[self.mirror_channel][ + "opt_amplitude2_neg" + ] + + self.mirror_amplitutde_increase, + ) + elif next2 == "B": + # print(" down") if self.mirror_channel != -1: - self._omny_interferometer_openloop_steps(4, self.mirror_parameters[self.mirror_channel]["opt_steps2_pos"], self.mirror_parameters[self.mirror_channel]["opt_amplitude2_pos"]+self.mirror_amplitutde_increase) - elif next2 == 'C': - #print("right") + self._omny_interferometer_openloop_steps( + 4, + self.mirror_parameters[self.mirror_channel][ + "opt_steps2_pos" + ], + self.mirror_parameters[self.mirror_channel][ + "opt_amplitude2_pos" + ] + + self.mirror_amplitutde_increase, + ) + elif next2 == "C": + # print("right") if self.mirror_channel != -1: - self._omny_interferometer_openloop_steps(3, -self.mirror_parameters[self.mirror_channel]["opt_steps1_neg"], self.mirror_parameters[self.mirror_channel]["opt_amplitude1_neg"]+self.mirror_amplitutde_increase) - elif next2 == 'D': - #print("left") + self._omny_interferometer_openloop_steps( + 3, + -self.mirror_parameters[self.mirror_channel][ + "opt_steps1_neg" + ], + self.mirror_parameters[self.mirror_channel][ + "opt_amplitude1_neg" + ] + + self.mirror_amplitutde_increase, + ) + elif next2 == "D": + # print("left") if self.mirror_channel != -1: - self._omny_interferometer_openloop_steps(3, self.mirror_parameters[self.mirror_channel]["opt_steps1_pos"], self.mirror_parameters[self.mirror_channel]["opt_amplitude1_pos"]+self.mirror_amplitutde_increase) + self._omny_interferometer_openloop_steps( + 3, + self.mirror_parameters[self.mirror_channel][ + "opt_steps1_pos" + ], + self.mirror_parameters[self.mirror_channel][ + "opt_amplitude1_pos" + ] + + self.mirror_amplitutde_increase, + ) elif key.isdigit() and 1 <= int(key) <= 8: self.mirror_channel = int(key) - opt_mirrorname = self.mirror_parameters[self.mirror_channel]["opt_mirrorname"] - autostop = self.mirror_parameters[self.mirror_channel]['opt_signal_stop'] - averaging_time = self.mirror_parameters[self.mirror_channel]["opt_averaging_time"] - print(f"\nSelected mirror channel {self.mirror_channel}: {opt_mirrorname}. Autostop {autostop}. Signal averaging time: {averaging_time}\r") + opt_mirrorname = self.mirror_parameters[self.mirror_channel][ + "opt_mirrorname" + ] + autostop = self.mirror_parameters[self.mirror_channel]["opt_signal_stop"] + averaging_time = self.mirror_parameters[self.mirror_channel][ + "opt_averaging_time" + ] + print( + f"\nSelected mirror channel {self.mirror_channel}: {opt_mirrorname}. Autostop {autostop}. Signal averaging time: {averaging_time}\r" + ) if int(key) == 6: dev.rtx.controller.laser_tracker_on() dev.rtx.controller._omny_interferometer_switch_channel(self.mirror_channel) - max=0 - printit=True - elif key == '+': + max = 0 + printit = True + elif key == "+": print("\nIncreasing voltage amplitudes by 100.\r") - self.mirror_amplitutde_increase+=100 - elif key == '-': + self.mirror_amplitutde_increase += 100 + elif key == "-": print("\nDecreasing voltage amplitudes by 100.\r") - self.mirror_amplitutde_increase-=100 - elif key == 'a': + self.mirror_amplitutde_increase -= 100 + elif key == "a": if self.mirror_channel != -1: - dev.rtx.controller._omny_interferometer_optimize(mirror_channel = self.mirror_channel, channel=3) - dev.rtx.controller._omny_interferometer_optimize(mirror_channel = self.mirror_channel, channel=4) - dev.rtx.controller._omny_interferometer_optimize(mirror_channel = self.mirror_channel, channel=3) - dev.rtx.controller._omny_interferometer_optimize(mirror_channel = self.mirror_channel, channel=4) + dev.rtx.controller._omny_interferometer_optimize( + mirror_channel=self.mirror_channel, channel=3 + ) + dev.rtx.controller._omny_interferometer_optimize( + mirror_channel=self.mirror_channel, channel=4 + ) + dev.rtx.controller._omny_interferometer_optimize( + mirror_channel=self.mirror_channel, channel=3 + ) + dev.rtx.controller._omny_interferometer_optimize( + mirror_channel=self.mirror_channel, channel=4 + ) if self.mirror_channel != -1 and printit: printit = False - signal = dev.rtx.controller._omny_interferometer_get_signalsample(self.mirror_parameters[self.mirror_channel]["opt_signalchannel"], self.mirror_parameters[self.mirror_channel]["opt_averaging_time"]) + signal = dev.rtx.controller._omny_interferometer_get_signalsample( + self.mirror_parameters[self.mirror_channel]["opt_signalchannel"], + self.mirror_parameters[self.mirror_channel]["opt_averaging_time"], + ) if signal > max: max = signal info_str = f"Channel {self.mirror_channel}, {opt_mirrorname}, Current signal: {signal:.0f}" - filling = " " * (50-len(info_str)) + filling = " " * (50 - len(info_str)) # Calculate the number of filled and unfilled segments length = 30 percentage = signal / max filled_length = int(length * percentage) unfilled_length = length - filled_length - bar = '#' * filled_length + '-' * unfilled_length - print(info_str + filling + "0 " + bar + f" {max:.0f} (q)uit\r", end='') - + bar = "#" * filled_length + "-" * unfilled_length + print(info_str + filling + "0 " + bar + f" {max:.0f} (q)uit\r", end="") except IOError: # No input available, keep looping @@ -147,9 +203,15 @@ class OMNY_rt_client: def omny_interferometer_align_incoupling_angle(self): dev.rtx.controller.omny_interferometer_align_incoupling_angle() - + def interferometer_tweak_otrack(self): - self.OMNYTools.tweak_cursor(dev.otrackz,.1,dev.otracky,.1,special_command=dev.rtx.controller.laser_tracker_print_intensity_for_otrack_tweaking) + self.OMNYTools.tweak_cursor( + dev.otrackz, + 0.1, + dev.otracky, + 0.1, + special_command=dev.rtx.controller.laser_tracker_print_intensity_for_otrack_tweaking, + ) def feedback_enable_with_reset(self): dev.rtx.controller.feedback_enable_with_reset() @@ -177,4 +239,3 @@ class OMNY_rt_client: def laser_tracker_check_and_wait_for_signalstrength(self): dev.rtx.controller.laser_tracker_check_and_wait_for_signalstrength() - \ No newline at end of file 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 7d1ed05..077d0c0 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 @@ -8,6 +8,7 @@ from rich.console import Console from rich.table import Table from typeguard import typechecked +# from functools import wraps from csaxs_bec.bec_ipython_client.plugins.cSAXS import epics_get, epics_put, fshopen, fshclose @@ -22,1395 +23,1414 @@ if builtins.__dict__.get("bec") is not None: 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 + 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 - self.fig200 = None - self.fig201 = None - self.fig202 = None - self.fig203 = None + self.fig200 = None + self.fig201 = None + self.fig202 = None + self.fig203 = None + @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) + def _otransfer_shuttle_aligner_down(self): + if not dev.oshuttlealign.get_motor_limit_switch()[1]: + dev.oshuttlealign.drive_axis_to_limit("forward") - @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) - - def _otransfer_shuttle_aligner_down(self): - if not dev.oshuttlealign.get_motor_limit_switch()[1]: - dev.oshuttlealign.drive_axis_to_limit("forward") - - if not dev.oshuttlealign.get_motor_limit_switch()[1]: - raise OMNYTransferError("The shuttle aligner did not move down") - else: - print("Shuttle aligner is down.") - - def _otransfer_wait_aligner_movement(self) -> bool: - return(bool(float(dev.oshuttlealign.controller.socket_put_and_receive("MG_BGH")))) - - def _otransfer_wait_opener_movement(self) -> bool: - return(bool(float(dev.oshuttleopen.controller.socket_put_and_receive("MG_BGG")))) - - def _otransfer_move_aligner_down_in_case(self): - dev.oshuttlealign.controller.socket_put_confirmed(1,"SHH") - searchwrongendswitch=0 - while searchwrongendswitch<100 and not dev.oshuttlealign.get_motor_limit_switch()[0]: - dev.oshuttlealign.socket_put_confirmed("PRH=200") - time.sleep(0.01) - dev.oshuttlealign.socket_put_confirmed(1,"BGH") - while(self._otransfer_wait_aligner_movement()==1): - time.sleep(0.2) - searchwrongendswitch = searchwrongendswitch+1 - if (dev.oshuttlealign.get_motor_limit_switch()[0]): - print("Aligner is back down.") - dev.oshuttlealign.socket_put_confirmed("MOH") - - def _otransfer_is_shuttle_closed(self) -> bool: - if dev.oshuttleopen.get_motor_limit_switch()[0]: - return True - else: - return False - - def _otransfer_ensure_shield_parking_closed(self): - if not self._otransfer_is_shuttle_closed(): - raise OMNYTransferError("The shield of the shuttle at the parking is not closed. Aborting.") - - def _otransfer_is_shuttle_open(self) -> bool: - if dev.oshuttleopen.get_motor_limit_switch()[1]: - return True - else: - return False - - def _otransfer_ensure_shuttle_closed(self): - if not self._otransfer_is_shuttle_closed(): - dev.oshuttleopen.drive_axis_to_limit("reverse") - if not self._otransfer_is_shuttle_closed(): - raise OMNYTransferError("The shuttle did not close.") - - def _omnycam_parking(self): - if self.fig200 is None: - self._omnycam_clear() - self.fig200 = self.gui.add_dock(name="omnycam200").add_widget("BECImageWidget") - if self._omnycam_check_device_exists(dev.cam200): - self.fig200.image("cam200") - time.sleep(0.3) - try: - self.fig200.set_rotation(deg_90=3) - except: - time.sleep(0.2) - self.fig200.set_rotation(deg_90=3) - self.fig200.lock_aspect_ratio(True) - else: - print("Cannot open cam200. Device does not exist.") - self.fig203 = self.gui.add_dock(name="omnycam203").add_widget("BECImageWidget") - if self._omnycam_check_device_exists(dev.cam203): - self.fig203.image("cam203") - time.sleep(0.3) - try: - self.fig203.set_rotation(deg_90=3) - except: - time.sleep(0.2) - self.fig203.set_rotation(deg_90=3) - self.fig203.lock_aspect_ratio(True) - else: - print("Cannot open cam203. Device does not exist.") - try: - self.gui.remove_dock(name="default_figure") - except: - pass - - def _omnycam_clear(self): - try: - self.gui.remove_dock(name="omnycam200") - except: - pass - try: - self.gui.remove_dock(name="omnycam201") - except: - pass - try: - self.gui.remove_dock(name="omnycam202") - except: - pass - try: - self.gui.remove_dock(name="omnycam203") - except: - pass - self.fig200 = None - self.fig201 = None - self.fig202 = None - self.fig203 = None - - def _omnycam_check_device_exists(self,device): - try: - device - except: - return False - else: - return True - - def _omnycam_samplestage(self): - if self.fig201 is None: - self._omnycam_clear() - self.fig201 = self.gui.add_dock(name="omnycam201").add_widget("BECImageWidget") - if self._omnycam_check_device_exists(dev.cam201): - self.fig201.image("cam201") - time.sleep(0.3) - try: - self.fig201.set_rotation(deg_90=3) - except: - time.sleep(0.2) - self.fig201.set_rotation(deg_90=3) - self.fig201.lock_aspect_ratio(True) - else: - print("Cannot open cam201. Device does not exist.") - if self._omnycam_check_device_exists(dev.cam202): - self.fig202 = self.gui.add_dock(name="omnycam202").add_widget("BECImageWidget") - self.fig202.image("cam202") - time.sleep(0.3) - try: - self.fig202.set_rotation(deg_90=3) - except: - time.sleep(0.2) - self.fig202.set_rotation(deg_90=3) - self.fig202.lock_aspect_ratio(True) - else: - print("Cannot open cam202. Device does not exist.") - try: - self.gui.remove_dock(name="default_figure") - except: - pass - - def _otransfer_shuttle_align(self): - _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() - - #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") - - #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. - ################################### - - # 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) - dev.oshuttlealign.controller.socket_put_confirmed("MO") - dev.oshuttlealign.controller.socket_put_confirmed("LDH=0") + if not dev.oshuttlealign.get_motor_limit_switch()[1]: + raise OMNYTransferError("The shuttle aligner did not move down") else: - raise OMNYTransferError("issue with aligner") - - # now start aligner movement + print("Shuttle aligner is down.") - # disable negative switch - dev.oshuttlealign.controller.socket_put_confirmed("LDH=2") + def _otransfer_wait_aligner_movement(self) -> bool: + return bool(float(dev.oshuttlealign.controller.socket_put_and_receive("MG_BGH"))) - # 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") + def _otransfer_wait_opener_movement(self) -> bool: + return bool(float(dev.oshuttleopen.controller.socket_put_and_receive("MG_BGG"))) - 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) + def _otransfer_move_aligner_down_in_case(self): + dev.oshuttlealign.controller.socket_put_confirmed(1, "SHH") + searchwrongendswitch = 0 + while searchwrongendswitch < 100 and not dev.oshuttlealign.get_motor_limit_switch()[0]: + dev.oshuttlealign.socket_put_confirmed("PRH=200") + time.sleep(0.01) + dev.oshuttlealign.socket_put_confirmed(1, "BGH") + while self._otransfer_wait_aligner_movement() == 1: + time.sleep(0.2) + searchwrongendswitch = searchwrongendswitch + 1 + if dev.oshuttlealign.get_motor_limit_switch()[0]: + print("Aligner is back down.") + dev.oshuttlealign.socket_put_confirmed("MOH") - if dev.oshuttlealign.get_motor_limit_switch()[0]: - dev.oshuttlealign.controller.socket_put_confirmed("MOH") - raise OMNYTransferError("Aligner did not move or switch error.") + def _otransfer_is_shuttle_closed(self) -> bool: + if dev.oshuttleopen.get_motor_limit_switch()[0]: + return True + else: + return False - # 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") - 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): - #only open if the shield is not open yet - if not self._otransfer_is_shuttle_open(): - #but if it is not closed, then we are in an undefined state + def _otransfer_ensure_shield_parking_closed(self): if not self._otransfer_is_shuttle_closed(): - raise OMNYTransferError("Open lid function called, but lid is not closed, i.e. in an undefined state") - + raise OMNYTransferError( + "The shield of the shuttle at the parking is not closed. Aborting." + ) + + def _otransfer_is_shuttle_open(self) -> bool: + if dev.oshuttleopen.get_motor_limit_switch()[1]: + return True + else: + return False + + def _otransfer_ensure_shuttle_closed(self): + if not self._otransfer_is_shuttle_closed(): + dev.oshuttleopen.drive_axis_to_limit("reverse") + if not self._otransfer_is_shuttle_closed(): + raise OMNYTransferError("The shuttle did not close.") + + def _otransfer_shuttle_align(self): + _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() + + # 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") + + # 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. + ################################### + + # 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) + 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") + + # 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) + + 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") + + # 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") + 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: + # only open if the shield is not open yet + if not self._otransfer_is_shuttle_open(): + # but if it is not closed, then we are in an undefined state + if not self._otransfer_is_shuttle_closed(): + raise OMNYTransferError( + "Open lid function called, but lid is not closed, i.e. in an undefined state" + ) + + self._otransfer_gripper_to_park_z() + + # ensure safety threads are running + dev.oshuttleopen.controller.socket_put_confirmed("XQ#SAFETY") + time.sleep(0.1) + dev.oshuttleopen.controller.socket_put_confirmed("SHG") + dev.oshuttleopen.controller.socket_put_confirmed("SPG=30000") + dev.oshuttleopen.controller.socket_put_confirmed("ACG=10000") + dev.oshuttleopen.controller.socket_put_confirmed("DCG=10000") + dev.oshuttleopen.controller.socket_put_confirmed("PRG=17000") + dev.oshuttleopen.controller.socket_put_confirmed("BGG") + while self._otransfer_wait_opener_movement() == True: + time.sleep(0.1) + dev.oshuttleopen.controller.socket_put_confirmed("PRG=37000") + dev.oshuttleopen.controller.socket_put_confirmed("BGG") + 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") + + if pin_position == 0 or pin_position == 100: + self._oshield_ST_open() + + def _oshield_is_ST_open(self) -> bool: + # the switch for detecting status can be reached via galil controller 1, so we use otransx for access + return bool(float(dev.otransx.controller.socket_put_and_receive("MG @IN[8014]"))) + + def _oshield_is_ST_closed(self): + dev.oshield.read(cached=False) + if np.fabs(dev.oshield.get().readback - 15.5) < 0.1 and self._oshield_is_ST_open() == False: + return True + else: + return False + + def _oshield_ST_open(self): + self._otransfer_gripper_up() + oosaz_current = dev.oosaz.get().readback + oosax_current = dev.oosax.get().readback + + if oosaz_current > 0.1 or oosax_current > -1.5: + self.oosa_move_out_of_shield() + + if dev.oosaz.get().readback > 0.1 or not dev.oosaz.controller.all_axes_referenced(): + raise OMNYTransferError("The osa is either not referenced or too close to the sample.") + + if not self._oshield_is_ST_open(): + umv(dev.oshield, -11.88) + _shieldattemptopencounter = 0 + while not self._oshield_is_ST_open() and _shieldattemptopencounter < 15: + dev.oshield.controller.move_open_loop_steps(2, -500, amplitude=4000, frequency=1000) + time.sleep(0.2) + _shieldattemptopencounter += 1 + + if not self._oshield_is_ST_open(): + raise OMNYTransferError("The shield of the sample stage did not open.") + else: + print("The shield of the sample stage is open.") + + def _otransfer_shield_close(self, pin_position): + if pin_position == 100: + umv(dev.ofzpz, 75) + # otherwise the shield will collide with the long FZP holder. + self._otransfer_gripper_to_park_z() - - #ensure safety threads are running - dev.oshuttleopen.controller.socket_put_confirmed("XQ#SAFETY") - time.sleep(0.1) - dev.oshuttleopen.controller.socket_put_confirmed("SHG") - dev.oshuttleopen.controller.socket_put_confirmed("SPG=30000") - dev.oshuttleopen.controller.socket_put_confirmed("ACG=10000") - dev.oshuttleopen.controller.socket_put_confirmed("DCG=10000") - dev.oshuttleopen.controller.socket_put_confirmed("PRG=17000") - dev.oshuttleopen.controller.socket_put_confirmed("BGG") - while self._otransfer_wait_opener_movement()==True: - time.sleep(0.1) - dev.oshuttleopen.controller.socket_put_confirmed("PRG=37000") - dev.oshuttleopen.controller.socket_put_confirmed("BGG") - 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.") + self._omnycam_parking() - if not self._otransfer_is_shuttle_open(): - raise OMNYTransferError("Did not manage to open the lid") + if pin_position > 0 and pin_position < 8: + # starting from open state + if self._otransfer_is_shuttle_open(): + # ensure safety threads are running + dev.oshuttleopen.controller.socket_put_confirmed("XQ#SAFETY") + time.sleep(0.1) + dev.oshuttleopen.controller.socket_put_confirmed("SHG") + dev.oshuttleopen.controller.socket_put_confirmed("SPG=15000") + dev.oshuttleopen.controller.socket_put_confirmed("ACG=10000") + dev.oshuttleopen.controller.socket_put_confirmed("DCG=10000") + dev.oshuttleopen.controller.socket_put_confirmed("PRG=-50000") + dev.oshuttleopen.controller.socket_put_confirmed("BGG") + while self._otransfer_wait_opener_movement() == True: + time.sleep(0.1) + dev.oshuttleopen.controller.socket_put_confirmed("MOG") + if not dev.oshuttleopen.get_motor_limit_switch()[0]: + dev.oshuttleopen.drive_axis_to_limit("reverse") - if pin_position==0 or pin_position==100: - self._oshield_ST_open() + if not dev.oshuttleopen.get_motor_limit_switch()[0]: + raise OMNYTransferError("Failed ot open shuttle.") - def _oshield_is_ST_open(self) -> bool: - #the switch for detecting status can be reached via galil controller 1, so we use otransx for access - return bool(float(dev.otransx.controller.socket_put_and_receive("MG @IN[8014]"))) + if pin_position == 100: + self._oshield_ST_close() - def _oshield_is_ST_closed(self): - dev.oshield.read(cached=False) - if np.fabs(dev.oshield.get().readback-15.5) < 0.1 and self._oshield_is_ST_open() == False: - return True - else: - return False + # there is a sample in the gripper. do not close the shield because the next sample will be mounted... + ## && epics_get("XOMNY-SAMPLE_DB_omny:110.VAL")==1) + ## functionality to be checked and also collision with optical fiber - def _oshield_ST_open(self): - self._otransfer_gripper_up() - oosaz_current = dev.oosaz.get().readback - oosax_current = dev.oosax.get().readback + if pin_position == 0: + self._oshield_ST_close() - if oosaz_current>0.1 or oosax_current>-1.5: - self.oosa_move_out_of_shield() - + def _oshield_ST_close(self): + if dev.oosaz.get().readback > 0.1: + self.oosa_move_out_of_shield() - if dev.oosaz.get().readback>0.1 or not dev.oosaz.controller.all_axes_referenced(): - raise OMNYTransferError("The osa is either not referenced or too close to the sample.") + if dev.oosaz.get().readback > 0.1 or not dev.oosaz.controller.all_axes_referenced(): + raise OMNYTransferError("The osa is either not referenced or too close to the sample.") - if not self._oshield_is_ST_open(): - umv(dev.oshield, -11.88) - _shieldattemptopencounter=0 - while not self._oshield_is_ST_open() and _shieldattemptopencounter<15: - dev.oshield.controller.move_open_loop_steps(2, -500, amplitude=4000, frequency=1000) - time.sleep(0.2) - _shieldattemptopencounter+=1 + self._otransfer_gripper_up() + umv(dev.oshield, 15.5) - if not self._oshield_is_ST_open(): - raise OMNYTransferError("The shield of the sample stage did not open.") - else: - print("The shield of the sample stage is open.") + def _otransfer_gripper_up(self): + up_position = self._get_user_param_safe("otransy", "up_position") + if dev.otransy.get().readback < up_position - 0.1: + umv(dev.otransy, up_position) + if dev.otransy.get().readback < up_position - 0.1: + raise OMNYTransferError("The gripper did not move up.") + def _otransfer_oparkz_safe_shuttle_operation(self): + # this returns 10 in case not in a slot position + if self._oparkz_slot_check() == 10: + raise OMNYTransferError("Parking stage is not in a slot position") - def _otransfer_shield_close(self, pin_position): - if pin_position==100: - umv(dev.ofzpz, 75) - #otherwise the shield will collide with the long FZP holder. + def _otransfer_gripper_to_park_z(self): + if not self._otransfer_gripper_querry_status_closed(): + if self.OMNYTools.yesno( + "The gripper appears to be open, while it was expected to be closed.May it be closed now?", + "y", + ): + dev.otransy.controller.socket_put_confirmed("XQ#GRCLOS") + time.sleep(0.5) - self._otransfer_gripper_to_park_z() - self._omnycam_parking() + if not dev.otransx.controller.all_axes_referenced(): + raise OMNYTransferError("Not all axes are referenced.") - if pin_position>0 and pin_position<8: - #starting from open state - if self._otransfer_is_shuttle_open(): - #ensure safety threads are running - dev.oshuttleopen.controller.socket_put_confirmed("XQ#SAFETY") - time.sleep(0.1) - dev.oshuttleopen.controller.socket_put_confirmed("SHG") - dev.oshuttleopen.controller.socket_put_confirmed("SPG=15000") - dev.oshuttleopen.controller.socket_put_confirmed("ACG=10000") - dev.oshuttleopen.controller.socket_put_confirmed("DCG=10000") - dev.oshuttleopen.controller.socket_put_confirmed("PRG=-50000") - dev.oshuttleopen.controller.socket_put_confirmed("BGG") - while self._otransfer_wait_opener_movement()==True: - time.sleep(0.1) - dev.oshuttleopen.controller.socket_put_confirmed("MOG") + up_position = self._get_user_param_safe("otransy", "up_position") - if not dev.oshuttleopen.get_motor_limit_switch()[0]: - dev.oshuttleopen.drive_axis_to_limit("reverse") + if ( + np.fabs(dev.otransx.get().readback - 20) < 0.1 + and dev.otransy.get().readback > up_position - 0.1 + and np.fabs(dev.otransz.get().readback + 50) < 0.1 + ): + print("Gripper is in parking position") + else: + print("Gripper is not yet in parking position. Moving...") + self._otransfer_gripper_up() - if not dev.oshuttleopen.get_motor_limit_switch()[0]: - raise OMNYTransferError("Failed ot open shuttle.") + # if coming from a position beyond a shuttle in parking station + if dev.otransx.get().readback < -2: + self._otransfer_ensure_shield_parking_closed() + # coming from an OSA or FZP transfer or also sample. Ensure shield open + if dev.otransx.get().readback < -350: - if pin_position==100: - self._oshield_ST_close() + # if xray eye is in, move it out + if dev.oeyez.get().readback < -5: + self.oeye_cam_in() - #there is a sample in the gripper. do not close the shield because the next sample will be mounted... - ## && epics_get("XOMNY-SAMPLE_DB_omny:110.VAL")==1) - ## functionality to be checked and also collision with optical fiber + # is executed in shield_st_open - _otransfer_gripper_up + self._oshield_ST_open() + umv(dev.otransz, 0) + # the oosa has in principle to be out because of shield open above + # if that is the case, then we do simultaneous shield and trans movement + oosaz_current = dev.oosaz.get().readback + if oosaz_current < 0.1: + umv(dev.otransx, -350, dev.oshield, 15.5) + # if the gripper is empty, then we can already move the xeye to the xray position + # simultaneous motion to reduce time. otherwise later manual eye in + if not dev.omny_samples.is_sample_in_gripper(): + # todo the oeyey mv may not be accessible + _omny_oeye_xray_inx = self._get_user_param_safe("oeyex", "xray_in") + _omny_oeye_xray_iny = self._get_user_param_safe("oeyey", "xray_in") + self._oeyey_mv(_omny_oeye_xray_iny) + umv(dev.otransx, -100, dev.oeyex, _omny_oeye_xray_inx, dev.oeyez, -2) + else: + umv(dev.otransx, -100) + else: + self._oshield_ST_close() + umv(dev.otransx, -100) - if pin_position==0: - self._oshield_ST_close() + # if process was aborted while moving to ST + if dev.otransx.get().readback < -105: + # if xray eye is in, move it out + if dev.oeyez.get().readback < -5: + self.oeye_cam_in() + self._oshield_ST_close() + umv(dev.otransz, 0) + umv(dev.otransx, -100) - def _oshield_ST_close(self): - if dev.oosaz.get().readback > 0.1: - self.oosa_move_out_of_shield() + umv(dev.otransx, 20, dev.otransz, -50) - if dev.oosaz.get().readback > 0.1 or not dev.oosaz.controller.all_axes_referenced(): - raise OMNYTransferError("The osa is either not referenced or too close to the sample.") + def _otransfer_gripper_safe_xray_in_operation(self): + if not dev.otransx.controller.all_axes_referenced(): + raise OMNYTransferError("Not all axes are referenced.") + self._otransfer_gripper_to_park_z() - self._otransfer_gripper_up() - umv(dev.oshield, 15.5) + def _otransfer_mode_query(self) -> bool: + return bool(float(dev.otransx.controller.socket_put_and_receive("MG mntmod"))) - def _otransfer_gripper_up(self): - up_position = self._get_user_param_safe("otransy", "up_position") - if dev.otransy.get().readback < up_position - 0.1: - umv(dev.otransy, up_position) - if dev.otransy.get().readback < up_position - 0.1: - raise OMNYTransferError("The gripper did not move up.") + def _otransfer_mode_ensurenot(self): + if self._otransfer_mode_query(): + raise OMNYTransferError("System is in transfer mode.") - def _otransfer_oparkz_safe_shuttle_operation(self): - #this returns 10 in case not in a slot position - if self._oparkz_slot_check()==10: - raise OMNYTransferError("Parking stage is not in a slot position") + def otransfer_park_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." + ) + if slot_number == 2: + self._oparkz_drive_and_check(-0.9 - 29 * 3 - 42 - 0.05) + elif slot_number == 3: + self._oparkz_drive_and_check(-0.9 - 29 * 3) + elif slot_number == 4: + self._oparkz_drive_and_check(-0.9 - 29 * 2) + elif slot_number == 5: + self._oparkz_drive_and_check(-0.9 - 29) + elif slot_number == 6: + self._oparkz_drive_and_check(-0.9) - def _otransfer_gripper_to_park_z(self): - if not self._otransfer_gripper_querry_status_closed(): - if self.OMNYTools.yesno("The gripper appears to be open, while it was expected to be closed.May it be closed now?","y"): - dev.otransy.controller.socket_put_confirmed("XQ#GRCLOS") + def otransfer_park_loadlock_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." + ) + # if the valve of the loadlock is not closed, ask before movement + # todo if(epics_get("XOMNY-ES1-LL1VG1:POSITION")!="CLOSED") { + 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 - 0.05) + elif slot_number == 3: + self._oparkz_drive_and_check(-6 - 29 * 3) + elif slot_number == 4: + self._oparkz_drive_and_check(-6 - 29 * 2) + elif slot_number == 5: + self._oparkz_drive_and_check(-6 - 29) + elif slot_number == 6: + self._oparkz_drive_and_check(-6) + + def _oparkz_drive_and_check(self, targetpos): + oparkz_current = dev.oparkz.get().readback + if np.fabs(oparkz_current - targetpos) >= 0.05: + self._otransfer_mode_ensurenot() + # make sure shield closed + self._otransfer_ensure_shuttle_closed() + self._otransfer_shuttle_aligner_down() + umv(dev.oparkz, targetpos) + + def _oparkz_check(self, targetpos) -> bool: + oparkz_current = dev.oparkz.get().readback + if np.fabs(oparkz_current - targetpos) < 0.05: + return True + else: + return False + + def _oparkz_slot_check(self): + parkingposition = 10 + if self._oparkz_check(-0.9): + parkingposition = 6 + elif self._oparkz_check(-0.9 - 29): + parkingposition = 5 + elif self._oparkz_check(-0.9 - 29 * 2): + parkingposition = 4 + elif self._oparkz_check(-0.9 - 29 * 3): + parkingposition = 3 + elif self._oparkz_check(-0.9 - 29 * 3 - 42 - 0.05): + parkingposition = 2 + + if parkingposition == 10: + print("Oparkz is not in a parking position.") + else: + print(f"Active parkting position: {parkingposition}") + + return parkingposition + + def _oparkz_drive_and_check_leica(self, targetpos): + oparkz_current = dev.oparkz.get().readback + if (oparkz_current - targetpos) >= 0.05: + self._otransfer_mode_ensurenot() + # make sure shuttle closed + self._otransfer_ensure_shuttle_closed() + self._otransfer_shuttle_aligner_down() + umv(dev.oparkz, targetpos) + + # when mounting a sample, this variable is defined at the release position of the sample + def _otransfer_get_release_position(self) -> float: + return float(dev.otransy.controller.socket_put_and_receive("MGrelpos")) + + # when a sample is picked, this variable is defined after touching the top of the pin + 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) -> float: + + # pos 0 ST / position in separate macro + # pos 1 to 6 at sample shuttle + # pos 7 FZP in shuttle + # pos 10 FZP in fixed holder right + # pos 100 FZP stage / position in separate macro + + # make sure 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 + # at RT was -0.05 at cryo -0.15 + + otrans_pin_positions = { + 1: [-1.3368 + xoffsettransfer, -25.0, -41.6591 + zoffsettransfer, "shuttle sample 1"], + 2: [ + -1.3368 + xoffsettransfer, + -25.0, + -41.6591 - 8 + zoffsettransfer, + "shuttle sample 1", + ], + 3: [ + -1.3368 + 7 + xoffsettransfer, + -25.0, + -41.6591 + zoffsettransfer, + "shuttle sample 1", + ], + 4: [ + -1.3368 + 7 + xoffsettransfer, + -25.0, + -41.6591 - 8 + zoffsettransfer, + "shuttle sample 1", + ], + 5: [ + -1.3368 + 14 + xoffsettransfer, + -25.0, + -41.6591 + zoffsettransfer, + "shuttle sample 1", + ], + 6: [ + -1.3368 + 14 + xoffsettransfer, + -25.0, + -41.6591 - 8 + zoffsettransfer, + "shuttle sample 1", + ], + 7: [-1.884 + 0.2 + 0.2432, -17, -49.94 + 0.6, "FZP holder"], + 8: [-13.4159 + 0.2432, -16, -46.5638 + 0.6, "OSA Holder 1"], + 9: [-13.4159 + 18.5 + 0.2432, -16, -46.5638 + 0.6, "OSA Holder 2"], + 10: [-80.9 + 0.2 + 0.2432, -16.0, -46.07 - 0.21 + 0.6, "fixed FZP Holder right"], + 11: [-80.9 + 0.2 + 0.2432, -16.0, -46.07 + 18 - 0.21 + 0.6, "fixed FZP Holder left"], + 12: [-104.67 + 0.2432, -23.9601, -49.600, "fixed holder 12"], + 13: [-104.67 + 0.2432, -23.9601, -49.600 + 8, "fixed holder 13"], + 14: [-104.67 + 0.2432, -23.9601, -49.600 + 16, "fixed holder 14"], + 32: [ + -104.8718 + 0.2, + -24.9601, + -42.1385 - 0.05 - 8 - 15 - 0.21 + 0.6, + "fixed holder 32", + ], + 33: [ + -104.8718 + 0.2 + 0.2432, + -24.9601, + -42.1385 - 0.05 - 15 - 0.21 + 0.6, + "fixed holder 33", + ], + 34: [ + -104.8718 + 0.2 + 0.2432, + -24.9601, + -42.1385 - 0.05 + 8 - 15 - 0.21 + 0.6, + "fixed holder 34", + ], + } + + if ( + pin_position not in range(0, 15) + and pin_position not in range(32, 35) + and pin_position != 100 + ): + raise OMNYTransferError(f"Position {pin_position} is not a valid pin position") + + 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 + 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 + umv( + dev.otransx, + otrans_pin_positions[pin_position][0], + dev.otransz, + otrans_pin_positions[pin_position][2], + ) + + if pin_position in range(10, 15): + current_parkz_slot = self._oparkz_slot_check() + if current_parkz_slot != 6: + raise OMNYTransferError( + "Sample position ranging from 10 to 14 are only defined for parkz slot 6, while the setup is currently in slot {current_parkz_slot}." + ) + + self._otransfer_gripper_to_park_z() + self._otransfer_oparkz_safe_shuttle_operation() + _otransy_approach_height = otrans_pin_positions[pin_position][1] # vertical position + umv(dev.otransx, otrans_pin_positions[pin_position][0]) + umv(dev.otransz, otrans_pin_positions[pin_position][2]) + + if pin_position in range(32, 35): + current_parkz_slot = self._oparkz_slot_check() + if current_parkz_slot != 2: + raise OMNYTransferError( + "Sample position ranging from 32 to 34 are only defined for parkz slot 2, while the setup is currently in slot {current_parkz_slot}." + ) + + raise OMNYSampleTransferMixin("Positions 32-24 need check before use, not commissioned") + # self._otransfer_gripper_to_park_z() + # self._otransfer_oparkz_safe_shuttle_operation() + # _otransy_approach_height=otrans_pin_positions[pin_position][1] #vertical position + # umv(dev.otransx, otrans_pin_positions[pin_position][0]) + # umv(dev.otransz, otrans_pin_positions[pin_position][2]) + + # sample stage + if pin_position == 0: + # oeye_cam_in + self._otransfer_gripper_to_park_z() + self._otransfer_stage_to_ST(pin_position) + _otransy_approach_height = -34 + # todo + # global xrayeye_alignment_done + # xrayeye_alignment_done = 0 + + # change sample name and increase measurement id if sample is at sample stage + # todo and to check + # # if (epics_get("XOMNY-SAMPLE_DB_omny:0.VAL") == 1) { + # local _new_sample_name + # _new_sample_name = epics_get("XOMNY-SAMPLE_DB_omny:0.DESC") + # # increase the metadatasetID, even if _dataset_id_on_hold==true + # global _dataset_id_on_hold + # if (_dataset_id_on_hold){ + # _meta_dataset_id++ + # } + # metadata_set("samplename", "string", 1, _new_sample_name) + # } + + # FZP + if pin_position == 100: + self._otransfer_gripper_to_park_z() + self._otransfer_stage_to_FZP() + _otransy_approach_height = -7 + + # OSA + if pin_position == 101: + raise OMNYTransferError("OSA Transfer disabled. Needs commissioning.") + # self._otransfer_gripper_to_park_z + # self._otransfer_stage_to_OSA + # _otransy_approach_height=-15 + + # set the force of the gripper for pushing + # positions with FZP holder + if pin_position == 7 or pin_position == 10 or pin_position == 11 or pin_position == 100: + dev.otransy.controller.socket_put_confirmed("pushfrce=1.5") + else: + dev.otransy.controller.socket_put_confirmed("pushfrce=0.8") + + return _otransy_approach_height + + def _otransfer_controller_query_mount_mode(self) -> bool: + return bool(float(dev.otransy.controller.socket_put_and_receive("MGmntmod"))) + + def _otransfer_controller_enable_mount_mode(self): + dev.otransy.controller.socket_put_confirmed("XQ#MNTMODE") time.sleep(0.5) + if not self._otransfer_controller_query_mount_mode(): + raise OMNYTransferError("System not switched to mount mode.") - if not dev.otransx.controller.all_axes_referenced(): - raise OMNYTransferError("Not all axes are referenced.") - - up_position = self._get_user_param_safe("otransy", "up_position") + def _otransfer_controller_disable_mount_mode(self): + dev.otransy.controller.socket_put_confirmed("XQ#POSMODE") + time.sleep(0.5) + if self._otransfer_controller_query_mount_mode(): + raise OMNYTransferError("System is still in sample mount mode.") - if np.fabs(dev.otransx.get().readback-20)<0.1 and dev.otransy.get().readback>up_position - 0.1 and np.fabs(dev.otransz.get().readback+50)<0.1: - print("Gripper is in parking position") - else: - print("Gripper is not yet in parking position. Moving...") - self._otransfer_gripper_up() + def _otransfer_gripper_querry_status_closed(self): + dev.otransy.controller.socket_put_confirmed("XQ#GRSTAT") + time.sleep(0.05) + return bool(float(dev.otransy.controller.socket_put_and_receive("MGgrstat"))) + + def otransfer_put_sample(self, pin_position: int): + self._otransfer_check_sensor_connected() + if not self._otransfer_check_free_slot_available_at_position(pin_position, 0): + raise OMNYTransferError(f"position {pin_position} is not free") + + # global _ogalil_encoder_steps_per_mm + if pin_position == 0: + self._omnycam_samplestage() + else: + self._omnycam_parking() + + self._otransfer_gripper_to_park_z() + _otransy_approach_height = self._otransfer_move_gripper_to_pin_pos(pin_position) + self._otransfer_controller_enable_mount_mode() + dev.otransy.controller.socket_put_confirmed(f"mntaprch={_otransy_approach_height:.2f}") + + input("Ready. Press Enter to start the mount process now...") + dev.otransy.controller.socket_put_confirmed("XQ#GRPUT") + + print("The mount process started.") + + self._otransfer_confirm() + self._otransfer_controller_disable_mount_mode() + # update the new sample status in storage + self._otransfer_check_free_slot_available_at_position(pin_position, 1) + # this also moves the gripper to parking position + # alternatively a next sample is to be picked + # keep shuttle open and ask user which sample to pick + # but have to make sure that shield will be closed for sample pos movements beyond shuttle positions + if pin_position in range(1, 7): + if self.OMNYTools.yesno( + "Pick another sample from this shuttle? Keep shield open?", "y" + ): + print( + " In case ... the shield can be manually closed by omny._otransfer_shield_close(1)." + ) + else: + self._otransfer_shield_close(pin_position) + else: + self._otransfer_shield_close(pin_position) + dev.omny_samples.show_all() + + def _otransfer_confirm(self): + mntprgs = 1 + + while mntprgs != 0: + time.sleep(1) + confirm = int(float(dev.otransy.controller.socket_put_and_receive("MGconfirm"))) + time.sleep(0.02) + mntprgs = int(float(dev.otransy.controller.socket_put_and_receive("MGmntprgs"))) + time.sleep(0.02) + if confirm == 0: + # print(f"otransy position {dev.otransz.readback.get()}", end=" ") + # print("Confirm check - no confirmation needed yet.") + pass + elif confirm == -1: + # we are getting a sample + if mntprgs == -1: + toppin = self._otransfer_get_toppin_position() + print(f"TopPin position is {toppin:.3f} mm") + if self._otransfer_get_toppin_position() > -25.4: + if not self.OMNYTools.yesno( + "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? Continue?" + ): + raise OMNYTransferError("Abort by user because of top pin position.") + text = "All OK?" + # we are mounting a sample + elif mntprgs == 1: + text = "All OK? Please confirm. First confirmation = sample release" + elif mntprgs == 0: + text = "All OK? Please confirm" + + if self.OMNYTools.yesno(text, "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(self): + sensorvoltage = float(dev.otransy.controller.socket_put_and_receive("MG@AN[8001]")) + gripper_sensorvoltagetarget = self._get_user_param_safe( + "otransy", "gripper_sensorvoltagetarget" + ) + if not np.fabs(sensorvoltage - gripper_sensorvoltagetarget) < 0.5: + raise OMNYTransferError( + f"Sensorvoltage is {sensorvoltage:.2f} V. This indicates a sensor error." + ) + + def otransfer_get_sample(self, pin_position: int): + self._omnycam_parking() + if not self.OMNYTools.yesno( + "Please confirm that currently there is no sample in the gripper. It would be dropped!", + "y", + ): + raise OMNYTransferError("Transfer process has been manually aborted.") + # clean abort before starting + dev.otransx.controller.socket_put_confirmed("XQ#STOP,1") + time.sleep(0.1) + + 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}") + + # global _otransy_approach_height + # global _ogalil_encoder_steps_per_mm + + if pin_position == 0 or pin_position == 100: + # oeye_cam_in + self._omnycam_samplestage() + # if (_rt_status_feedback() == 0) { + # print("May the feedback be disabled? Y/n?") + # if(!yesno(1)) + # exit; + # } + # rt_feedback_disable + else: + self._omnycam_parking() + + _otransy_approach_height = self._otransfer_move_gripper_to_pin_pos(pin_position) + self._otransfer_controller_enable_mount_mode() + + dev.otransy.controller.socket_put_confirmed(f"getaprch={_otransy_approach_height:.2f}") + + input("Ready. Press Enter to start the mount process now...") + + dev.otransy.controller.socket_put_confirmed("XQ#GRGET") + + print("The Unmount process started.") + time.sleep(1) + 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() + + def _otransfer_stage_to_ST(self, pin_position): + self._otransfer_gripper_to_park_z() - #if coming from a position beyond a shuttle in parking station - if dev.otransx.get().readback < -2: self._otransfer_ensure_shield_parking_closed() - #coming from an OSA or FZP transfer or also sample. Ensure shield open - if dev.otransx.get().readback < -350: + 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 - if dev.oeyez.get().readback<-5: - self.oeye_cam_in() - - #is executed in shield_st_open - _otransfer_gripper_up - self._oshield_ST_open() - umv(dev.otransz, 0) - #the oosa has in principle to be out because of shield open above - #if that is the case, then we do simultaneous shield and trans movement + # if xray eye is in, move it out + oeyez_current = dev.oeyez.get().readback + if oeyez_current < -5: + self.oeye_cam_in() + + # old gripper motor + # check ST position and move gripper to ST + # umv otransz -18 + # umv osamroy 0 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 "rtx" in dev and dev.rtx.enabled: + feedback_status = self.device_manager.devices.rtx.controller.feedback_is_running() + if feedback_status == True: + # feedback is running + if self.OMNYTools.yesno("May the feedback be disabled", "y"): + raise OMNYTransferError( + "Manual abort of sample transfer, need to disable feedback has not been confirmed." + ) + + self.device_manager.devices.rtx.controller.feedback_disable() + + fshclose() + + if oeyez_current < -20: + raise OMNYTransferError( + "Eyez is too close to the sample stage for unknown reason. Aborting." + ) + + # 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) + + oeyez_current = dev.oeyez.get().readback + + if np.fabs(oeyez_current + 2) > 0.1: + raise OMNYTransferError("The oeye is too close in z for transfer. ERROR!") + + # 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 - if oosaz_current<0.1: - umv(dev.otransx, -350, dev.oshield, 15.5) - #if the gripper is empty, then we can already move the xeye to the xray position - #simultaneous motion to reduce time. otherwise later manual eye in - if not dev.omny_samples.is_sample_in_gripper(): - #todo the oeyey mv may not be accessible - _omny_oeye_xray_inx = self._get_user_param_safe("oeyex", "xray_in") - _omny_oeye_xray_iny = self._get_user_param_safe("oeyey", "xray_in") - self._oeyey_mv(_omny_oeye_xray_iny) - umv(dev.otransx, -100, dev.oeyex, _omny_oeye_xray_inx, dev.oeyez, -2) - else: - umv(dev.otransx, -100) + + if oosaz_current < 0.1 and oosax_current < -1.5: + oeyey_current = dev.oeyey.get().readback + if oeyey_current < -40: + umv( + dev.osamroy, + 0, + dev.osamy, + 2.7, + dev.osamx, + 0, + dev.otransx, + -350, + dev.oeyex, + 0, + dev.oeyey, + -15, + ) + else: + umv(dev.osamroy, 0, 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, dev.otransz, -45.6494) else: - self._oshield_ST_close() - umv(dev.otransx, -100) - - #if process was aborted while moving to ST - if dev.otransx.get().readback < -105: - #if xray eye is in, move it out - if dev.oeyez.get().readback<-5: - self.oeye_cam_in() - self._oshield_ST_close() - umv(dev.otransz, 0) - umv(dev.otransx, -100) - - umv(dev.otransx, 20, dev.otransz, -50) - - - def _otransfer_gripper_safe_xray_in_operation(self): - if not dev.otransx.controller.all_axes_referenced(): - raise OMNYTransferError("Not all axes are referenced.") - self._otransfer_gripper_to_park_z() - - def _otransfer_mode_query(self) -> bool: - return(bool(float(dev.otransx.controller.socket_put_and_receive("MG mntmod")))) - - def _otransfer_mode_ensurenot(self): - if self._otransfer_mode_query(): - raise OMNYTransferError("System is in transfer mode.") - - def otransfer_park_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.") - if slot_number == 2: - self._oparkz_drive_and_check(-0.9-29*3-42-.05) - elif slot_number == 3: - self._oparkz_drive_and_check(-0.9-29*3) - elif slot_number == 4: - self._oparkz_drive_and_check(-0.9-29*2) - elif slot_number == 5: - self._oparkz_drive_and_check(-0.9-29) - elif slot_number == 6: - self._oparkz_drive_and_check(-0.9) - - - def otransfer_park_loadlock_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.") - #if the valve of the loadlock is not closed, ask before movement - #todo if(epics_get("XOMNY-ES1-LL1VG1:POSITION")!="CLOSED") { - 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: - self._oparkz_drive_and_check(-6-29*3) - elif slot_number == 4: - self._oparkz_drive_and_check(-6-29*2) - elif slot_number == 5: - self._oparkz_drive_and_check(-6-29) - elif slot_number == 6: - self._oparkz_drive_and_check(-6) - - def _oparkz_drive_and_check(self, targetpos): - oparkz_current = dev.oparkz.get().readback - if np.fabs(oparkz_current-targetpos)>=0.05: - self._otransfer_mode_ensurenot() - #make sure shield closed - self._otransfer_ensure_shuttle_closed() - self._otransfer_shuttle_aligner_down() - umv(dev.oparkz, targetpos) - - def _oparkz_check(self, targetpos) -> bool: - oparkz_current = dev.oparkz.get().readback - if np.fabs(oparkz_current-targetpos)<0.05: - return True - else: - return False - - def _oparkz_slot_check(self): - parkingposition=10 - if self._oparkz_check(-0.9): - parkingposition=6 - elif self._oparkz_check(-0.9-29): - parkingposition=5 - elif self._oparkz_check(-0.9-29*2): - parkingposition=4 - elif self._oparkz_check(-0.9-29*3): - parkingposition=3 - elif self._oparkz_check(-0.9-29*3-42-.05): - parkingposition=2 - - if parkingposition == 10: - print("Oparkz is not in a parking position.") - else: - print(f"Active parkting position: {parkingposition}") - - return parkingposition - - - def _oparkz_drive_and_check_leica(self, targetpos): - oparkz_current = dev.oparkz.get().readback - if (oparkz_current-targetpos)>=0.05: - self._otransfer_mode_ensurenot() - #make sure shuttle closed - self._otransfer_ensure_shuttle_closed() - self._otransfer_shuttle_aligner_down() - umv(dev.oparkz, targetpos) - - - #when mounting a sample, this variable is defined at the release position of the sample - def _otransfer_get_release_position(self) -> float: - return(float(dev.otransy.controller.socket_put_and_receive("MGrelpos"))) - - #when a sample is picked, this variable is defined after touching the top of the pin - 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) -> float: - - #pos 0 ST / position in separate macro - #pos 1 to 6 at sample shuttle - #pos 7 FZP in shuttle - #pos 10 FZP in fixed holder right - #pos 100 FZP stage / position in separate macro - - - #make sure 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 - #at RT was -0.05 at cryo -0.15 - - otrans_pin_positions = { - 1:[-1.3368+xoffsettransfer, -25.0, -41.6591+zoffsettransfer, "shuttle sample 1"], - 2:[-1.3368+xoffsettransfer, -25.0, -41.6591-8+zoffsettransfer, "shuttle sample 1"], - 3:[-1.3368+7+xoffsettransfer, -25.0, -41.6591+zoffsettransfer, "shuttle sample 1"], - 4:[-1.3368+7+xoffsettransfer, -25.0, -41.6591-8+zoffsettransfer, "shuttle sample 1"], - 5:[-1.3368+14+xoffsettransfer, -25.0, -41.6591+zoffsettransfer, "shuttle sample 1"], - 6:[-1.3368+14+xoffsettransfer, -25.0, -41.6591-8+zoffsettransfer, "shuttle sample 1"], - 7:[-1.884+0.2+0.2432, -17, -49.94+0.6, "FZP holder"], - 8:[-13.4159+0.2432, -16, -46.5638+0.6, "OSA Holder 1"], - 9:[-13.4159+18.5+0.2432, -16, -46.5638+0.6, "OSA Holder 2"], - 10:[-80.9+0.2+0.2432, -16.0, -46.07-0.21+0.6, "fixed FZP Holder right"], - 11:[-80.9+0.2+0.2432, -16.0, -46.07+18-0.21+0.6, "fixed FZP Holder left"], - 12:[-104.67+0.2432, -23.9601, -49.600, "fixed holder 12"], - 13:[-104.67+0.2432, -23.9601, -49.600+8, "fixed holder 13"], - 14:[-104.67+0.2432, -23.9601, -49.600+16, "fixed holder 14"], - 32:[-104.8718+0.2, -24.9601, -42.1385-0.05-8-15-0.21+0.6, "fixed holder 32"], - 33:[-104.8718+0.2+0.2432, -24.9601, -42.1385-0.05-15-0.21+0.6, "fixed holder 33"], - 34:[-104.8718+0.2+0.2432, -24.9601, -42.1385-0.05+8-15-0.21+0.6, "fixed holder 34"] - } - - if pin_position not in range(0,15) and pin_position not in range(32,35) and pin_position != 100: - raise OMNYTransferError(f"Position {pin_position} is not a valid pin position") - - 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 - 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 - umv(dev.otransx, otrans_pin_positions[pin_position][0], dev.otransz, otrans_pin_positions[pin_position][2]) - - if pin_position in range(10,15): - current_parkz_slot = self._oparkz_slot_check() - if current_parkz_slot != 6: - raise OMNYTransferError("Sample position ranging from 10 to 14 are only defined for parkz slot 6, while the setup is currently in slot {current_parkz_slot}.") - - self._otransfer_gripper_to_park_z() - self._otransfer_oparkz_safe_shuttle_operation() - _otransy_approach_height=otrans_pin_positions[pin_position][1] #vertical position - umv(dev.otransx, otrans_pin_positions[pin_position][0]) - umv(dev.otransz, otrans_pin_positions[pin_position][2]) - - if pin_position in range(32,35): - current_parkz_slot = self._oparkz_slot_check() - if current_parkz_slot != 2: - raise OMNYTransferError("Sample position ranging from 32 to 34 are only defined for parkz slot 2, while the setup is currently in slot {current_parkz_slot}.") - - raise OMNYSampleTransferMixin("Positions 32-24 need check before use, not commissioned") - # self._otransfer_gripper_to_park_z() - # self._otransfer_oparkz_safe_shuttle_operation() - # _otransy_approach_height=otrans_pin_positions[pin_position][1] #vertical position - # umv(dev.otransx, otrans_pin_positions[pin_position][0]) - # umv(dev.otransz, otrans_pin_positions[pin_position][2]) - - #sample stage - if(pin_position==0): - #oeye_cam_in - self._otransfer_gripper_to_park_z() - self._otransfer_stage_to_ST(pin_position) - _otransy_approach_height=-34 - #todo - # global xrayeye_alignment_done - # xrayeye_alignment_done = 0 - - #change sample name and increase measurement id if sample is at sample stage - #todo and to check - # # if (epics_get("XOMNY-SAMPLE_DB_omny:0.VAL") == 1) { - # local _new_sample_name - # _new_sample_name = epics_get("XOMNY-SAMPLE_DB_omny:0.DESC") - # # increase the metadatasetID, even if _dataset_id_on_hold==true - # global _dataset_id_on_hold - # if (_dataset_id_on_hold){ - # _meta_dataset_id++ - # } - # metadata_set("samplename", "string", 1, _new_sample_name) - # } - - - #FZP - if pin_position==100: - self._otransfer_gripper_to_park_z() - self._otransfer_stage_to_FZP() - _otransy_approach_height=-7 - - #OSA - if pin_position==101: - raise OMNYTransferError("OSA Transfer disabled. Needs commissioning.") - # self._otransfer_gripper_to_park_z - # self._otransfer_stage_to_OSA - # _otransy_approach_height=-15 - - #set the force of the gripper for pushing - #positions with FZP holder - if pin_position == 7 or pin_position == 10 or pin_position == 11 or pin_position == 100: - dev.otransy.controller.socket_put_confirmed("pushfrce=1.5") - else: - dev.otransy.controller.socket_put_confirmed("pushfrce=0.8") - - return _otransy_approach_height - - - def _otransfer_controller_query_mount_mode(self) -> bool: - return(bool(float(dev.otransy.controller.socket_put_and_receive("MGmntmod")))) - - - def _otransfer_controller_enable_mount_mode(self): - dev.otransy.controller.socket_put_confirmed("XQ#MNTMODE") - time.sleep(0.5) - if not self._otransfer_controller_query_mount_mode(): - raise OMNYTransferError("System not switched to mount mode.") - - def _otransfer_controller_disable_mount_mode(self): - dev.otransy.controller.socket_put_confirmed("XQ#POSMODE") - time.sleep(0.5) - if self._otransfer_controller_query_mount_mode(): - raise OMNYTransferError("System is still in sample mount mode.") - - def _otransfer_gripper_querry_status_closed(self): - dev.otransy.controller.socket_put_confirmed("XQ#GRSTAT") - time.sleep(0.05) - return(bool(float(dev.otransy.controller.socket_put_and_receive("MGgrstat")))) - - def otransfer_put_sample(self, pin_position:int): - self._otransfer_check_sensor_connected() - if not self._otransfer_check_free_slot_available_at_position(pin_position,0): - raise OMNYTransferError(f"position {pin_position} is not free") - -# global _ogalil_encoder_steps_per_mm - if pin_position==0: - self._omnycam_samplestage() - else: - self._omnycam_parking() - - self._otransfer_gripper_to_park_z() - _otransy_approach_height = self._otransfer_move_gripper_to_pin_pos(pin_position) - self._otransfer_controller_enable_mount_mode() - dev.otransy.controller.socket_put_confirmed(f"mntaprch={_otransy_approach_height:.2f}") - - input("Ready. Press Enter to start the mount process now...") - dev.otransy.controller.socket_put_confirmed("XQ#GRPUT") - - print("The mount process started.") - - self._otransfer_confirm() - self._otransfer_controller_disable_mount_mode() - #update the new sample status in storage - self._otransfer_check_free_slot_available_at_position(pin_position,1) - #this also moves the gripper to parking position - #alternatively a next sample is to be picked - #keep shuttle open and ask user which sample to pick - #but have to make sure that shield will be closed for sample pos movements beyond shuttle positions - if pin_position in range(1,7): - if self.OMNYTools.yesno("Pick another sample from this shuttle? Keep shield open?","y"): - print(" In case ... the shield can be manually closed by omny._otransfer_shield_close(1).") - else: - self._otransfer_shield_close(pin_position) - else: - self._otransfer_shield_close(pin_position) - dev.omny_samples.show_all() - - - def _otransfer_confirm(self): - mntprgs=1 - - while(mntprgs != 0): - time.sleep(1) - confirm = (int(float(dev.otransy.controller.socket_put_and_receive("MGconfirm")))) - time.sleep(0.02) - mntprgs = (int(float(dev.otransy.controller.socket_put_and_receive("MGmntprgs")))) - time.sleep(0.02) - if confirm == 0: - #print(f"otransy position {dev.otransz.readback.get()}", end=" ") - #print("Confirm check - no confirmation needed yet.") - pass - elif confirm == -1: - #we are getting a sample - if mntprgs == -1: - toppin = self._otransfer_get_toppin_position() - print(f"TopPin position is {toppin:.3f} mm") - if self._otransfer_get_toppin_position()>-25.4: - if not self.OMNYTools.yesno("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? Continue?"): - raise OMNYTransferError("Abort by user because of top pin position.") - text = "All OK?" - #we are mounting a sample - elif mntprgs == 1: - text = "All OK? Please confirm. First confirmation = sample release" - elif mntprgs == 0: - text = "All OK? Please confirm" - - if self.OMNYTools.yesno(text,"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(self): - sensorvoltage = (float(dev.otransy.controller.socket_put_and_receive("MG@AN[8001]"))) - gripper_sensorvoltagetarget = self._get_user_param_safe("otransy", "gripper_sensorvoltagetarget") - if not np.fabs(sensorvoltage - gripper_sensorvoltagetarget) < 0.5: - raise OMNYTransferError(f"Sensorvoltage is {sensorvoltage:.2f} V. This indicates a sensor error.") - - def otransfer_get_sample(self, pin_position: int): - self._omnycam_parking() - if not self.OMNYTools.yesno("Please confirm that currently there is no sample in the gripper. It would be dropped!","y"): - raise OMNYTransferError("Transfer process has been manually aborted.") - #clean abort before starting - dev.otransx.controller.socket_put_confirmed("XQ#STOP,1") - time.sleep(0.1) - - 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}") - -# global _otransy_approach_height -# global _ogalil_encoder_steps_per_mm - - if pin_position==0 or pin_position==100: - # oeye_cam_in - self._omnycam_samplestage() - # if (_rt_status_feedback() == 0) { - # print("May the feedback be disabled? Y/n?") - # if(!yesno(1)) - # exit; - #} - # rt_feedback_disable - else: - self._omnycam_parking() - - - _otransy_approach_height = self._otransfer_move_gripper_to_pin_pos(pin_position) - self._otransfer_controller_enable_mount_mode() - - dev.otransy.controller.socket_put_confirmed(f"getaprch={_otransy_approach_height:.2f}") - - input("Ready. Press Enter to start the mount process now...") - - dev.otransy.controller.socket_put_confirmed("XQ#GRGET") - - print("The Unmount process started.") - time.sleep(1) - 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() - - - - - def _otransfer_stage_to_ST(self,pin_position): - self._otransfer_gripper_to_park_z() - - self._otransfer_ensure_shield_parking_closed() - - - 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() - - #old gripper motor - #check ST position and move gripper to ST - #umv otransz -18 - #umv osamroy 0 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 "rtx" in dev and dev.rtx.enabled: - feedback_status = self.device_manager.devices.rtx.controller.feedback_is_running() - if feedback_status == True: - #feedback is running - if self.OMNYTools.yesno("May the feedback be disabled","y"): - raise OMNYTransferError("Manual abort of sample transfer, need to disable feedback has not been confirmed.") - - self.device_manager.devices.rtx.controller.feedback_disable() - - fshclose() - - if oeyez_current<-20: - raise OMNYTransferError("Eyez is too close to the sample stage for unknown reason. Aborting.") - - #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) - - oeyez_current = dev.oeyez.get().readback - - if np.fabs(oeyez_current+2)>0.1: - raise OMNYTransferError("The oeye is too close in z for transfer. ERROR!") - - #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 - - - if oosaz_current<0.1 and oosax_current < -1.5: - oeyey_current = dev.oeyey.get().readback - if oeyey_current < -40: - umv(dev.osamroy, 0, dev.osamy, 2.7, dev.osamx, 0, dev.otransx, -350, dev.oeyex, 0, dev.oeyey, -15) - else: - umv(dev.osamroy, 0, 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, dev.otransz, -45.6494) - else: - umv(dev.osamroy, 0, dev.osamy, 2.7, dev.osamx, 0, dev.otransx, -458.1545+0.05, dev.oeyex, 0, dev.oeyey, -4.8) - - self.oeye_cam_in() - - self._otransfer_shield_open(pin_position) - umv(dev.otransz, -45.6494) - - - def _otransfer_stage_to_FZP(self): - - raise OMNYTransferError("This routine needs commissioning after park pos of gripper and new transfer stages changed.") - - # print("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 - - - # }' - - def _otransfer_stage_to_OSA(self): - - raise OMNYTransferError("This routine needs commissioning after park pos of gripper and new transfer stages changed.") - - # if(A[ofzpz]>40) { - # print("The FZP stage is too close in z direction. Please move it to at least 60 mm or less upstream.") - # 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) + umv( + dev.osamroy, + 0, + dev.osamy, + 2.7, + dev.osamx, + 0, + dev.otransx, + -458.1545 + 0.05, + dev.oeyex, + 0, + dev.oeyey, + -4.8, + ) + + self.oeye_cam_in() + + self._otransfer_shield_open(pin_position) + umv(dev.otransz, -45.6494) + + def _otransfer_stage_to_FZP(self): + + raise OMNYTransferError( + "This routine needs commissioning after park pos of gripper and new transfer stages changed." + ) + + # print("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 + + # }' + + def _otransfer_stage_to_OSA(self): + + raise OMNYTransferError( + "This routine needs commissioning after park pos of gripper and new transfer stages changed." + ) + + # if(A[ofzpz]>40) { + # print("The FZP stage is too close in z direction. Please move it to at least 60 mm or less upstream.") + # 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) + # { + # print("FZP did not reach target position. Potentially the motor is too hot.") + # 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(sprint("XOMNY-SAMPLE_DB_%s:%d.VAL", _ocontainer, _oposition),0) + # epics_put(sprint("XOMNY-SAMPLE_DB_%s:%d.DESC", _ocontainer, _oposition),"-") + # #sample at position + # if _ostatus>0: + # epics_put(sprint("XOMNY-SAMPLE_DB_%s:%d.VAL",_ocontainer, _oposition),_ostatus) + # epics_put(sprint("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") # { - # print("FZP did not reach target position. Potentially the motor is too hot.") - # exit + # epics_put(sprint("XOMNY-SAMPLE_DB_parking:%d.VAL", _oparkposition),0) + # epics_put(sprint("XOMNY-SAMPLE_DB_parking:%d.DESC", _oparkposition),"-") + # } + # else + # { + # epics_put(sprint("XOMNY-SAMPLE_DB_parking:%d.VAL", _oparkposition),1) + # epics_put(sprint("XOMNY-SAMPLE_DB_parking:%d.DESC", _oparkposition), _ocontainer) # } # }' - def otransfer_storage(self): - dev.omny_samples.show_all() + def _otransfer_check_sample_available_at_position( + self, _osampleposition: int, _picked_it: bool + ) -> bool: + # 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.") - # 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 + # _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 True + else: + print("There is no sample availabe at that position.") + return False + else: + print("There is no sample shuttle installed at the current parkz position.") + return False - # if _ocontainer=="omny": - # if _oposition == 0: - + # # _osampleposition 7 for FZPs + # if (_osampleposition==7) { + # local activeparkingposition + # local installedshuttle + # activeparkingposition = _oparkz_slot_check() + # if(activeparkingposition==10) + # exit + # installedshuttle = epics_get(sprint("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(sprint("XOMNY-SAMPLE_DB_shuttle_FZP:0.DESC")) + # _otransfer_modify_sample(installedshuttle, 0, 0, "-") + # _otransfer_modify_sample("omny",110,2,samplename) + # } + # return(1) + # } + # else + # { + # print("There is no FZP available.") + # return(0) + # } + # } + # else + # { + # print("There is no FZP shuttle installed at the current parkz position.") + # 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(sprint("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(sprint("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 + # { + # print("There is no OSA available.") + # return(0) + # } + # } + # else + # { + # print("There is no OSA shuttle installed at the current parkz position.") + # 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: + 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 True + else: + print("There is nothing to get from this position.") + return False + # sample stage + elif _osampleposition == 0: + if dev.omny_samples.is_sample_in_samplestage(): + if _picked_it: + 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 True + else: + print("There is no sample in the sample stage.") + return False - # #free a position - # if _ostatus==0: - # epics_put(sprint("XOMNY-SAMPLE_DB_%s:%d.VAL", _ocontainer, _oposition),0) - # epics_put(sprint("XOMNY-SAMPLE_DB_%s:%d.DESC", _ocontainer, _oposition),"-") - # #sample at position - # if _ostatus>0: - # epics_put(sprint("XOMNY-SAMPLE_DB_%s:%d.VAL",_ocontainer, _oposition),_ostatus) - # epics_put(sprint("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) + return 0 + def _otransfer_check_free_slot_available_at_position( + self, _osampleposition: int, _put_it: bool + ) -> bool: + # 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 -# def _otransfer_modify_parking(self, _oparkposition, _ocontainer): -# #_ocontainer is A, B, C for the pin containers -# #it can also be FZP, and OSA + # 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.") -# self._otransfer_check_parking(_ocontainer) + # this was from early omny when automatic changing of samples, fzps and osas was expected + # the idea was that it is distinguished wich kind of holder is currently in the gripper. turns out not to be needed. + # special transfer is always very manual with a lot of attention. + # + # #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 + # { + # print("There is a sample pin in the gripper, which is not compatible with position %d", _osampleposition) + # exit + # } + # #FZP holder + # if (epics_get("XOMNY-SAMPLE_DB_omny:110.VAL")==2) + # if (_osampleposition == 7 || _osampleposition == 10 || _osampleposition == 11 || _osampleposition == 100) + # { } + # else + # { + # print("There is a FZP holder in the gripper, which is not compatible with position %d", _osampleposition) + # exit + # } + # #OSA holder + # if (epics_get("XOMNY-SAMPLE_DB_omny:110.VAL")==3) + # if (_osampleposition == 8 || _osampleposition == 9 || _osampleposition == 101 ) + # { } + # else + # { + # print("There is an OSA holder in the gripper, which is not compatible with position %d", _osampleposition) + # exit + # } -# #free a position -# if (_ocontainer=="0") -# { -# epics_put(sprint("XOMNY-SAMPLE_DB_parking:%d.VAL", _oparkposition),0) -# epics_put(sprint("XOMNY-SAMPLE_DB_parking:%d.DESC", _oparkposition),"-") -# } -# else -# { -# epics_put(sprint("XOMNY-SAMPLE_DB_parking:%d.VAL", _oparkposition),1) -# epics_put(sprint("XOMNY-SAMPLE_DB_parking:%d.DESC", _oparkposition), _ocontainer) -# } + # _osampleposition 1 to 6 are in shuttles + if _osampleposition > 0 and _osampleposition < 7: + activeparkingposition = self._oparkz_slot_check() + if activeparkingposition == 10: + raise OMNYTransferError("Parking stage is not at an active parking position.") + 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 free position available? + if not dev.omny_samples.is_sample_slot_used(installedshuttle, _osampleposition): + if _put_it: + samplename = dev.omny_samples.get_sample_name_in_gripper() + dev.omny_samples.unset_sample_in_gripper() + dev.omny_samples.set_sample_slot( + installedshuttle, _osampleposition, samplename + ) + return True + else: + print("There is no free sample slot availabe at that position.") + return False + else: + print("There is no sample shuttle installed at the current parkz position.") + return False -# }' + # OSA and FZP section, needs commissioning, was never + # _osampleposition 7 for FZPs + # if _osampleposition==7: + # activeparkingposition = _oparkz_slot_check() + # if(activeparkingposition==10) + # exit + # installedshuttle = epics_get(sprint("XOMNY-SAMPLE_DB_parking:%d.DESC", activeparkingposition)) + # #is there a samle shuttle at this position? + # if(installedshuttle == "FZP") + # { + # #is there a free FZP slot available? + # if (epics_get("XOMNY-SAMPLE_DB_shuttle_FZP:0.VAL")==0) + # { + # if(_put_it==1) + # { + # samplename = epics_get(sprint("XOMNY-SAMPLE_DB_omny:110.DESC")) + # _otransfer_modify_sample(installedshuttle, 0, 1, samplename) + # _otransfer_modify_sample("omny",110,0,"-") + # } + # return(1) + # } + # else + # { + # print("There is no free FZP position available.") + # return(0) + # } + # } + # else + # { + # print("There is no FZP shuttle installed at the current parkz position.") + # return(0) + # } + # } - def _otransfer_check_sample_available_at_position(self, _osampleposition:int, _picked_it:bool) -> bool: - #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 + # # _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(sprint("XOMNY-SAMPLE_DB_parking:%d.DESC", activeparkingposition)) + # #is there a samle shuttle at this position? + # if(installedshuttle == "OSA") + # { + # #is there a free OSA slot available? + # if (epics_get(sprint("XOMNY-SAMPLE_DB_shuttle_OSA:%d.VAL",(_osampleposition-8)))==0) + # { + # if(_put_it==1) + # { + # samplename = epics_get(sprint("XOMNY-SAMPLE_DB_omny:110.DESC")) + # _otransfer_modify_sample(installedshuttle, (_osampleposition-8), 1, samplename) + # _otransfer_modify_sample("omny",110,0,"-") + # } + # return(1) + # } + # else + # { + # print("There is no free OSA position available.") + # return(0) + # } + # } + # else + # { + # print("There is no OSA shuttle installed at the current parkz position.") + # return(0) + # } + # } - #check that gripper is empty - if dev.omny_samples.is_sample_in_gripper(): - raise OMNYTransferError("There is a sample in the gripper. Aborting.") + # _osampleposition for fixed positions + if ( + (_osampleposition > 9 and _osampleposition < 15) + or (_osampleposition > 31 and _osampleposition < 35) + or _osampleposition == 100 + or _osampleposition == 101 + ): + # is there a free slot available? + if not dev.omny_samples.is_sample_slot_used("O", _osampleposition): + if _put_it: + samplename = dev.omny_samples.get_sample_name_in_gripper() + dev.omny_samples.set_sample_slot("O", _osampleposition, samplename) + dev.omny_samples.unset_sample_in_gripper() + return True + else: + print("There is no free space at this position.") + return False + + # sample stage + elif _osampleposition == 0: + if not dev.omny_samples.is_sample_in_samplestage(): + if _put_it: + samplename = dev.omny_samples.get_sample_name_in_gripper() + dev.omny_samples.set_sample_in_samplestage(samplename) + dev.omny_samples.unset_sample_in_gripper() + return True + else: + print("There is no sample in the sample stage.") + return False - # _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 True - else: - print("There is no sample availabe at that position.") - return False - else: - print("There is no sample shuttle installed at the current parkz position.") return False - # # _osampleposition 7 for FZPs - # if (_osampleposition==7) { - # local activeparkingposition - # local installedshuttle - # activeparkingposition = _oparkz_slot_check() - # if(activeparkingposition==10) - # exit - # installedshuttle = epics_get(sprint("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(sprint("XOMNY-SAMPLE_DB_shuttle_FZP:0.DESC")) - # _otransfer_modify_sample(installedshuttle, 0, 0, "-") - # _otransfer_modify_sample("omny",110,2,samplename) - # } - # return(1) - # } - # else - # { - # print("There is no FZP available.") - # return(0) - # } - # } - # else - # { - # print("There is no FZP shuttle installed at the current parkz position.") - # 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(sprint("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(sprint("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 - # { - # print("There is no OSA available.") - # return(0) - # } - # } - # else - # { - # print("There is no OSA shuttle installed at the current parkz position.") - # 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: - 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 True - else: - print("There is nothing to get from this position.") - return False - #sample stage - elif _osampleposition==0: - if dev.omny_samples.is_sample_in_samplestage(): - if _picked_it: - 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 True - else: - print("There is no sample in the sample stage.") - return False - - - return(0) - - - def _otransfer_check_free_slot_available_at_position(self, _osampleposition:int, _put_it:bool) -> bool: - #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.") - - # this was from early omny when automatic changing of samples, fzps and osas was expected - # the idea was that it is distinguished wich kind of holder is currently in the gripper. turns out not to be needed. - # special transfer is always very manual with a lot of attention. - # - # #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 - # { - # print("There is a sample pin in the gripper, which is not compatible with position %d", _osampleposition) - # exit - # } - # #FZP holder - # if (epics_get("XOMNY-SAMPLE_DB_omny:110.VAL")==2) - # if (_osampleposition == 7 || _osampleposition == 10 || _osampleposition == 11 || _osampleposition == 100) - # { } - # else - # { - # print("There is a FZP holder in the gripper, which is not compatible with position %d", _osampleposition) - # exit - # } - # #OSA holder - # if (epics_get("XOMNY-SAMPLE_DB_omny:110.VAL")==3) - # if (_osampleposition == 8 || _osampleposition == 9 || _osampleposition == 101 ) - # { } - # else - # { - # print("There is an OSA holder in the gripper, which is not compatible with position %d", _osampleposition) - # exit - # } - - - # _osampleposition 1 to 6 are in shuttles - if _osampleposition>0 and _osampleposition<7: - activeparkingposition = self._oparkz_slot_check() - if(activeparkingposition==10): - raise OMNYTransferError("Parking stage is not at an active parking position.") - 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 free position available? - if not dev.omny_samples.is_sample_slot_used(installedshuttle,_osampleposition): - if _put_it: - samplename = dev.omny_samples.get_sample_name_in_gripper() - dev.omny_samples.unset_sample_in_gripper() - dev.omny_samples.set_sample_slot(installedshuttle, _osampleposition, samplename) - return True - else: - print("There is no free sample slot availabe at that position.") - return False - else: - print("There is no sample shuttle installed at the current parkz position.") - return False - - # OSA and FZP section, needs commissioning, was never - # _osampleposition 7 for FZPs - # if _osampleposition==7: - # activeparkingposition = _oparkz_slot_check() - # if(activeparkingposition==10) - # exit - # installedshuttle = epics_get(sprint("XOMNY-SAMPLE_DB_parking:%d.DESC", activeparkingposition)) - # #is there a samle shuttle at this position? - # if(installedshuttle == "FZP") - # { - # #is there a free FZP slot available? - # if (epics_get("XOMNY-SAMPLE_DB_shuttle_FZP:0.VAL")==0) - # { - # if(_put_it==1) - # { - # samplename = epics_get(sprint("XOMNY-SAMPLE_DB_omny:110.DESC")) - # _otransfer_modify_sample(installedshuttle, 0, 1, samplename) - # _otransfer_modify_sample("omny",110,0,"-") - # } - # return(1) - # } - # else - # { - # print("There is no free FZP position available.") - # return(0) - # } - # } - # else - # { - # print("There is no FZP shuttle installed at the current parkz position.") - # 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(sprint("XOMNY-SAMPLE_DB_parking:%d.DESC", activeparkingposition)) - # #is there a samle shuttle at this position? - # if(installedshuttle == "OSA") - # { - # #is there a free OSA slot available? - # if (epics_get(sprint("XOMNY-SAMPLE_DB_shuttle_OSA:%d.VAL",(_osampleposition-8)))==0) - # { - # if(_put_it==1) - # { - # samplename = epics_get(sprint("XOMNY-SAMPLE_DB_omny:110.DESC")) - # _otransfer_modify_sample(installedshuttle, (_osampleposition-8), 1, samplename) - # _otransfer_modify_sample("omny",110,0,"-") - # } - # return(1) - # } - # else - # { - # print("There is no free OSA position available.") - # return(0) - # } - # } - # else - # { - # print("There is no OSA shuttle installed at the current parkz position.") - # return(0) - # } - # } - - # _osampleposition for fixed positions - if (_osampleposition>9 and _osampleposition<15) or (_osampleposition>31 and _osampleposition<35) or _osampleposition == 100 or _osampleposition == 101: - #is there a free slot available? - if not dev.omny_samples.is_sample_slot_used('O',_osampleposition): - if _put_it: - samplename = dev.omny_samples.get_sample_name_in_gripper() - dev.omny_samples.set_sample_slot('O', _osampleposition, samplename) - dev.omny_samples.unset_sample_in_gripper() - return True - else: - print("There is no free space at this position.") - return False - - #sample stage - elif _osampleposition==0: - if not dev.omny_samples.is_sample_in_samplestage(): - if _put_it: - samplename = dev.omny_samples.get_sample_name_in_gripper() - dev.omny_samples.set_sample_in_samplestage(samplename) - dev.omny_samples.unset_sample_in_gripper() - return True - else: - print("There is no sample in the sample stage.") - return False - - return False - - - def otransfer_help(self): - print("omny.otransfer_park_slot(slot) drive the parking station to transfer from with the gripper") - print("omny.otransfer_park_loadlock_slot(slot) drive the parking station to transfer from with the loadlock") - print("omny.otransfer_get_sample(position) pick with the gripper from ") - print("omny.otransfer_put_sample(position) put with the gripper to ") - print("To modify the storage information see dev.omny_samples.help()") - + def otransfer_help(self): + print( + "omny.otransfer_park_slot(slot) drive the parking station to transfer from with the gripper" + ) + print( + "omny.otransfer_park_loadlock_slot(slot) drive the parking station to transfer from with the loadlock" + ) + print("omny.otransfer_get_sample(position) pick with the gripper from ") + print("omny.otransfer_put_sample(position) put with the gripper to ") + print("To modify the storage information see dev.omny_samples.help()") diff --git a/csaxs_bec/bec_ipython_client/plugins/omny/x_ray_eye_align.py b/csaxs_bec/bec_ipython_client/plugins/omny/x_ray_eye_align.py index 22c83fc..ef0222c 100644 --- a/csaxs_bec/bec_ipython_client/plugins/omny/x_ray_eye_align.py +++ b/csaxs_bec/bec_ipython_client/plugins/omny/x_ray_eye_align.py @@ -22,7 +22,7 @@ if TYPE_CHECKING: class XrayEyeAlign: # pixel calibration, multiply to get mm - PIXEL_CALIBRATION = 0.2/218 # .2 with binning + PIXEL_CALIBRATION = 0.2 / 218 # .2 with binning def __init__(self, client, omny: OMNY) -> None: self.client = client