Skip to content

Commit

Permalink
Merge pull request #366 from lnls-sirius/PR-cleanup-remove-computer
Browse files Browse the repository at this point in the history
Remove Unnecessary Computer Class
  • Loading branch information
xresende authored Feb 10, 2020
2 parents 75dfa2d + 30367f4 commit 8f28bfe
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 215 deletions.
2 changes: 1 addition & 1 deletion siriuspy/siriuspy/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.12.0
1.13.0
24 changes: 0 additions & 24 deletions siriuspy/siriuspy/computer.py

This file was deleted.

22 changes: 19 additions & 3 deletions siriuspy/siriuspy/diagnostics/bpms/bpm_plugins.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import numpy as _np
"""BPM plugins module."""

from threading import Event as _Event
from threading import Thread as _Thread

import numpy as _np
from epics import PV as _PV
from siriuspy.epics.fake_pv import PVFake as _PVFake
from siriuspy.epics.fake_pv import add_to_database as _add_to_database

from siriuspy.epics.pv_fake import PVFake as _PVFake
from siriuspy.epics.pv_fake import add_to_database as _add_to_database
from siriuspy.csdevice.bpms import get_bpm_database as _get_bpm_db
from siriuspy.csdevice.bpms import FFTWritableProps

Expand All @@ -12,6 +16,7 @@


def get_prop_and_suffix(name):
"""."""
prop = name.lower().replace('-', '_').replace('.', '')
prop = prop.split('_')
suf = prop[1] if len(prop) > 1 else ''
Expand All @@ -34,9 +39,11 @@ def run(self):
self.function(*self.args)

def restart(self):
"""."""
self.run_now = True

def stop(self):
"""."""
self.run_now = False


Expand Down Expand Up @@ -75,9 +82,12 @@ def {0}_{1}_run_callbacks(self):


class BPM:
"""BPM class."""

_PV_class = None

def __init__(self, bpm_name, prefix='', callback=None):
"""."""
self.pv_prefix = prefix + bpm_name + ':'
_add_to_database(pvDB, prefix=self.pv_prefix)
self.pvs = dict()
Expand All @@ -101,11 +111,15 @@ def __init__(self, bpm_name, prefix='', callback=None):


class BPMEpics(BPM):
"""BPM Epics."""

_PV_class = _PV
_PV_add_class = _PVFake


class BPMFake(BPM):
"""BPM Fake."""

_PV_class = _PVFake
_PV_add_class = _PVFake
M = _np.array([[-2, -2, 0, 0],
Expand All @@ -114,6 +128,7 @@ class BPMFake(BPM):
[-2, -2, -2, -2]])

def __init__(self, bpm_name, prefix='', callback=None):
"""."""
super().__init__(bpm_name=bpm_name, prefix=prefix, callback=callback)
self._x_ref = 0
self._y_ref = 0
Expand Down Expand Up @@ -141,6 +156,7 @@ def __init__(self, bpm_name, prefix='', callback=None):
self.timer.start()

def set_ref_pos(self, x=None, y=None, q=None):
"""."""
if x is not None:
self._x_ref = float(x)
if y is not None:
Expand Down
123 changes: 0 additions & 123 deletions siriuspy/siriuspy/epics/psdiag_pv.py

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
"""Definition of ComputedPV class that simulates a PV composed of epics PVs."""
#!/usr/local/bin/python-sirius
"""PS Diag PVs."""

import numpy as _np

from epics import PV as _PV

from siriuspy.epics import connection_timeout as _connection_timeout
from siriuspy.csdevice.pwrsupply import Const as _PSConst
from siriuspy.csdevice.pwrsupply import ETypes as _ETypes
from siriuspy.search import PSSearch as _PSSearch
from siriuspy.namesys import SiriusPVName as _PVName


class ComputedPV:
Expand All @@ -13,8 +21,6 @@ class ComputedPV:
computed process variables.
"""

# NOTE: currently this is being used only in as-ps-diag IOC classes.

def __init__(self, pvname, computer, queue, pvs, monitor=True):
"""Initialize PVs."""
# print('compute_pv: ', pvname, pvs)
Expand Down Expand Up @@ -108,7 +114,7 @@ def run_callbacks(self):
'lolim': self.lower_disp_limit,
'low': self.lower_warning_limit,
'lolo': self.lower_alarm_limit,
})
})

def wait_for_connection(self, timeout):
"""Wait util computed PV is connected or until timeout."""
Expand Down Expand Up @@ -197,3 +203,106 @@ def _value_update_callback(self, pvname, value, **kwargs):
def _issue_callback(self, **kwargs):
for index, callback in self._callbacks.items():
callback(**kwargs)


class PSDiffPV:
"""Diff of a PS current setpoint and a readback."""

CURRT_SP = 0
CURRT_MON = 1


def compute_update(self, computed_pv, updated_pv_name, value):
"""Compute difference between SP and Mon current values."""
disconnected = \
not computed_pv.pvs[PSDiffPV.CURRT_SP].connected or \
not computed_pv.pvs[PSDiffPV.CURRT_MON].connected
if disconnected:
return None
value_sp = computed_pv.pvs[PSDiffPV.CURRT_SP].value
value_rb = computed_pv.pvs[PSDiffPV.CURRT_MON].value
diff = value_rb - value_sp
return {'value': diff}


class PSStatusPV:
"""Power Supply Status PV."""

# TODO: Add other interlocks for some PS types

BIT_PSCONNECT = 0b000001
BIT_PWRSTATON = 0b000010
BIT_OPMODEDIF = 0b000100
BIT_CURRTDIFF = 0b001000
BIT_INTERLKOK = 0b010000
BIT_BOWFMDIFF = 0b100000

PWRSTE_STS = 0
INTLK_SOFT = 1
INTLK_HARD = 2
OPMODE_SEL = 3
OPMODE_STS = 4
CURRT_DIFF = 5
WAVFRM_MON = 6

DTOLWFM_DICT = dict()

def compute_update(self, computed_pv, updated_pv_name, value):
"""Compute PS Status PV."""
psname = _PVName(computed_pv.pvs[0].pvname).device_name
value = 0
# ps connected?
disconnected = \
not computed_pv.pvs[PSStatusPV.PWRSTE_STS].connected or \
not computed_pv.pvs[PSStatusPV.INTLK_SOFT].connected or \
not computed_pv.pvs[PSStatusPV.INTLK_HARD].connected or \
not computed_pv.pvs[PSStatusPV.OPMODE_SEL].connected or \
not computed_pv.pvs[PSStatusPV.OPMODE_STS].connected or \
not computed_pv.pvs[PSStatusPV.CURRT_DIFF].connected
if disconnected:
value |= PSStatusPV.BIT_PSCONNECT
value |= PSStatusPV.BIT_PWRSTATON
value |= PSStatusPV.BIT_INTERLKOK
value |= PSStatusPV.BIT_OPMODEDIF
value |= PSStatusPV.BIT_CURRTDIFF
value |= PSStatusPV.BIT_BOWFMDIFF
return {'value': value}

# pwrstate?
pwrsts = computed_pv.pvs[PSStatusPV.PWRSTE_STS].value
if pwrsts != _PSConst.PwrStateSts.On or pwrsts is None:
value |= PSStatusPV.BIT_PWRSTATON

# opmode?
sel = computed_pv.pvs[PSStatusPV.OPMODE_SEL].value
sts = computed_pv.pvs[PSStatusPV.OPMODE_STS].value
if sel is not None and sts is not None:
opmode_sel = _ETypes.OPMODES[sel]
opmode_sts = _ETypes.STATES[sts]
if opmode_sel != opmode_sts:
value |= PSStatusPV.BIT_OPMODEDIF
# current-diff?
if sts == _PSConst.States.SlowRef:
severity = computed_pv.pvs[PSStatusPV.CURRT_DIFF].severity
if severity != 0:
value |= PSStatusPV.BIT_CURRTDIFF
# waveform diff?
elif (psname.sec == 'BO') and (sts == _PSConst.States.RmpWfm):
mon = computed_pv.pvs[PSStatusPV.WAVFRM_MON].value
if psname not in PSStatusPV.DTOLWFM_DICT.keys():
pstype = _PSSearch.conv_psname_2_pstype(psname)
PSStatusPV.DTOLWFM_DICT[psname] = _PSSearch.get_splims(
pstype, 'DTOL_WFM')
if not _np.allclose(mon, 0.0,
atol=PSStatusPV.DTOLWFM_DICT[psname]):
value |= PSStatusPV.BIT_BOWFMDIFF
else:
value |= PSStatusPV.BIT_OPMODEDIF

# interlocks?
intlksoft = computed_pv.pvs[PSStatusPV.INTLK_SOFT].value
intlkhard = computed_pv.pvs[PSStatusPV.INTLK_HARD].value
if intlksoft != 0 or intlksoft is None or \
intlkhard != 0 or intlkhard is None:
value |= PSStatusPV.BIT_INTERLKOK
return {'value': value}
Loading

0 comments on commit 8f28bfe

Please sign in to comment.