From 266235ae9d1e166b5cda25fbbacae175347a118e Mon Sep 17 00:00:00 2001 From: Roman Mankowsky Date: Tue, 2 Oct 2018 16:25:58 +0200 Subject: [PATCH] adding alias and adjustable conventions, unfinished --- eco/adjustable.py | 34 +++++++++++++ eco/aliases/aliases.py | 12 +++++ eco/devices_general/motors.py | 9 +++- eco/endstations/bernina_xrd_new.py | 82 ++++++++++++++++++++++++++++++ 4 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 eco/adjustable.py create mode 100644 eco/endstations/bernina_xrd_new.py diff --git a/eco/adjustable.py b/eco/adjustable.py new file mode 100644 index 0000000..7ea2816 --- /dev/null +++ b/eco/adjustable.py @@ -0,0 +1,34 @@ + +class Adjustable: + def __init__(self, + f_get_value, + f_change_value, + f_set_value_to=None): + + self._f_get_value = f_get_value + self._f_change_value = f_change_value + self._f_set_value_to = f_set_value_to + + + + + +def wrap_spec_convenience(obj): + # spec-inspired convenience methods + def mv(self,value): + self._currentChange = self.changeTo(value) + def wm(self,*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.changeTo(value+startvalue,*args,**kwargs) + def wait(self): + self._currentChange.wait() + obj.wm = wm + obj.mv = mv + obj.mvr = mvr + obj.wait = wait diff --git a/eco/aliases/aliases.py b/eco/aliases/aliases.py index 81714b7..f0419d1 100644 --- a/eco/aliases/aliases.py +++ b/eco/aliases/aliases.py @@ -32,6 +32,18 @@ class Alias: ta['alias'] = self.alias + ta['alias'] aa.append(ta) + def add_children(self,*args): + self.children.append(find_aliases(args)) + + +def find_aliases(*args): + o = [] + for obj in args: + if hasattr(obj,'alias'): + o.append(obj.alias) + return tuple(o) + + class Namespace: def __init__(self,namespace_file=None): path = Path(namespace_file) diff --git a/eco/devices_general/motors.py b/eco/devices_general/motors.py index cb7f2d9..c77cb1f 100755 --- a/eco/devices_general/motors.py +++ b/eco/devices_general/motors.py @@ -3,6 +3,7 @@ import subprocess from threading import Thread from epics import PV from .utilities import Changer +from ..aliases import Alias _MotorRocordStandardProperties = \ {} @@ -32,11 +33,17 @@ def _keywordChecker(kw_key_list_tups): assert tkey in tlist, "Keyword %s should be one of %s"%(tkw,tlist) class MotorRecord: - def __init__(self,pvname, name=None, elog=None): + def __init__(self,pvname, name=None, elog=None, + alias_fields={ + 'readback'='RBV', + 'user_offset' = 'OFF'}): self.Id = pvname self._motor = _Motor(pvname) self._elog = elog self.name = name + self.alias = Alias(name) + for an,af in alias_fields.items(): + self.alias.add_children(Alias('readback',channel='.'.join(Id,af)) self._currentChange = None diff --git a/eco/endstations/bernina_xrd_new.py b/eco/endstations/bernina_xrd_new.py new file mode 100644 index 0000000..2943b2d --- /dev/null +++ b/eco/endstations/bernina_xrd_new.py @@ -0,0 +1,82 @@ +import sys +sys.path.append("..") +from ..devices_general.motors import MotorRecord +from epics import PV +from ..aliases import Alias + +class XRD: + def __init__(self,name=None,Id=None,configuration=[]): + """X-ray diffractometer platform in AiwssFEL Bernina.\ + : list of elements mounted on + the plaform, options are kappa, nutable, hlgonio, polana""" + self.Id = Id + self.name = name + self.alias = Alias(name) + + + + ### motors heavy load table ### + self.xhl = MotorRecord(Id+':MOT_TBL_TX',name='xhl') + self.zhl = MotorRecord(Id+':MOT_TBL_TZ',name='zhl') + self.yhl = MotorRecord(Id+':MOT_TBL_TY',name='yhl') + try: + self.rxhl = MotorRecord(Id+':MOT_TBL_RX',name='rxhl') + except: + print ('GPS.pitch not found') + pass + try: + self.ryhl = MotorRecord(Id+':MOT_TBL_RY',name='rxhl') + except: + print ('GPS.roll not found') + pass + + ### motors heavy load gonio base ### + self.omega = MotorRecord(Id+':MOT_MY_RYTH',name='omega') + self.tnu = MotorRecord(Id+':MOT_HEX_TX',name='tnu') + self.nu = MotorRecord(Id+':MOT_HEX_RX',name='nu') + self.gamma = MotorRecord(Id+':MOT_NY_RY2TH', name='gam') + self.delta = MotorRecord(Id+':MOT_DT_RX2TH', name='del') + self.xbase = MotorRecord(Id+':MOT_TX') + self.ybase = MotorRecord(Id+':MOT_TY') + + ### motors XRD arm ### + self.tdet = MotorRecord(Id+':MOT_D_T') + self.tpol = MotorRecord(Id+':MOT_P_T') + + + self.hex_x = PV("SARES20-HEX_PI:POSI-X") + self.hex_y = PV("SARES20-HEX_PI:POSI-Y") + self.hex_z = PV("SARES20-HEX_PI:POSI-Z") + self.hex_u = PV("SARES20-HEX_PI:POSI-U") + self.hex_v = PV("SARES20-HEX_PI:POSI-V") + self.hex_w = PV("SARES20-HEX_PI:POSI-W") + + + + + + + def __repr__(self): + s = "**Heavy Load**\n" + motors = "xmu mu tth xbase ybase".split() + for motor in motors: + s+= " - %s %.4f\n"%(motor,getattr(self,motor).wm()) + + s+= " - xhl %.4f\n"%(self.xhl.wm()) + s+= " - yhl %.4f\n"%(self.yhl.wm()) + s+= " - zhl %.4f\n"%(self.zhl.wm()) + s+= " - th %.4f\n"%(self.th.wm()) + s+= "\n" + + s+= "**Gonio**\n" + motors = "xmu mu tth delta det_z cam_z xbase ybase".split() + for motor in motors: + s+= " - %s %.4f\n"%(motor,getattr(self,motor).wm()) + s+= "\n" + + s+= "**Hexapod**\n" + motors = "x y z u v w".split() + for motor in motors: + s+= " - hex_%s %.4f\n"%(motor,getattr(self,"hex_"+motor).get()) + return s +