Skip to content

Commit

Permalink
Merge pull request #1087 from lnls-sirius/fix-fofb
Browse files Browse the repository at this point in the history
Minor fixes in FOFB IOC
  • Loading branch information
anacso17 authored May 27, 2024
2 parents 83508fd + 526ab74 commit 87b1a9c
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 18 deletions.
2 changes: 1 addition & 1 deletion siriuspy/siriuspy/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.88.0
2.88.1
55 changes: 52 additions & 3 deletions siriuspy/siriuspy/devices/fofb.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,6 @@ def fofbacc_filter_num_biquads(self):
ctl = self._ctl_refs[FOFBCtrlBase.DEVICES.SI01]
return ctl.fofbacc_filter_num_biquads



class FamFastCorrs(_DeviceSet):
"""Family of FOFB fast correctors."""
Expand Down Expand Up @@ -1103,13 +1102,13 @@ def check_fofbacc_filter(
if not isinstance(value, (list, tuple, _np.ndarray)):
raise ValueError('Value must be iterable.')
devs = self._get_devices(psnames, psindices)
for dev in devs:
for dev in devs:
if len(value) != len(dev.fofbacc_filter):
return False
if not _np.allclose(value, dev.fofbacc_filter, atol=atol):
return False
return True

def set_fofbacc_filter_gain(self, value, psnames=None, psindices=None):
"""Command to set accumulator filter gain."""
if not isinstance(value, (int, float)):
Expand Down Expand Up @@ -1178,6 +1177,11 @@ class DEVICES:
'CtrlrSyncTFrameLen-Cmd', 'CtrlrConfBPMLogTrg-Cmd',
'CtrlrSyncMaxOrbDist-Cmd', 'CtrlrSyncPacketLossDetec-Cmd',
'CtrlrReset-Cmd',
'FOFBAccDecimation-Sel', 'FOFBAccDecimation-Sts',
'FOFBAccDecimation-SP', 'FOFBAccDecimation-RB',
'FOFBAccFilter-Sel', 'FOFBAccFilter-Sts',
'FOFBAccFilter-SP', 'FOFBAccFilter-RB',
'FOFBAccFilterGain-SP', 'FOFBAccFilterGain-RB',
'KickCHAcc-Mon', 'KickCVAcc-Mon',
'KickCHRef-Mon', 'KickCVRef-Mon',
'KickCH-Mon', 'KickCV-Mon',
Expand Down Expand Up @@ -1422,6 +1426,51 @@ def cmd_fofbctrl_reset(self):
self['CtrlrReset-Cmd'] = 1
return True

@property
def fofbacc_decimation_enumvalue(self):
"""Accumulator decimation enum value."""
return self['FOFBAccDecimation-Sts']

@fofbacc_decimation_enumvalue.setter
def fofbacc_decimation_enumvalue(self, value):
self['FOFBAccDecimation-Sel'] = value

@property
def fofbacc_decimation_value(self):
"""Accumulator decimation value."""
return self['FOFBAccDecimation-RB']

@fofbacc_decimation_value.setter
def fofbacc_decimation_value(self, value):
self['FOFBAccDecimation-SP'] = value

@property
def fofbacc_filter_enumvalue(self):
"""Accumulator filter enum value."""
return self['FOFBAccFilter-Sts']

@fofbacc_filter_enumvalue.setter
def fofbacc_filter_enumvalue(self, value):
self['FOFBAccFilter-Sel'] = value

@property
def fofbacc_filter_value(self):
"""Accumulator filter value."""
return self['FOFBAccFilter-RB']

@fofbacc_filter_value.setter
def fofbacc_filter_value(self, value):
self['FOFBAccFilter-SP'] = value

@property
def fofbacc_filter_gain(self):
"""Accumulator filter gain value."""
return self['FOFBAccFilterGain-RB']

@fofbacc_filter_gain.setter
def fofbacc_filter_gain(self, value):
self['FOFBAccFilterGain-SP'] = value

@property
def kickch_acc(self):
"""Return CH kicks related to FOFBAcc-Mon PVs."""
Expand Down
16 changes: 8 additions & 8 deletions siriuspy/siriuspy/fofb/csdev.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ETypes(_csdev.ETypes):
STS_LBLS_CORR = (
'Connected', 'PwrStateOn', 'OpModeConfigured', 'AccFreezeConfigured',
'InvRespMatRowSynced', 'AccGainSynced', 'AccSatLimsSynced',
'AccDecimationSynced')
'AccDecimationSynced', 'AccFilterSynced', 'AccFilterGainSynced')
STS_LBLS_FOFBCTRL = (
'Connected', 'BPMIdsConfigured', 'NetSynced', 'LinkPartnerConnected',
'RefOrbSynced', 'TimeFrameLenSynced', 'BPMLogTrigsConfigured',
Expand Down Expand Up @@ -69,17 +69,17 @@ class HLFOFBConst(_csdev.Const):
MeasRespMatMon = _csdev.Const.register('MeasRespMatMon', _et.MEAS_RMAT_MON)
DecOpt = _csdev.Const.register('DecOpt', _et.DEC_OPT)
FilterOpt = _csdev.Const.register('FilterOpt', _et.FILTER_OPT)

# FOFB Switching filter coefficientes
_b4 = [9.10339395e-01, -1.11484423e-16, 9.10339395e-01] # freq FOFB/4
_a4 = [-1.11484423e-16, 8.20678791e-01] # freq FOFB/4
_b2 = [0.83408931895964943947774372645654, 0.83408931895964943947774372645654, 0.0] # freq FOFB/2
_a2 = [0.66817863791929887895548745291308, 0.0] # freq FOFB/2

FILTER_UNIT = [1.0, 0.0, 0.0, 0.0, 0.0]
FILTER_SW_4 = _b4 + _a4
FILTER_SW_4 = _b4 + _a4
FILTER_SW_2 = _b2 + _a2

def __init__(self):
"""Class constructor."""

Expand Down Expand Up @@ -269,7 +269,7 @@ def get_hlfofb_database(self):
'FOFBAccDecimation-RB': {
'type': 'float', 'value': 1, 'prec': 0, 'lolim': 1,
'hilim': 8600, 'unit': 'count'},

# filter configuration
'FOFBAccFilter-Sel': {
'type': 'enum', 'enums': _et.FILTER_OPT,
Expand All @@ -278,16 +278,16 @@ def get_hlfofb_database(self):
'type': 'enum', 'enums': _et.FILTER_OPT,
'value': self.FilterOpt.Unit, 'unit': 'Unit_Switching_Custom'},
'FOFBAccFilter-SP': {
'type': 'float', 'value': 20*[0], 'prec': 5, 'count': 20,
'type': 'float', 'value': 20*[0], 'prec': 5, 'count': 20,
'unit': 'coef'},
'FOFBAccFilter-RB': {
'type': 'float', 'value': 20*[0], 'prec': 5, 'count': 20,
'unit': 'coef'},
'FOFBAccFilterGain-SP': {
'type': 'float', 'value': 1.0, 'prec': 5,
'type': 'float', 'value': 1.0, 'prec': 5,
'lolim': 0, 'hilim': 1000,'unit': 'gain'},
'FOFBAccFilterGain-RB': {
'type': 'float', 'value': 1.0, 'prec': 5,
'type': 'float', 'value': 1.0, 'prec': 5,
'unit': 'gain'},

# Reference Orbit (same order of SOFB)
Expand Down
25 changes: 19 additions & 6 deletions siriuspy/siriuspy/fofb/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,12 @@ def init_database(self):
'FOFBAccDecimation-Sts': self._corr_accdec_enm,
'FOFBAccDecimation-SP': self._corr_accdec_val,
'FOFBAccDecimation-RB': self._corr_accdec_val,
'FOFBAccFilter-Sel': self._corr_accfilter_enm,
'FOFBAccFilter-Sts': self._corr_accfilter_enm,
'FOFBAccFilter-SP': self._corr_accfilter_val,
'FOFBAccFilter-RB': self._corr_accfilter_val,
'FOFBAccFilterGain-SP': self._corr_accfilter_gain,
'FOFBAccFilterGain-RB': self._corr_accfilter_gain,
'MinSingValue-SP': self._min_sing_val,
'MinSingValue-RB': self._min_sing_val,
'TikhonovRegConst-SP': self._tikhonov_reg_const,
Expand Down Expand Up @@ -574,6 +580,11 @@ def cmd_corr_configure(self, _):
self._set_corrs_fofbacc_freeze()
# matrix coefficients
self._set_corrs_coeffs()
# filter
self._update_log('Setting corrector filter...')
self._corrs_dev.set_fofbacc_filter(self._corr_accfilter_val)
self._corrs_dev.set_fofbacc_filter_gain(self._corr_accfilter_gain)
self._update_log('...done!')

self._update_log('Correctors configuration done!')
return True
Expand Down Expand Up @@ -709,7 +720,7 @@ def set_corr_accdec(self, option, value):
self._update_log('...done!')

return True

def set_corr_accfilter(self, option, value):
"""Set corrector accumulator filter."""

Expand All @@ -728,7 +739,7 @@ def set_corr_accfilter(self, option, value):

elif value == self._const.FilterOpt.Switching:
filter = sw2 + sw4 + (num_biquads - 2) * unit

else:
filter = self._corr_accfilter_val
self._corr_accfilter_enm = value
Expand Down Expand Up @@ -1887,11 +1898,13 @@ def _check_corrs_configs(self):
dec = self._corr_accdec_val
if not self._corrs_dev.check_fofbacc_decimation(dec):
value = _updt_bit(value, 7, 1)
# AccFilter
if not self._corrs_dev.check_fofbacc_filter(self._corr_accfilter_val):
# AccFilterSynced
filter = self._corr_accfilter_val
if not self._corrs_dev.check_fofbacc_filter(filter):
value = _updt_bit(value, 8, 1)
# AccFilterGain
if not self._corrs_dev.check_fofbacc_filter_gain(self._corr_accfilter_gain):
# AccFilterGainSynced
gain = self._corr_accfilter_gain
if not self._corrs_dev.check_fofbacc_filter_gain(gain):
value = _updt_bit(value, 9, 1)
else:
value = 0b1111111111
Expand Down

0 comments on commit 87b1a9c

Please sign in to comment.