Skip to content

Commit

Permalink
Merge pull request #1104 from lnls-sirius/add-iuv-ids
Browse files Browse the repository at this point in the history
Add Long Coil (LC) correctors in IDFF
  • Loading branch information
xresende authored Oct 8, 2024
2 parents 929a636 + 63fa41f commit 5dbe45f
Show file tree
Hide file tree
Showing 6 changed files with 255 additions and 65 deletions.
30 changes: 21 additions & 9 deletions siriuspy/siriuspy/devices/idff.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
"""Insertion Device Feedforward Devices."""

from ..idff.config import IDFFConfig as _IDFFConfig
from ..namesys import SiriusPVName as _SiriusPVName
from ..search import IDSearch as _IDSearch
from ..idff.config import IDFFConfig as _IDFFConfig

from .device import Device as _Device, DeviceSet as _DeviceSet
from .pwrsupply import PowerSupplyFBP as _PowerSupplyFBP
from .device import DeviceSet as _DeviceSet
from .ids import ID as _ID
from .pwrsupply import PowerSupplyFBP as _PowerSupplyFBP


class IDFF(_DeviceSet):
Expand All @@ -31,8 +30,8 @@ def __init__(self, devname):
self._kparametername = \
_IDSearch.conv_idname_2_kparameter_propty(devname)

self._devid, self._devsch, self._devscv, self._devsqs = \
self._create_devices(devname)
(self._devid, self._devsch, self._devscv,
self._devsqs, self._devslc) = self._create_devices(devname)

devices = [self._devid, ]
devices += self._devsch
Expand All @@ -55,6 +54,11 @@ def qsnames(self):
"""Return QS corrector power supply names."""
return _IDSearch.conv_idname_2_idff_qsnames(self.devname)

@property
def lcnames(self):
"""Return LC corrector power supply names."""
return _IDSearch.conv_idname_2_idff_lcnames(self.devname)

@property
def iddev(self):
"""Return ID device."""
Expand All @@ -75,6 +79,11 @@ def qsdevs(self):
"""Return QS corrector power supply names."""
return self._devsqs

@property
def lcdevs(self):
"""Return LC corrector power supply names."""
return self._devslc

@property
def pparametername(self):
"""Return corresponding to ID pparameter."""
Expand Down Expand Up @@ -158,7 +167,8 @@ def implement_setpoints(
else:
polarization, pparameter_value, kparameter_value = [None, ] * 3
if corrdevs is None:
corrdevs = self._devsch + self._devscv + self._devsqs
corrdevs = \
self._devsch + self._devscv + self._devsqs + self._devslc
for pvname, value in setpoints.items():
# find corrdev corresponding to pvname
for dev in corrdevs:
Expand All @@ -181,7 +191,8 @@ def check_valid_value(self, value):

# check pvnames in configs
pvsconfig = set(pvnames.values())
pvsidsearch = set(self.chnames + self.cvnames + self.qsnames)
pvsidsearch = set(
self.chnames + self.cvnames + self.qsnames + self.lcnames)
symm_diff = pvsconfig ^ pvsidsearch
if symm_diff:
raise ValueError('List of pvnames in config is not consistent')
Expand Down Expand Up @@ -258,4 +269,5 @@ def _create_devices(self, devname):
devsch = [_PowerSupplyFBP(devname=dev) for dev in self.chnames]
devscv = [_PowerSupplyFBP(devname=dev) for dev in self.cvnames]
devsqs = [_PowerSupplyFBP(devname=dev) for dev in self.qsnames]
return devid, devsch, devscv, devsqs
devslc = [_PowerSupplyFBP(devname=dev) for dev in self.lcnames]
return devid, devsch, devscv, devsqs, devslc
121 changes: 99 additions & 22 deletions siriuspy/siriuspy/devices/ids.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
"""Insertion Devices."""

import time as _time
import inspect as _inspect
import time as _time

import numpy as _np

from ..search import IDSearch as _IDSearch

from .device import Device as _Device


class _PARAM_PVS:
class _ParamPVs:
"""."""

# --- GENERAL ---
Expand Down Expand Up @@ -79,10 +79,11 @@ class IDBase(_Device):
_SHORT_SHUT_EYE = 0.1 # [s]
_DEF_TIMEOUT = 8 # [s]

PARAM_PVS = _PARAM_PVS()
PARAM_PVS = _ParamPVs()

PROPERTIES_DEFAULT = \
tuple(set(value for key, value in _inspect.getmembers(PARAM_PVS) \
tuple(set(
value for key, value in _inspect.getmembers(PARAM_PVS)
if not key.startswith('_') and value is not None))

def __init__(self, devname, props2init='all', auto_monitor_mon=True):
Expand Down Expand Up @@ -454,6 +455,7 @@ def cmd_beamline_ctrl_disable(self, timeout=None):

def wait_while_busy(self, timeout=None):
"""Command wait within timeout while ID control is busy."""
_ = timeout
return True

def wait_move_start(self, timeout=None):
Expand Down Expand Up @@ -766,7 +768,7 @@ class DEVICES:
_CMD_MOVE = 3

# --- PARAM_PVS ---
PARAM_PVS = _PARAM_PVS()
PARAM_PVS = _ParamPVs()
PARAM_PVS.KPARAM_SP = 'Phase-SP'
PARAM_PVS.KPARAM_RB = 'Phase-SP' # There is no Phase-RB!
PARAM_PVS.KPARAM_MON = 'Phase-Mon'
Expand All @@ -778,7 +780,8 @@ class DEVICES:
PARAM_PVS.KPARAM_CHANGE_CMD = 'DevCtrl-Cmd'

PROPERTIES_DEFAULT = \
tuple(set(value for key, value in _inspect.getmembers(PARAM_PVS) \
tuple(set(
value for key, value in _inspect.getmembers(PARAM_PVS)
if not key.startswith('_') and value is not None))

def __init__(self, devname, props2init='all', auto_monitor_mon=True):
Expand Down Expand Up @@ -853,6 +856,7 @@ def set_phase_speed_max(self, phase_speed_max, timeout=None):

def cmd_move_stop(self, timeout=None):
"""Send command to stop ID movement."""
_ = timeout
self['DevCtrl-Cmd'] = self._CMD_MOVE_STOP
return True

Expand All @@ -878,7 +882,7 @@ class DEVICES:
ALL = (PAPU50_17SA, )

# --- PARAM_PVS ---
PARAM_PVS = _PARAM_PVS()
PARAM_PVS = _ParamPVs()
PARAM_PVS.PERIOD_LEN_CTE = 'PeriodLength-Cte'
PARAM_PVS.KPARAM_SP = 'Phase-SP'
PARAM_PVS.KPARAM_RB = 'Phase-RB'
Expand All @@ -903,7 +907,8 @@ class DEVICES:
)

PROPERTIES_DEFAULT = \
tuple(set(value for key, value in _inspect.getmembers(PARAM_PVS) \
tuple(set(
value for key, value in _inspect.getmembers(PARAM_PVS)
if not key.startswith('_') and value is not None)) + \
_properties + _properties_papu

Expand Down Expand Up @@ -1073,7 +1078,7 @@ class DEVICES:
ALL = (EPU50_10SB, )

# --- PARAM_PVS ---
PARAM_PVS = _PARAM_PVS()
PARAM_PVS = _ParamPVs()
PARAM_PVS.PERIOD_LEN_CTE = 'PeriodLength-Cte'
PARAM_PVS.IS_MOVING = 'IsMoving-Mon'
PARAM_PVS.PPARAM_SP = 'Phase-SP'
Expand Down Expand Up @@ -1102,13 +1107,13 @@ class DEVICES:
PARAM_PVS.POL_CHANGE_CMD = 'ChangePolarization-Cmd'

PROPERTIES_DEFAULT = PAPU._properties + \
tuple(set(value for key, value in _inspect.getmembers(PARAM_PVS) \
if not key.startswith('_') and value is not None)) + (
'EnblPwrAll-Cmd', 'PwrGap-Mon', 'Status-Mon',
'EnblAndReleaseGap-Sel', 'EnblAndReleaseGap-Sts',
'AllowedToChangeGap-Mon',
'IsBusy-Mon', 'Stop-Cmd',
)
tuple(set(
value for key, value in _inspect.getmembers(PARAM_PVS)
if not key.startswith('_') and value is not None)) + \
('EnblPwrAll-Cmd', 'PwrGap-Mon', 'Status-Mon',
'EnblAndReleaseGap-Sel', 'EnblAndReleaseGap-Sts',
'AllowedToChangeGap-Mon',
'IsBusy-Mon', 'Stop-Cmd',)

def __init__(self, devname=None, props2init='all', auto_monitor_mon=True):
"""."""
Expand Down Expand Up @@ -1280,6 +1285,7 @@ def cmd_move_gap_start(self, timeout=None):
return self.cmd_move_kparameter_start(timeout)

def calc_move_eta_composed(self, pparam_eta, kparam_eta):
"""."""
# model: here pparam and kparam as parallel in time
eta = max(pparam_eta, kparam_eta)
return eta
Expand All @@ -1301,7 +1307,7 @@ class DEVICES:
ALL = (DELTA52_10SB, )

# --- PARAM_PVS ---
PARAM_PVS = _PARAM_PVS()
PARAM_PVS = _ParamPVs()
PARAM_PVS.PERIOD_LEN_CTE = 'PeriodLength-Cte'
PARAM_PVS.IS_MOVING = 'Moving-Mon'
PARAM_PVS.START_PARKING_CMD = 'StartParking-Cmd'
Expand Down Expand Up @@ -1454,23 +1460,92 @@ def __init__(self, devname=None, props2init='all', auto_monitor_mon=True):
devname, props2init=props2init, auto_monitor_mon=auto_monitor_mon)


class IVU(IDBase):
"""IVU Insertion Device."""

class DEVICES:
"""Device names."""

IVU18_08SB = 'SI-08SB:ID-IVU18'
IVU18_14SB = 'SI-14SB:ID-IVU18'
ALL = (IVU18_08SB, IVU18_14SB)

# --- PARAM_PVS ---
PARAM_PVS = _ParamPVs()
# PARAM_PVS.PERIOD_LEN_CTE = 'PeriodLength-Cte'
# PARAM_PVS.IS_MOVING = 'Moving-Mon'
# PARAM_PVS.START_PARKING_CMD = 'StartParking-Cmd'
# PARAM_PVS.MOVE_ABORT = 'Abort-Cmd'
# PARAM_PVS.PPARAM_SP = 'PParam-SP'
# PARAM_PVS.PPARAM_RB = 'PParam-RB'
# PARAM_PVS.PPARAM_MON = 'PParam-Mon'
# PARAM_PVS.PPARAM_PARKED_CTE = 'PParamParked-Cte'
# PARAM_PVS.PPARAM_MAXACC_SP = 'MaxAcc-SP'
# PARAM_PVS.PPARAM_MAXACC_RB = 'MaxAcc-RB'
# PARAM_PVS.PPARAM_MAXVELO_SP = 'MaxVelo-SP'
# PARAM_PVS.PPARAM_MAXVELO_RB = 'MaxVelo-RB'
# PARAM_PVS.PPARAM_VELO_SP = 'PParamVelo-SP'
# PARAM_PVS.PPARAM_VELO_RB = 'PParamVelo-RB'
# PARAM_PVS.PPARAM_ACC_SP = 'PParamAcc-SP'
# PARAM_PVS.PPARAM_ACC_RB = 'PParamAcc-RB'
# PARAM_PVS.PPARAM_TOL_SP = 'PolTol-SP'
# PARAM_PVS.PPARAM_TOL_RB = 'PolTol-RB'
# PARAM_PVS.PPARAM_CHANGE_CMD = 'PParamChange-Cmd'
PARAM_PVS.KPARAM_SP = 'KParam-SP'
PARAM_PVS.KPARAM_RB = 'KParam-RB'
PARAM_PVS.KPARAM_MON = 'KParam-Mon'
PARAM_PVS.KPARAM_PARKED_CTE = 'KParamParked-Cte'
PARAM_PVS.KPARAM_MAXACC_SP = 'MaxAcc-SP'
PARAM_PVS.KPARAM_MAXACC_RB = 'MaxAcc-RB'
PARAM_PVS.KPARAM_MAXVELO_SP = 'MaxVelo-SP'
PARAM_PVS.KPARAM_MAXVELO_RB = 'MaxVelo-RB'
PARAM_PVS.KPARAM_VELO_SP = 'KParamVelo-SP'
PARAM_PVS.KPARAM_VELO_RB = 'KParamVelo-RB'
PARAM_PVS.KPARAM_ACC_SP = 'KParamAcc-SP'
PARAM_PVS.KPARAM_ACC_RB = 'KParamAcc-RB'
# PARAM_PVS.KPARAM_TOL_SP = 'PosTol-SP'
# PARAM_PVS.KPARAM_TOL_RB = 'PosTol-RB'
# PARAM_PVS.KPARAM_CHANGE_CMD = 'KParamChange-Cmd'
# PARAM_PVS.POL_SEL = 'Pol-Sel'
# PARAM_PVS.POL_STS = 'Pol-Sts'
# PARAM_PVS.POL_MON = 'Pol-Mon'
# PARAM_PVS.POL_CHANGE_CMD = 'PolChange-Cmd'

PROPERTIES_DEFAULT = tuple(set(
value for key, value in _inspect.getmembers(PARAM_PVS)
if not key.startswith('_') and value is not None))

def __init__(self, devname, props2init='all', auto_monitor_mon=True):
"""."""
# check if device exists
if devname not in self.DEVICES.ALL:
raise NotImplementedError(devname)

# call base class constructor
super().__init__(
devname, props2init=props2init, auto_monitor_mon=auto_monitor_mon)


class ID(IDBase):
"""Insertion Device."""

class DEVICES:
"""Device names."""
APU = APU.DEVICES
PAPU = PAPU.DEVICES
EPU = EPU.DEVICES
DELTA = DELTA.DEVICES
WIG = WIG.DEVICES
IVU = IVU.DEVICES
ALL = APU.ALL + PAPU.ALL + \
EPU.ALL + DELTA.ALL + WIG.ALL
EPU.ALL + DELTA.ALL + \
WIG.ALL + IVU.ALL

def __new__(cls, devname, **kwargs):
"""."""
IDClass = ID.get_idclass(devname)
if IDClass:
return IDClass(devname, **kwargs)
idclass = ID.get_idclass(devname)
if idclass:
return idclass(devname, **kwargs)
else:
raise NotImplementedError(devname)

Expand All @@ -1487,5 +1562,7 @@ def get_idclass(devname):
return DELTA
elif devname in WIG.DEVICES.ALL:
return WIG
elif devname in IVU.DEVICES.ALL:
return IVU
else:
return None
20 changes: 13 additions & 7 deletions siriuspy/siriuspy/idff/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import numpy as _np

from ..search import IDSearch as _IDSearch
from ..clientconfigdb import ConfigDBDocument as _ConfigDBDocument
from ..search import IDSearch as _IDSearch


class IDFFConfig(_ConfigDBDocument):
Expand Down Expand Up @@ -68,6 +68,11 @@ def qs_pvnames(self):
"""Return QS corrector power supply pvnames."""
return self._get_corr_pvnames('qs1', 'qs2')

@property
def lc_pvnames(self):
"""Return LC corrector power supply pvnames."""
return self._get_corr_pvnames('lch', '')

@property
def polarizations(self):
"""Return list of light polarizations in the IDFF config."""
Expand Down Expand Up @@ -170,7 +175,7 @@ def __str__(self):
for pol, table in self.value['polarizations'].items():
stg += f'\n--- {pol} ---'
for key, value in table.items():
if isinstance(value, (int, float)):
if value is None or isinstance(value, (int, float)):
nrpts = 1
str_ = f'{value}'
else:
Expand Down Expand Up @@ -206,10 +211,12 @@ def check_valid_value(self, value):
getch = _IDSearch.conv_idname_2_idff_chnames
getcv = _IDSearch.conv_idname_2_idff_cvnames
getqs = _IDSearch.conv_idname_2_idff_qsnames
getlc = _IDSearch.conv_idname_2_idff_lcnames
chnames = [corr + ':Current-SP' for corr in getch(self.idname)]
cvnames = [corr + ':Current-SP' for corr in getcv(self.idname)]
qsnames = [corr + ':Current-SP' for corr in getqs(self.idname)]
pvsidsearch = set(chnames + cvnames + qsnames)
lcnames = [corr + ':Current-SP' for corr in getlc(self.idname)]
pvsidsearch = set(chnames + cvnames + qsnames + lcnames)
symm_diff = pvsconfig ^ pvsidsearch

if symm_diff:
Expand Down Expand Up @@ -294,11 +301,10 @@ def _find_idname(self):
for idname in _IDSearch.get_idnames():
kparam_propty = _IDSearch.conv_idname_2_kparameter_propty(idname)
pparam_propty = _IDSearch.conv_idname_2_pparameter_propty(idname)
if None in (kparam_propty, pparam_propty):
if kparam_propty is None and pparam_propty is None:
continue
kparam = idname + ':' + kparam_propty
pparam = idname + ':' + pparam_propty

kparam = idname + ':' + kparam_propty if kparam_propty else None
pparam = idname + ':' + pparam_propty if pparam_propty else None
if kparam == kparameter and pparam == pparameter:
self._idname = idname
break
Expand Down
Loading

0 comments on commit 5dbe45f

Please sign in to comment.