feat: extension for epics motors from xiaoqiang

This commit is contained in:
appel_c 2023-09-06 07:59:51 +02:00
parent 3e594b5e04
commit 057d93ab60

View File

@ -0,0 +1,44 @@
from ophyd import Component as Cpt, EpicsSignal, EpicsMotor
class EpicsMotorEx(EpicsMotor):
"""Extend EpicsMotor with extra configuration fields."""
# configuration
motor_resolution = Cpt(EpicsSignal, ".MRES", kind="config", auto_monitor=True)
base_velocity = Cpt(EpicsSignal, ".VBAS", kind="config", auto_monitor=True)
backlash_distance = Cpt(EpicsSignal, ".BDST", kind="config", auto_monitor=True)
def __init__(
self,
prefix="",
*,
name,
kind=None,
read_attrs=None,
configuration_attrs=None,
parent=None,
**kwargs
):
# get configuration attributes from kwargs and then remove them
attrs = {}
for key, value in kwargs.items():
if hasattr(EpicsMotorEx, key) and isinstance(getattr(EpicsMotorEx, key), Cpt):
attrs[key] = value
for key in attrs:
kwargs.pop(key)
super().__init__(
prefix,
name=name,
kind=kind,
read_attrs=read_attrs,
configuration_attrs=configuration_attrs,
parent=parent,
**kwargs
)
# set configuration attributes
for key, value in attrs.items():
print("setting ", key, "=", value)
getattr(self, key).put(value)