Skip to content

Commit

Permalink
Merge pull request #572 from lnls-sirius/add-pv-sofb
Browse files Browse the repository at this point in the history
Add PV to control FOFB RefOrb update Percentage
  • Loading branch information
anacso17 authored Oct 31, 2022
2 parents df5a47a + d6c3353 commit 1e34150
Show file tree
Hide file tree
Showing 10 changed files with 241 additions and 66 deletions.
7 changes: 2 additions & 5 deletions pyqt-apps/scripts/sirius-hla-si-ap-fofb.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@
import sys
import argparse as _argparse

import qtawesome as qta
import siriushla.util as util

from siriushla.sirius_application import SiriusApplication
from siriushla.widgets.windows import create_window_from_widget
from siriushla.si_ap_fofb import MainWindow, MatrixWidget
from siriushla.si_ap_fofb import MainWindow, MatrixWidget, get_fofb_icon
from siriuspy.envars import VACA_PREFIX


Expand All @@ -31,7 +28,7 @@
if args.matrix:
window = create_window_from_widget(
MatrixWidget, 'Matrix View',
icon=qta.icon('fa5s.hammer', color=util.get_appropriate_color('SI')),
icon=get_fofb_icon(),
is_main=True)
app.open_window(
window, parent=None, device='SI-Glob:AP-FOFB', propty=args.property,
Expand Down
2 changes: 1 addition & 1 deletion pyqt-apps/siriushla/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.75.0
0.76.0
8 changes: 2 additions & 6 deletions pyqt-apps/siriushla/as_ap_launcher/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from siriushla.as_ap_configdb.pvsconfigs import SelectAndApplyPVsWidget
from siriushla.as_di_scrns.list_scrns import get_scrn_list
from siriushla.as_di_dccts.main import get_dcct_list
from siriushla.si_ap_fofb import get_fofb_icon


def get_pushbutton(name, parent):
Expand Down Expand Up @@ -482,12 +483,7 @@ def _set_optics_menu(self, sec):

if sec == 'si':
fofb = QAction('FOFB', optics)
fofb.setIcon(qta.icon(
'fa5s.hammer', 'fa5s.signal',
options=[
dict(scale_factor=0.85, offset=(0.15, 0.0)),
dict(scale_factor=0.7, offset=(0.0, 0.25),
rotated=90, vflip=True)]))
fofb.setIcon(get_fofb_icon(color=False))
self.connect_newprocess(fofb, 'sirius-hla-si-ap-fofb.py')
optics.addAction(fofb)

Expand Down
11 changes: 11 additions & 0 deletions pyqt-apps/siriushla/as_ap_sofb/ioc_control/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,17 @@ def get_fofb_widget(self, parent):
gdl2.addWidget(spb, 0, 0)
gdl2.addWidget(lbl, 1, 0)
gdl.addLayout(gdl2, 1, 4)

spb = SiriusSpinbox(
wid, self.devpref.substitute(propty='FOFBUpdateRefOrbPerc-SP'))
lbl = SiriusLabel(
wid, self.devpref.substitute(propty='FOFBUpdateRefOrbPerc-RB'))
lbl.showUnits = False
gdl2 = QGridLayout()
gdl2.addWidget(spb, 0, 0)
gdl2.addWidget(lbl, 1, 0)
gdl.addLayout(gdl2, 2, 4)

gdl.setRowStretch(5, 3)
return wid

Expand Down
1 change: 1 addition & 0 deletions pyqt-apps/siriushla/si_ap_fofb/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from .main import MainWindow
from .graphics import MatrixWidget
from .base import get_fofb_icon
14 changes: 14 additions & 0 deletions pyqt-apps/siriushla/si_ap_fofb/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

from qtpy.QtWidgets import QWidget

import qtawesome as qta

from siriuspy.namesys import SiriusPVName as _PVName
from siriuspy.fofb.csdev import HLFOFBConst

from ..util import get_appropriate_color
from ..as_ap_sofb.ioc_control.base import BaseObject as _BaseObject, \
BaseWidget as _BaseWidget

Expand All @@ -13,6 +16,7 @@ class BaseObject(_BaseObject):
"""Base object."""

UM2M = 1e-6
UM2NM = 1e3
URAD2RAD = 1e-6

def __init__(self, device, prefix=''):
Expand Down Expand Up @@ -46,3 +50,13 @@ def __init__(self, parent, device, prefix=''):
BaseObject.__init__(self, device, prefix)
QWidget.__init__(self, parent)
self.setObjectName('SIApp')


def get_fofb_icon(color=True):
"""Return default icon."""
iconcolor = get_appropriate_color('SI') if color else None
return qta.icon(
'fa5s.hammer', 'fa5s.signal', options=[
dict(scale_factor=0.85, offset=(0.15, 0.0)),
dict(scale_factor=0.7, offset=(0.0, 0.25), rotated=90,
vflip=True)], color=iconcolor)
168 changes: 151 additions & 17 deletions pyqt-apps/siriushla/si_ap_fofb/custom_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def __init__(self, parent, device, prefix=''):
self._ch_refy = _ConnSignal(
self.devpref.substitute(propty='RefOrbY-SP'))
self._ch_syncref = _ConnSignal(
self.devpref.substitute(propty='FOFBCtrlSyncRefOrb-Cmd'))
self.devpref.substitute(propty='CtrlrSyncRefOrb-Cmd'))

sofb_prefix = _PVName('SI-Glob:AP-SOFB').substitute(prefix=self.prefix)
self._ch_sofb_orbx = _ConnSignal(
Expand Down Expand Up @@ -214,17 +214,20 @@ class BPMSwModeWidget(BaseObject, QWidget):
def __init__(self, parent, device, prefix=''):
BaseObject.__init__(self, device, prefix)
QWidget.__init__(self, parent)
bnames = self._csorb.bpm_names
props = ['SwMode-Sel', ]
self._bpm_devs = [Device(b, props, auto_mon=True) for b in bnames]
self._bpm_devs = [
Device(b, props, auto_mon=True) for b in self._csorb.bpm_names]
self._setupUi()
self._init_dict = {}
self._init = False
self._pv_objs = list()
for dev in self._bpm_devs:
pvo = dev.pv_object('SwMode-Sel')
pvo.add_callback(self._set_initial_value)
pvo.add_callback(self._update_current_value)
if pvo.connected:
self._set_initial_value(pvo.pvname, pvo.value)
self._pv_objs.append(pvo)

def _setupUi(self):
lbl = QLabel(
Expand All @@ -241,12 +244,21 @@ def _setupUi(self):
lay.addWidget(self.sel)
lay.addWidget(self.sts)

def _set_swithing_mode(self, text):
def _set_swithing_mode(self, text, do_sp=True):
mode = _csbpm.SwModes._fields.index(text)
for dev in self._bpm_devs:
dev['SwMode-Sel'] = mode
ch2vals = {
bpm+':SwMode-Sts': mode for bpm in self._csorb.bpm_names}
if do_sp:
for dev in self._bpm_devs:
dev['SwMode-Sel'] = mode
else:
self.blockSignals(True)
self.sel.setCurrentText(text)
self.blockSignals(False)

ch2vals = dict()
for bpm in self._csorb.bpm_names:
pvn = _PVName(bpm).substitute(
prefix=self.prefix, propty='SwMode-Sts')
ch2vals[pvn] = mode
self.sts.set_channels2values(ch2vals)

def _set_initial_value(self, pvname, value, **kws):
Expand All @@ -263,13 +275,23 @@ def _set_initial_value(self, pvname, value, **kws):
value = vals[_np.argmax(cnts)]
mode = _csbpm.SwModes._fields[value]

ch2vals = {
bpm+':SwMode-Sts': value for bpm in self._csorb.bpm_names}
ch2vals = dict()
for bpm in self._csorb.bpm_names:
pvn = _PVName(bpm).substitute(
prefix=self.prefix, propty='SwMode-Sts')
ch2vals[pvn] = value
self.sts.set_channels2values(ch2vals)

self.sel.setCurrentText(mode)
self.sel.currentTextChanged.connect(self._set_swithing_mode)

def _update_current_value(self, value, **kws):
if not self._init:
return
if not _np.all([pvo.value == value for pvo in self._pv_objs]):
return
mode = _csbpm.SwModes._fields[value]
self._set_swithing_mode(mode, do_sp=False)

class AuxCommDialog(BaseObject, SiriusDialog):
"""Auxiliary command dialog."""
Expand All @@ -293,12 +315,11 @@ def _setupUi(self):
'Set all AccFreeze to Dsbl': 'CorrSetAccFreezeDsbl-Cmd',
},
'Controllers': {
'Sync Net': 'FOFBCtrlSyncNet-Cmd',
'Sync RefOrb': 'FOFBCtrlSyncRefOrb-Cmd',
# 'Configure TimeFrameLength': 'FOFBCtrlConfTFrameLen-Cmd',
'Sync Net': 'CtrlrSyncNet-Cmd',
'Sync RefOrb': 'CtrlrSyncRefOrb-Cmd',
},
'BPMs': {
'Configure BPM Log.Trigs.': 'FOFBCtrlConfBPMLogTrg-Cmd',
'Configure BPM Log.Trigs.': 'CtrlrConfBPMLogTrg-Cmd',
},
}
lay = QVBoxLayout(self)
Expand All @@ -309,7 +330,7 @@ def _setupUi(self):
if 'Corr' in group:
for dev in ['CH', 'CV']:
lbl = QLabel(
dev+' Sat. Limit (A): ', self,
dev+' Sat. Limit [A]: ', self,
alignment=Qt.AlignRight | Qt.AlignVCenter)
pref = self.devpref
spw = SiriusSpinbox(
Expand Down Expand Up @@ -341,13 +362,34 @@ def _setupUi(self):
lbl = QLabel(
'Consider BPMEnblList in Sync: ', self,
alignment=Qt.AlignRight | Qt.AlignVCenter)
pvn = pref.substitute(propty='FOFBCtrlSyncUseEnblList-Sel')
pvn = pref.substitute(propty='CtrlrSyncUseEnblList-Sel')
sbt = PyDMStateButton(self, pvn)
led = SiriusLedState(self, pvn.substitute(propty_suffix='Sts'))
glay2.addWidget(lbl, 1, 0)
glay2.addWidget(sbt, 1, 1)
glay2.addWidget(led, 1, 2)

lbl = QLabel(
'Orbit Distortion Threshold [um]: ', self,
alignment=Qt.AlignRight | Qt.AlignVCenter)
spw = SiriusSpinbox(
self, pref.substitute(propty='LoopMaxOrbDistortion-SP'))
rbw = SiriusLabel(
self, pref.substitute(propty='LoopMaxOrbDistortion-RB'))
glay2.addWidget(lbl, 2, 0)
glay2.addWidget(spw, 2, 1)
glay2.addWidget(rbw, 2, 2)

lbl = QLabel(
'Enable Orbit Distortion Detection: ', self,
alignment=Qt.AlignRight | Qt.AlignVCenter)
pvn = pref.substitute(propty='LoopMaxOrbDistortionEnbl-Sel')
sbt = PyDMStateButton(self, pvn)
led = SiriusLedState(self, pvn.substitute(propty_suffix='Sts'))
glay2.addWidget(lbl, 3, 0)
glay2.addWidget(sbt, 3, 1)
glay2.addWidget(led, 3, 2)

glay.addLayout(glay2)
elif 'BPM' in group:
swbpm = BPMSwModeWidget(self, self.device, self.prefix)
Expand Down Expand Up @@ -388,7 +430,7 @@ def __init__(self, parent, device, prefix=''):
self._setupUi()

self._ch_synenls = _ConnSignal(
self.devpref.substitute(propty='FOFBCtrlSyncEnblList-Mon'))
self.devpref.substitute(propty='CtrlrSyncEnblList-Mon'))
self._ch_synenls.new_value_signal[_np.ndarray].connect(
self._update_dcc_enbllist)

Expand All @@ -402,6 +444,8 @@ def _setupUi(self):
tab.addTab(self._setupLinkPartnerTab(), 'DCC Linked Partners')
tab.addTab(self._setupRefOrbTab(), 'RefOrb Sync Status')
tab.addTab(self._setupTimeFrameLenTab(), 'DCC TimeFrameLen')
tab.addTab(self._setupOrbDistTab(), 'Orbit Distortion Detection')
tab.addTab(self._setupIntlkTab(), 'Interlock')
tab.addTab(self._setupBPMLogTrigTab(), 'BPM Logical Trigger Configs')

lay = QVBoxLayout(self)
Expand Down Expand Up @@ -649,6 +693,96 @@ def _update_reftimeframelen(self, value):
for pvn, led in self._led_timeframelen.items():
led.set_channels2values({pvn: value})

def _setupOrbDistTab(self):
wid = QWidget()
lay = QGridLayout(wid)
lay.setSpacing(1)
lay.setAlignment(Qt.AlignLeft | Qt.AlignTop)

# header
lay.addWidget(
QLabel('<h4>Device</h4>', self, alignment=Qt.AlignCenter), 0, 0)
lay.addWidget(
QLabel('<h4>Threshold</h4>', self, alignment=Qt.AlignCenter), 0, 1)
lay.addWidget(
QLabel('<h4>Enable</h4>', self, alignment=Qt.AlignCenter), 0, 2)

# table
self.leds_odd = dict()
for idx, ctl in enumerate(self.ctrlrs):
row = idx + 1
c2v = dict()

lbl = QLabel(ctl, self, alignment=Qt.AlignCenter)
pvn = _PVName(ctl).substitute(
prefix=self.prefix, propty='MaxOrbDistortion-RB')
c2v[pvn] = 0
plb = SiriusLabel(self, pvn)
lay.addWidget(lbl, row, 0)
lay.addWidget(plb, row, 1)

pvn = _PVName(ctl).substitute(
prefix=self.prefix, propty='MaxOrbDistortionEnbl-Sts')
c2v[pvn] = 0
led = SiriusLedState(self, pvn)
led.setObjectName('led_status')
led.shape = led.ShapeMap.Square
lay.addWidget(led, row, 2, alignment=Qt.AlignTop)

led = PyDMLedMultiChannel(self, c2v)
self.leds_odd[ctl] = led
lay.addWidget(led, row, 3)

self._ch_odt = _ConnSignal(
self.devpref.substitute(propty='LoopMaxOrbDistortion-RB'))
self._ch_odt.new_value_signal[float].connect(
self._update_reforbdist)
self._ch_odd = _ConnSignal(
self.devpref.substitute(propty='LoopMaxOrbDistortionEnbl-Sts'))
self._ch_odd.new_value_signal[int].connect(
self._update_reforbdist)

return self._build_scroll_area(wid)

def _update_reforbdist(self, _):
odt = self._ch_odt.value
odd = self._ch_odd.value
if odt is None or odd is None:
return
odt = int(odt*self.UM2NM)
for ctl, led in self.leds_odd.items():
pref = _PVName(ctl).substitute(prefix=self.prefix)
c2v = {
pref.substitute(propty='MaxOrbDistortion-RB'): odt,
pref.substitute(propty='MaxOrbDistortionEnbl-Sts'): odd,
}
led.set_channels2values(c2v)

def _setupIntlkTab(self):
wid = QWidget()
lay = QGridLayout(wid)
lay.setSpacing(1)
lay.setAlignment(Qt.AlignLeft | Qt.AlignTop)

# header
lay.addWidget(
QLabel('<h4>Device</h4>', self, alignment=Qt.AlignCenter), 0, 0)
lay.addWidget(
QLabel('<h4>Interlock</h4>', self, alignment=Qt.AlignCenter), 0, 1)

# table
for idx, dcc in enumerate(self.ctrlrs):
row = idx + 1
lbl = QLabel(dcc, self, alignment=Qt.AlignCenter)
lay.addWidget(lbl, row, 0)
pvn = _PVName(dcc).substitute(
prefix=self.prefix, propty='Intlk-Mon')
led = SiriusLedAlert(self, pvn)
led.setObjectName('led_status')
lay.addWidget(led, row, 1, alignment=Qt.AlignTop)

return self._build_scroll_area(wid)

def _setupBPMLogTrigTab(self):
wid = QWidget()
lay = QGridLayout(wid)
Expand Down
Loading

0 comments on commit 1e34150

Please sign in to comment.