diff --git a/eco/bernina/__init__.py b/eco/bernina/__init__.py index 35f54c8..5c6d740 100644 --- a/eco/bernina/__init__.py +++ b/eco/bernina/__init__.py @@ -6,8 +6,9 @@ import logging from .config import components, config import sys -from .bernina import * + try: + from .bernina import * from ..utilities.runtable import Run_Table except: print('Initializing of run_table failed') diff --git a/eco/bernina/config.py b/eco/bernina/config.py index 311199a..cd16e50 100755 --- a/eco/bernina/config.py +++ b/eco/bernina/config.py @@ -56,7 +56,7 @@ components = [ "name": "archiver", "desc": "SwisFEL archiver data_buffer", "type": "eco.dbase.archiver:DataApi", - "kwargs": {"pv_pulse_id":"SLAAR21-LTIM01-EVR0:RX-PULSEID"}, + "kwargs": {"pv_pulse_id": "SLAAR21-LTIM01-EVR0:RX-PULSEID"}, }, { "name": "slit_und", @@ -226,7 +226,7 @@ components = [ { "name": "att", "args": ["SAROP21-OATT135"], - "kwargs": {"shutter": Component("xp"),'set_limits':[]}, + "kwargs": {"shutter": Component("xp"), "set_limits": []}, "z_und": 135, "desc": "Attenuator Bernina", "type": "eco.xoptics.attenuator_aramis:AttenuatorAramis", @@ -312,8 +312,12 @@ components = [ "z_und": 142, "desc": "General purpose station", "type": "eco.endstations.bernina_diffractometers:GPS", - "kwargs": {"Id": "SARES22-GPS", "configuration": config["gps_config"],"fina_hex_angle_offset":"~/eco/reference_values/hex_pi_angle_offset.json"}, - "lazy":False, + "kwargs": { + "Id": "SARES22-GPS", + "configuration": config["gps_config"], + "fina_hex_angle_offset": "~/eco/reference_values/hex_pi_angle_offset.json", + }, + "lazy": False, }, { "args": [], @@ -497,7 +501,10 @@ components = [ "name": "event_system", "desc": "SwissFEL timing information", "type": "eco.timing.event_timing_new:TimingSystem", - "kwargs": {"pv_master":"SIN-TIMAST-TMA","pv_pulse_id":"SLAAR21-LTIM01-EVR0:RX-PULSEID"}, + "kwargs": { + "pv_master": "SIN-TIMAST-TMA", + "pv_pulse_id": "SLAAR21-LTIM01-EVR0:RX-PULSEID", + }, }, { "args": ["SIN-TIMAST-TMA"], @@ -563,7 +570,7 @@ components = [ "z_und": 141, "desc": "Upstream diagnostics table", "type": "eco.endstations.hexapod:HexapodSymmetrie", - "kwargs": {'offset':[0.,0.,0.,0.,0.,0.]}, + "kwargs": {"offset": [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]}, "lazy": True, }, { @@ -572,7 +579,11 @@ components = [ "z_und": 141, "desc": "", "type": "eco.xoptics.kb_bernina:KBMirrorBernina", - "kwargs": {'kb_ver':Component('kb_ver'),'kb_hor':Component('kb_hor'),'usd_table':Component('usd_table')}, + "kwargs": { + "kb_ver": Component("kb_ver"), + "kb_hor": Component("kb_hor"), + "usd_table": Component("usd_table"), + }, "lazy": True, }, { @@ -617,7 +628,6 @@ components = [ "kwargs": {"Id": "SARES23"}, "lazy": True, }, - { "args": [], "name": "tht", @@ -627,7 +637,6 @@ components = [ "kwargs": {"Id": "SARES23"}, "lazy": True, }, - { "args": [], "name": "eos", diff --git a/eco/dbase/archiver.py b/eco/dbase/archiver.py index 2fe2d54..dd9f07c 100644 --- a/eco/dbase/archiver.py +++ b/eco/dbase/archiver.py @@ -6,57 +6,57 @@ from numbers import Number from matplotlib import pyplot as plt import numpy as np + class DataApi: - def __init__(self,pv_pulse_id=None,name=None): + def __init__(self, pv_pulse_id=None, name=None): self.name = name if pv_pulse_id: - self.pulse_id = PvDataStream(pv_pulse_id,name='pulse_id') + self.pulse_id = PvDataStream(pv_pulse_id, name="pulse_id") - def get_data_time_range(self,channels=[],start=None,end=None,plot=False): + def get_data_time_range(self, channels=[], start=None, end=None, plot=False): if not end: end = datetime.datetime.now() - if isinstance(start,datetime.timedelta): - start = end+start - elif isinstance(start,dict): + if isinstance(start, datetime.timedelta): + start = end + start + elif isinstance(start, dict): start = datetime.timedelta(**start) - start = end+start - elif isinstance(start,Number): + start = end + start + elif isinstance(start, Number): start = datetime.timedelta(seconds=start) - start = end+start + start = end + start - data = get_data(channels,start=start,end=end,range_type='time') + data = get_data(channels, start=start, end=end, range_type="time") if plot: ah = plt.gca() for chan in channels: sel = ~np.isnan(data[chan]) x = data.index[sel] y = data[chan][sel] - ah.step(x,y,'.-',label=chan,where='post') + ah.step(x, y, ".-", label=chan, where="post") plt.xticks(rotation=30) plt.legend() plt.tight_layout() plt.xlabel(data.index.name) return data - - def get_data_pulse_id_range(self,channels=[],start=None,end=None,plot=False): + + def get_data_pulse_id_range(self, channels=[], start=None, end=None, plot=False): if not end: - if hasattr(self,"pulse_id"): + if hasattr(self, "pulse_id"): end = int(self.pulse_id.get_current_value()) else: raise Exception("no end pulse id provided") - start = start+end - data = get_data(channels,start=start,end=end,range_type='pulseId') + start = start + end + data = get_data(channels, start=start, end=end, range_type="pulseId") if plot: ah = plt.gca() for chan in channels: sel = ~np.isnan(data[chan]) x = data.index[sel] y = data[chan][sel] - ah.plot(x,y,'.-',label=chan,where='post') + ah.plot(x, y, ".-", label=chan, where="post") return data - def search(self,searchstring): + def search(self, searchstring): """ A search in database using simpler unix glob expressions (e.g. '*ARES*')""" return search(translate(searchstring)) - diff --git a/eco/devices_general/adjustable.py b/eco/devices_general/adjustable.py index aaaf03f..c33efec 100644 --- a/eco/devices_general/adjustable.py +++ b/eco/devices_general/adjustable.py @@ -23,14 +23,14 @@ class AdjustableError(Exception): # wrappers for adjustables >>>>>>>>>>> def default_representation(Obj): def get_name(Obj): - if hasattr(Obj,'alias') and Obj.alias: + if hasattr(Obj, "alias") and Obj.alias: return Obj.alias.get_full_name() elif Obj.name: return Obj.name - elif hasattr(Obj,'Id') and Obj.Id: + elif hasattr(Obj, "Id") and Obj.Id: return Obj.Id else: - return '' + return "" def get_repr(Obj): s = datetime.datetime.now().strftime("%Y/%m/%d %H:%M:%S") + ": " @@ -259,29 +259,33 @@ def _keywordChecker(kw_key_list_tups): for tkw, tkey, tlist in kw_key_list_tups: assert tkey in tlist, "Keyword %s should be one of %s" % (tkw, tlist) + @default_representation @spec_convenience class AdjustableFS: - def __init__(self,file_path,name=None): + def __init__(self, file_path, name=None): self.file_path = Path(file_path) self.name = name def get_current_value(self): - with open(self.file_path,'r') as f: + with open(self.file_path, "r") as f: res = load(f) - return res['value'] + return res["value"] - def _write_value(self,value): - with open(self.file_path,'w') as f: - dump({'value':value},f) + def _write_value(self, value): + with open(self.file_path, "w") as f: + dump({"value": value}, f) - def set_target_value(self,value,hold=False): + def set_target_value(self, value, hold=False): return Changer( - target=value, parent=self, changer=self._write_value, hold=hold, stopper=None + target=value, + parent=self, + changer=self._write_value, + hold=hold, + stopper=None, ) - @spec_convenience class PvRecord: def __init__( @@ -345,21 +349,21 @@ class PvRecord: # spec-inspired convenience methods # def mv(self, value): - # self._currentChange = self.set_target_value(value) + # self._currentChange = self.set_target_value(value) # def wm(self, *args, **kwargs): - # return self.get_current_value(*args, **kwargs) + # return self.get_current_value(*args, **kwargs) # def mvr(self, value, *args, **kwargs): - # if self.get_moveDone == 1: - # startvalue = self.get_current_value(readback=True, *args, **kwargs) - # else: - # startvalue = self.get_current_value(readback=False, *args, **kwargs) - # self._currentChange = self.set_target_value(value + startvalue, *args, **kwargs) + # if self.get_moveDone == 1: + # startvalue = self.get_current_value(readback=True, *args, **kwargs) + # else: + # startvalue = self.get_current_value(readback=False, *args, **kwargs) + # self._currentChange = self.set_target_value(value + startvalue, *args, **kwargs) # def wait(self): - # self._currentChange.wait() + # self._currentChange.wait() def __repr__(self): return "%s is at: %s" % (self.Id, self.get_current_value()) diff --git a/eco/devices_general/detectors.py b/eco/devices_general/detectors.py index 5efb82a..dd30bb2 100755 --- a/eco/devices_general/detectors.py +++ b/eco/devices_general/detectors.py @@ -16,7 +16,6 @@ from ..acquisition.utilities import Acquisition from ..aliases import Alias - class PvDataStream: def __init__(self, Id, name=None): self.Id = Id diff --git a/eco/devices_general/motors.py b/eco/devices_general/motors.py index fa73707..6662612 100755 --- a/eco/devices_general/motors.py +++ b/eco/devices_general/motors.py @@ -10,6 +10,18 @@ from .adjustable import spec_convenience, ValueInRange, update_changes, Adjustab import colorama from ..utilities.KeyPress import KeyPress import sys, colorama +from .. import global_config + +if hasattr(global_config, "elog"): + elog = global_config.elog +else: + elog = None + +if hasattr(global_config, "archiver"): + archiver = global_config.archiver +else: + archiver = None + _MotorRocordStandardProperties = {} _posTypes = ["user", "dial", "raw"] diff --git a/eco/endstations/bernina_diffractometers.py b/eco/endstations/bernina_diffractometers.py index a73d301..1fd2a83 100644 --- a/eco/endstations/bernina_diffractometers.py +++ b/eco/endstations/bernina_diffractometers.py @@ -20,7 +20,12 @@ def addMotorRecordToSelf(self, name=None, Id=None): class GPS: def __init__( - self, name=None, Id=None, configuration=["base"], alias_namespace=None, fina_hex_angle_offset=None + self, + name=None, + Id=None, + configuration=["base"], + alias_namespace=None, + fina_hex_angle_offset=None, ): self.Id = Id self.name = name @@ -53,7 +58,7 @@ class GPS: HexapodPI, "SARES20-HEX_PI", name="hex", - fina_angle_offset = fina_hex_angle_offset + fina_angle_offset=fina_hex_angle_offset, ) if "hlxz" in self.configuration: diff --git a/eco/endstations/bernina_sample_environments.py b/eco/endstations/bernina_sample_environments.py index ac7b46f..1016182 100644 --- a/eco/endstations/bernina_sample_environments.py +++ b/eco/endstations/bernina_sample_environments.py @@ -134,9 +134,6 @@ class High_field_thz_chamber: return self.get_adjustable_positions_str() - - - class High_field_thz_table: def __init__(self, name=None, Id=None, alias_namespace=None): self.Id = Id @@ -184,7 +181,6 @@ class High_field_thz_table: "speed": 250, "home_direction": "back", }, - "mirr1_x": { "id": "-ESB7", "pv_descr": "Motor5:1 near IR mirror x", @@ -273,9 +269,6 @@ class High_field_thz_table: return self.get_adjustable_positions_str() - - - class electro_optic_sampling: def __init__(self, name=None, Id=None, alias_namespace=None): self.Id = Id @@ -292,16 +285,16 @@ class electro_optic_sampling: "home_direction": "back", }, "rx": { - "id": "-ESB17", - "pv_descr": "Motor8:2 EOS prism rx ", + "id": "-LIC11", + "pv_descr": "Motor6:2 EOS prism rx ", "type": 1, "sensor": 0, "speed": 250, "home_direction": "back", }, "x": { - "id": "-ESB18", - "pv_descr": "Motor8:3 EOS prism x ", + "id": "-LIC10", + "pv_descr": "Motor6:1 EOS prism x ", "type": 1, "sensor": 0, "speed": 250, diff --git a/eco/endstations/hexapod.py b/eco/endstations/hexapod.py index 4402a92..c4937de 100644 --- a/eco/endstations/hexapod.py +++ b/eco/endstations/hexapod.py @@ -1,10 +1,16 @@ from epics import PV -from ..devices_general.adjustable import PvEnum,PvRecord,AdjustableFS,AdjustableVirtual +from ..devices_general.adjustable import ( + PvEnum, + PvRecord, + AdjustableFS, + AdjustableVirtual, +) from time import sleep -from ..aliases import append_object_to_object,Alias +from ..aliases import append_object_to_object, Alias from scipy.spatial.transform import Rotation import datetime + class Hexapod_PI: def __init__(self, Id): self.Id = Id @@ -21,70 +27,164 @@ class Hexapod_PI: for i in "RST" ] + class HexapodPI: - def __init__(self,pvname,name=None,fina_angle_offset=None): + def __init__(self, pvname, name=None, fina_angle_offset=None): self.name = name self.alias = Alias(name) self.pvname = pvname - append_object_to_object(self,PvRecord,self.pvname+':SET-POSI-X',pvreadbackname=self.pvname+':POSI-X',accuracy=.001,name='x_raw') - append_object_to_object(self,PvRecord,self.pvname+':SET-POSI-Y',pvreadbackname=self.pvname+':POSI-Y',accuracy=.001,name='y_raw') - append_object_to_object(self,PvRecord,self.pvname+':SET-POSI-Z',pvreadbackname=self.pvname+':POSI-Z',accuracy=.001,name='z_raw') - append_object_to_object(self,PvRecord,self.pvname+':SET-POSI-U',pvreadbackname=self.pvname+':POSI-U',accuracy=.001,name='rx_raw') - append_object_to_object(self,PvRecord,self.pvname+':SET-POSI-V',pvreadbackname=self.pvname+':POSI-V',accuracy=.001,name='ry_raw') - append_object_to_object(self,PvRecord,self.pvname+':SET-POSI-W',pvreadbackname=self.pvname+':POSI-W',accuracy=.001,name='rz_raw') - append_object_to_object(self,PvRecord,self.pvname+':SET-PIVOT-R',pvreadbackname=self.pvname+':PIVOT-R',accuracy=.001,name='pivot_x') - append_object_to_object(self,PvRecord,self.pvname+':SET-PIVOT-S',pvreadbackname=self.pvname+':PIVOT-S',accuracy=.001,name='pivot_y') - append_object_to_object(self,PvRecord,self.pvname+':SET-PIVOT-T',pvreadbackname=self.pvname+':PIVOT-T',accuracy=.001,name='pivot_z') + append_object_to_object( + self, + PvRecord, + self.pvname + ":SET-POSI-X", + pvreadbackname=self.pvname + ":POSI-X", + accuracy=0.001, + name="x_raw", + ) + append_object_to_object( + self, + PvRecord, + self.pvname + ":SET-POSI-Y", + pvreadbackname=self.pvname + ":POSI-Y", + accuracy=0.001, + name="y_raw", + ) + append_object_to_object( + self, + PvRecord, + self.pvname + ":SET-POSI-Z", + pvreadbackname=self.pvname + ":POSI-Z", + accuracy=0.001, + name="z_raw", + ) + append_object_to_object( + self, + PvRecord, + self.pvname + ":SET-POSI-U", + pvreadbackname=self.pvname + ":POSI-U", + accuracy=0.001, + name="rx_raw", + ) + append_object_to_object( + self, + PvRecord, + self.pvname + ":SET-POSI-V", + pvreadbackname=self.pvname + ":POSI-V", + accuracy=0.001, + name="ry_raw", + ) + append_object_to_object( + self, + PvRecord, + self.pvname + ":SET-POSI-W", + pvreadbackname=self.pvname + ":POSI-W", + accuracy=0.001, + name="rz_raw", + ) + append_object_to_object( + self, + PvRecord, + self.pvname + ":SET-PIVOT-R", + pvreadbackname=self.pvname + ":PIVOT-R", + accuracy=0.001, + name="pivot_x", + ) + append_object_to_object( + self, + PvRecord, + self.pvname + ":SET-PIVOT-S", + pvreadbackname=self.pvname + ":PIVOT-S", + accuracy=0.001, + name="pivot_y", + ) + append_object_to_object( + self, + PvRecord, + self.pvname + ":SET-PIVOT-T", + pvreadbackname=self.pvname + ":PIVOT-T", + accuracy=0.001, + name="pivot_z", + ) if fina_angle_offset: self.ref_frame_angle = AdjustableFS(fina_angle_offset) self.x = AdjustableVirtual( - [self.x_raw,self.y_raw,self.z_raw], - lambda xraw,yraw,zraw: self._calc_xyz(xraw,yraw,zraw)[0], - lambda x:self._calc_xyzraw(x,self.y.get_current_value(),self.z.get_current_value()), - reset_current_value_to=False, - append_aliases=False, - change_simultaneously=False, - name='x', - ) + [self.x_raw, self.y_raw, self.z_raw], + lambda xraw, yraw, zraw: self._calc_xyz(xraw, yraw, zraw)[0], + lambda x: self._calc_xyzraw( + x, self.y.get_current_value(), self.z.get_current_value() + ), + reset_current_value_to=False, + append_aliases=False, + change_simultaneously=False, + name="x", + ) self.y = AdjustableVirtual( - [self.x_raw,self.y_raw,self.z_raw], - lambda xraw,yraw,zraw: self._calc_xyz(xraw,yraw,zraw)[1], - lambda y:self._calc_xyzraw(self.x.get_current_value(),y,self.z.get_current_value()), - reset_current_value_to=False, - change_simultaneously=False, - append_aliases=False, - name='y', - ) + [self.x_raw, self.y_raw, self.z_raw], + lambda xraw, yraw, zraw: self._calc_xyz(xraw, yraw, zraw)[1], + lambda y: self._calc_xyzraw( + self.x.get_current_value(), y, self.z.get_current_value() + ), + reset_current_value_to=False, + change_simultaneously=False, + append_aliases=False, + name="y", + ) self.z = AdjustableVirtual( - [self.x_raw,self.y_raw,self.z_raw], - lambda xraw,yraw,zraw: self._calc_xyz(xraw,yraw,zraw)[2], - lambda z: self._calc_xyzraw(self.x.get_current_value(),self.y.get_current_value(),z), - reset_current_value_to=False, - append_aliases=False, - change_simultaneously=False, - name='z', - ) - @property + [self.x_raw, self.y_raw, self.z_raw], + lambda xraw, yraw, zraw: self._calc_xyz(xraw, yraw, zraw)[2], + lambda z: self._calc_xyzraw( + self.x.get_current_value(), self.y.get_current_value(), z + ), + reset_current_value_to=False, + append_aliases=False, + change_simultaneously=False, + name="z", + ) + + @property def rotation(self): angs = self.ref_frame_angle.get_current_value() - angs = [angs['rx'],angs['ry'],angs['rz']] - return Rotation.from_euler('xyz',angs,degrees=True) + angs = [angs["rx"], angs["ry"], angs["rz"]] + return Rotation.from_euler("xyz", angs, degrees=True) - def _calc_xyz(self,xraw,yraw,zraw): - return self.rotation.apply([xraw,yraw,zraw]) - - def _calc_xyzraw(self,x,y,z): - print(self.rotation.inv().apply([x,y,z])) - return self.rotation.inv().apply([x,y,z]) + def _calc_xyz(self, xraw, yraw, zraw): + return self.rotation.apply([xraw, yraw, zraw]) + + def _calc_xyzraw(self, x, y, z): + print(self.rotation.inv().apply([x, y, z])) + return self.rotation.inv().apply([x, y, z]) def get_status(self): s = f'Hexapod {self.alias.get_full_name()} status ({datetime.datetime.now().strftime("%Y/%m/%d %H:%M:%S")})\n' - if hasattr(self,'ref_frame_angle'): - for var in ['x','y','z']: - s+=(' '*4+var.ljust(16)+f'{self.__dict__[var].get_current_value():g}\n') - s+= ' '*4+'ref_frame_angle'.ljust(16)+str(self.ref_frame_angle.get_current_value())+'\n' - for var in ['x_raw','y_raw','z_raw','rx_raw','ry_raw','rz_raw','pivot_x','pivot_y','pivot_z']: - s+=(' '*4+var.ljust(16)+f'{self.__dict__[var].get_current_value():g}\n') + if hasattr(self, "ref_frame_angle"): + for var in ["x", "y", "z"]: + s += ( + " " * 4 + + var.ljust(16) + + f"{self.__dict__[var].get_current_value():g}\n" + ) + s += ( + " " * 4 + + "ref_frame_angle".ljust(16) + + str(self.ref_frame_angle.get_current_value()) + + "\n" + ) + for var in [ + "x_raw", + "y_raw", + "z_raw", + "rx_raw", + "ry_raw", + "rz_raw", + "pivot_x", + "pivot_y", + "pivot_z", + ]: + s += ( + " " * 4 + + var.ljust(16) + + f"{self.__dict__[var].get_current_value():g}\n" + ) return s def __str__(self): @@ -93,63 +193,65 @@ class HexapodPI: def __repr__(self): return self.__str__() - - class HexapodSymmetrie: - def __init__(self,pv_master='SARES20-HEXSYM',name='hex_usd',offset=[0,0,0,0,0,0]): + def __init__( + self, pv_master="SARES20-HEXSYM", name="hex_usd", offset=[0, 0, 0, 0, 0, 0] + ): self.name = name self.offset = offset self.pvname = pv_master - self.coordinate_switch = PvEnum(f'{self.pvname}:MOVE#PARAM:CM',name='hex_usd_coordinate_switch') + self.coordinate_switch = PvEnum( + f"{self.pvname}:MOVE#PARAM:CM", name="hex_usd_coordinate_switch" + ) self.pvs_setpos = { - 'x':PV(f'{self.pvname}:MOVE#PARAM:X.VAL'), - 'y':PV(f'{self.pvname}:MOVE#PARAM:Y.VAL'), - 'z':PV(f'{self.pvname}:MOVE#PARAM:Z.VAL'), - 'rx':PV(f'{self.pvname}:MOVE#PARAM:RX.VAL'), - 'ry':PV(f'{self.pvname}:MOVE#PARAM:RY.VAL'), - 'rz':PV(f'{self.pvname}:MOVE#PARAM:RZ.VAL'), - } + "x": PV(f"{self.pvname}:MOVE#PARAM:X.VAL"), + "y": PV(f"{self.pvname}:MOVE#PARAM:Y.VAL"), + "z": PV(f"{self.pvname}:MOVE#PARAM:Z.VAL"), + "rx": PV(f"{self.pvname}:MOVE#PARAM:RX.VAL"), + "ry": PV(f"{self.pvname}:MOVE#PARAM:RY.VAL"), + "rz": PV(f"{self.pvname}:MOVE#PARAM:RZ.VAL"), + } self.pvs_getpos = { - 'x':PV(f'{self.pvname}:POSMACH:X'), - 'y':PV(f'{self.pvname}:POSMACH:Y'), - 'z':PV(f'{self.pvname}:POSMACH:Z'), - 'rx':PV(f'{self.pvname}:POSMACH:RX'), - 'ry':PV(f'{self.pvname}:POSMACH:RY'), - 'rz':PV(f'{self.pvname}:POSMACH:RZ'), - } - self._ctrl_pv = PV(f'{self.pvname}:STATE#PANEL:SET.VAL') + "x": PV(f"{self.pvname}:POSMACH:X"), + "y": PV(f"{self.pvname}:POSMACH:Y"), + "z": PV(f"{self.pvname}:POSMACH:Z"), + "rx": PV(f"{self.pvname}:POSMACH:RX"), + "ry": PV(f"{self.pvname}:POSMACH:RY"), + "rz": PV(f"{self.pvname}:POSMACH:RZ"), + } + self._ctrl_pv = PV(f"{self.pvname}:STATE#PANEL:SET.VAL") - def set_coordinates(self,x,y,z,rx,ry,rz,relative_to_eco_offset=True): + def set_coordinates(self, x, y, z, rx, ry, rz, relative_to_eco_offset=True): if relative_to_eco_offset: - x = x+self.offset[0] - y = y+self.offset[1] - z = z+self.offset[2] - rx = rx+self.offset[3] - ry = ry+self.offset[4] - rz = rz+self.offset[5] - self.pvs_setpos['x'].put(x) - self.pvs_setpos['y'].put(y) - self.pvs_setpos['z'].put(z) - self.pvs_setpos['rx'].put(rx) - self.pvs_setpos['ry'].put(ry) - self.pvs_setpos['rz'].put(rz) - - def get_coordinates(self,relative_to_eco_offset=True): - x = self.pvs_getpos['x'].get() - y = self.pvs_getpos['y'].get() - z = self.pvs_getpos['z'].get() - rx = self.pvs_getpos['rx'].get() - ry = self.pvs_getpos['ry'].get() - rz = self.pvs_getpos['rz'].get() + x = x + self.offset[0] + y = y + self.offset[1] + z = z + self.offset[2] + rx = rx + self.offset[3] + ry = ry + self.offset[4] + rz = rz + self.offset[5] + self.pvs_setpos["x"].put(x) + self.pvs_setpos["y"].put(y) + self.pvs_setpos["z"].put(z) + self.pvs_setpos["rx"].put(rx) + self.pvs_setpos["ry"].put(ry) + self.pvs_setpos["rz"].put(rz) + + def get_coordinates(self, relative_to_eco_offset=True): + x = self.pvs_getpos["x"].get() + y = self.pvs_getpos["y"].get() + z = self.pvs_getpos["z"].get() + rx = self.pvs_getpos["rx"].get() + ry = self.pvs_getpos["ry"].get() + rz = self.pvs_getpos["rz"].get() if relative_to_eco_offset: - x = x-self.offset[0] - y = y-self.offset[1] - z = z-self.offset[2] - rx = rx-self.offset[3] - ry = ry-self.offset[4] - rz = rz-self.offset[5] - return x,y,z,rx,ry,rz + x = x - self.offset[0] + y = y - self.offset[1] + z = z - self.offset[2] + rx = rx - self.offset[3] + ry = ry - self.offset[4] + rz = rz - self.offset[5] + return x, y, z, rx, ry, rz def set_control_on(self): self._ctrl_pv.put(3) @@ -159,43 +261,72 @@ class HexapodSymmetrie: def get_control_state(self): stat = self._ctrl_pv.get() - if stat==3: - return 'control on' - elif stat==4: - return 'control on' - elif stat==2: - return 'stopped' - elif stat==11: - return 'moving' + if stat == 3: + return "control on" + elif stat == 4: + return "control on" + elif stat == 2: + return "stopped" + elif stat == 11: + return "moving" - def move_to_coordinates(self,x,y,z,rx,ry,rz,precision=[.001,.001,.001,.001,.001,.001],coordinate_type='absolute',relative_to_eco_offset=True): + def move_to_coordinates( + self, + x, + y, + z, + rx, + ry, + rz, + precision=[0.001, 0.001, 0.001, 0.001, 0.001, 0.001], + coordinate_type="absolute", + relative_to_eco_offset=True, + ): self.coordinate_switch.set_target_value(coordinate_type).wait() - self.set_coordinates(x,y,z,rx,ry,rz,relative_to_eco_offset=relative_to_eco_offset) - sleep(.1) - self.start_move(target=(x,y,z,rx,ry,rz),precision=precision,coordinate_type=coordinate_type) + self.set_coordinates( + x, y, z, rx, ry, rz, relative_to_eco_offset=relative_to_eco_offset + ) + sleep(0.1) + self.start_move( + target=(x, y, z, rx, ry, rz), + precision=precision, + coordinate_type=coordinate_type, + ) - def start_move(self,target=None,precision=[.001,.001,.001,.001,.001,.001],coordinate_type='absolute',relative_to_eco_offset=True): - print('Starting to move... stop with Ctrl-C') + def start_move( + self, + target=None, + precision=[0.001, 0.001, 0.001, 0.001, 0.001, 0.001], + coordinate_type="absolute", + relative_to_eco_offset=True, + ): + print("Starting to move... stop with Ctrl-C") self.set_control_on() sleep(0.2) - self._ctrl_pv.put(11) #this starts moving! + self._ctrl_pv.put(11) # this starts moving! while 1: try: if target: - coo = self.get_coordinates(relative_to_eco_offset=relative_to_eco_offset) - if all([abs(ctarg-cnow)