From 8deed37983348f703a7c0281d27e210374b82ac2 Mon Sep 17 00:00:00 2001 From: juliacscarvalho Date: Tue, 7 May 2024 12:55:45 -0300 Subject: [PATCH 01/11] Add accumulator filter for FOFB fast correctors --- siriuspy/siriuspy/devices/fofb.py | 30 +++++++++++++++++ siriuspy/siriuspy/devices/pwrsupply.py | 9 ++++++ siriuspy/siriuspy/fofb/csdev.py | 20 ++++++++++++ siriuspy/siriuspy/fofb/main.py | 45 ++++++++++++++++++++++++++ 4 files changed, 104 insertions(+) diff --git a/siriuspy/siriuspy/devices/fofb.py b/siriuspy/siriuspy/devices/fofb.py index 1db26b9d6..a56a1e340 100644 --- a/siriuspy/siriuspy/devices/fofb.py +++ b/siriuspy/siriuspy/devices/fofb.py @@ -702,6 +702,7 @@ class FamFastCorrs(_DeviceSet): DEF_ATOL_FOFBACCSAT = 2e-2 DEF_ATOL_CURRENT_RB = 1e-6 DEF_ATOL_CURRENT_MON = 2e-2 + DEF_ATOL_ACCFILTER = 2**-17 def __init__(self, psnames=None): """Init.""" @@ -1071,6 +1072,35 @@ def cmd_fofbacc_clear(self, psnames=None, psindices=None): dev.cmd_fofbacc_clear() return True + def set_fofbacc_filter(self, values, psnames=None, psindices=None): + """Command to set power supply filter coefficients values.""" + if not isinstance(values, (list, tuple, _np.ndarray)): + raise ValueError('Value must be iterable.') + devs = self._get_devices(psnames, psindices) + if not len(values) == len(devs): + raise ValueError('Values and indices must have the same size.') + for i, dev in enumerate(devs): + dev.fofbacc_filter = values[i] + return True + + def check_fofbacc_filter( + self, values, psnames=None, psindices=None, + atol=DEF_ATOL_ACCFILTER): + """Check power supplies filter coefficients.""" + if not self.connected: + return False + if not isinstance(values, (list, tuple, _np.ndarray)): + raise ValueError('Value must be iterable.') + devs = self._get_devices(psnames, psindices) + if not len(values) == len(devs): + raise ValueError('Values and indices must have the same size.') + for i, dev in enumerate(devs): + if len(values[i]) != len(dev.fofbacc_filter): + return False + if not _np.allclose(values[i], dev.fofbacc_filter, atol=atol): + return False + return True + # ----- private methods ----- def _get_devices(self, names, indices): diff --git a/siriuspy/siriuspy/devices/pwrsupply.py b/siriuspy/siriuspy/devices/pwrsupply.py index 9fab6b677..f64f8d3bb 100644 --- a/siriuspy/siriuspy/devices/pwrsupply.py +++ b/siriuspy/siriuspy/devices/pwrsupply.py @@ -65,6 +65,7 @@ class _PSDev(_Device): 'FOFBAccSatMin-SP', 'FOFBAccSatMin-RB', 'FOFBAcc-Mon', 'FOFBAccDecimation-SP', 'FOFBAccDecimation-RB', + 'FOFBAccFilter-SP', 'FOFBAccFilter-RB', ) _properties_pulsed = ( 'Voltage-SP', 'Voltage-RB', 'Voltage-Mon', @@ -1031,6 +1032,14 @@ def cmd_fofbacc_clear(self): self['FOFBAccClear-Cmd'] = 1 return True + @property + def fofbacc_filter(self): + """FOFB accumulator filter.""" + return self['FOFBAccFilter-RB'] + + @fofbacc_filter.setter + def fofbacc_filter(self, value): + self['FOFBAccFilter-SP'] = value class PowerSupplyFBP(PowerSupply): """FBP Power Supply Device.""" diff --git a/siriuspy/siriuspy/fofb/csdev.py b/siriuspy/siriuspy/fofb/csdev.py index b9e875709..90e6285fd 100644 --- a/siriuspy/siriuspy/fofb/csdev.py +++ b/siriuspy/siriuspy/fofb/csdev.py @@ -34,6 +34,7 @@ class ETypes(_csdev.ETypes): 'LoopInterlockOk', 'SYSIDExcitationDisabled') DEC_OPT = ('FOFB', 'Monit', 'Custom') + FILTER_OPT = ('Unit', 'Switching', 'Custom') _et = ETypes # syntactic sugar @@ -67,6 +68,7 @@ class HLFOFBConst(_csdev.Const): MeasRespMatCmd = _csdev.Const.register('MeasRespMatCmd', _et.MEAS_RMAT_CMD) 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) def __init__(self): """Class constructor.""" @@ -118,6 +120,10 @@ def __init__(self): self.dccenbl_min = _np.array([ bpm.sub[2:] in ['M1', 'M2'] for bpm in self.bpm_names]) + # acc filters + # self.acc_filter_unit = 50*[1] + # self + def get_hlfofb_database(self): """Return Soft IOC database.""" pvs_database = { @@ -257,6 +263,20 @@ 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, + 'value': self.FilterOpt.Unit, 'unit': 'Unit_Switching_Custom'}, + 'FOFBAccFilter-Sts': { + 'type': 'enum', 'enums': _et.FILTER_OPT, + 'value': self.FilterOpt.Unit, 'unit': 'Unit_Switching_Custom'}, + 'FOFBAccFilter-SP': { + 'type': 'float', 'value': 50*[0], 'prec': 5, 'count': 50, + 'unit': 'coef'}, + 'FOFBAccFilter-RB': { + 'type': 'float', 'value': 50*[0], 'prec': 5, 'count': 50, + 'unit': 'coef'}, # Reference Orbit (same order of SOFB) 'RefOrbX-SP': { diff --git a/siriuspy/siriuspy/fofb/main.py b/siriuspy/siriuspy/fofb/main.py index cfd91cc13..5686b31c4 100644 --- a/siriuspy/siriuspy/fofb/main.py +++ b/siriuspy/siriuspy/fofb/main.py @@ -72,6 +72,8 @@ def __init__(self, tests=False): } self._corr_accdec_val = 1 self._corr_accdec_enm = self._const.DecOpt.FOFB + self._corr_accfilter_val = 20*[0.0] + self._corr_accfilter_enm = self._const.FilterOpt.Unit self._thread_enbllist = None self._abort_thread_enbllist = False self._min_sing_val = self._const.MIN_SING_VAL @@ -152,6 +154,8 @@ def __init__(self, tests=False): 'CtrlrDsblSYSIDExc-Cmd': self.cmd_fofbctrl_dsblsysid, 'FOFBAccDecimation-Sel': _part(self.set_corr_accdec, 'enum'), 'FOFBAccDecimation-SP': _part(self.set_corr_accdec, 'value'), + 'FOFBAccFilter-Sel': _part(self.set_corr_accfilter, 'enum'), + 'FOFBAccFilter-SP': _part(self.set_corr_accfilter, 'value'), 'RefOrbX-SP': _part(self.set_reforbit, 'x'), 'RefOrbY-SP': _part(self.set_reforbit, 'y'), 'RespMat-SP': self.set_respmat, @@ -703,6 +707,47 @@ def set_corr_accdec(self, option, value): self._update_log('...done!') return True + + + def set_corr_accfilter(self, option, value): + """Set corrector accumulator filter.""" + if self._corr_accfilter_enm != self._const.FilterOpt.Custom and \ + option == 'value': + return False + + if option == 'enum': + if value == self._const.FilterOpt.Unit: + filter = 20*[0.0] + filter[0] = 1 + filter[5] = 1 + filter[10] = 1 + filter[15] = 1 + + elif value == self._const.FilterOpt.Switching: + 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 = 20*[0.0] + filter[0:3] = b4 + filter[3:5] = a4 + filter[5:8] = b2 + filter[8:10] = a2 + else: + filter = self._corr_accfilter_val + self._corr_accdfilter_enm = value + self.run_callbacks('FOFBAccFilter-Sts', value) + self.run_callbacks('FOFBAccFilter-SP', filter) + else: + filter = value + self._corr_accfilter_val = filter + self.run_callbacks('FOFBAccFilter-RB', filter) + + self._update_log('Setting FOFB Acc filter...') + self._corrs_dev.set_fofbacc_filter(filter) + self._update_log('...done!') + + return True def _thread_corr_currzero(self): if self._corrs_dev.check_current(0): From f4f032407334a41bd277aec2ba8d4e0f2396c811 Mon Sep 17 00:00:00 2001 From: juliacscarvalho Date: Tue, 7 May 2024 17:11:12 -0300 Subject: [PATCH 02/11] Use PV FOFBAccFilterNumBiquads-Cte --- siriuspy/siriuspy/devices/fofb.py | 12 ++++++++++++ siriuspy/siriuspy/devices/pwrsupply.py | 1 + siriuspy/siriuspy/fofb/csdev.py | 12 +++++++++++- siriuspy/siriuspy/fofb/main.py | 24 +++++++++--------------- 4 files changed, 33 insertions(+), 16 deletions(-) diff --git a/siriuspy/siriuspy/devices/fofb.py b/siriuspy/siriuspy/devices/fofb.py index a56a1e340..5d5fe3768 100644 --- a/siriuspy/siriuspy/devices/fofb.py +++ b/siriuspy/siriuspy/devices/fofb.py @@ -39,6 +39,7 @@ class FOFBCtrlRef(_Device, FOFBCtrlBase): 'LoopIntlk-Mon', 'LoopIntlkReset-Cmd', 'SYSIDPRBSFOFBAccEn-Sel', 'SYSIDPRBSFOFBAccEn-Sts', 'SYSIDPRBSBPMPosEn-Sel', 'SYSIDPRBSBPMPosEn-Sts', + 'FOFBAccFilterNumBiquads-Cte', ) def __init__(self, devname, props2init='all'): @@ -141,6 +142,10 @@ def cmd_reset(self): self['LoopIntlkReset-Cmd'] = 1 return True + @property + def fofbacc_filter_num_biquads(self): + """FOFB accumulator filter number of biquads.""" + return self['FOFBAccFilterNumBiquads-Cte'] # ---------------- DCC devices ---------------- @@ -690,6 +695,13 @@ def cmd_dsbl_sysid_exc(self, timeout=DEF_TIMEOUT): self._evt_fofb.cmd_external_trigger() return True + @property + def fofbacc_filter_num_biquads(self): + """FOFB accumulator filter number of biquads.""" + ctl = self._ctl_refs[FOFBCtrlBase.DEVICES.SI01] + return ctl.fofbacc_filter_num_biquads + + class FamFastCorrs(_DeviceSet): """Family of FOFB fast correctors.""" diff --git a/siriuspy/siriuspy/devices/pwrsupply.py b/siriuspy/siriuspy/devices/pwrsupply.py index f64f8d3bb..214095f14 100644 --- a/siriuspy/siriuspy/devices/pwrsupply.py +++ b/siriuspy/siriuspy/devices/pwrsupply.py @@ -1040,6 +1040,7 @@ def fofbacc_filter(self): @fofbacc_filter.setter def fofbacc_filter(self, value): self['FOFBAccFilter-SP'] = value + class PowerSupplyFBP(PowerSupply): """FBP Power Supply Device.""" diff --git a/siriuspy/siriuspy/fofb/csdev.py b/siriuspy/siriuspy/fofb/csdev.py index 90e6285fd..4f56d0865 100644 --- a/siriuspy/siriuspy/fofb/csdev.py +++ b/siriuspy/siriuspy/fofb/csdev.py @@ -69,7 +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_2 = _b2 + _a2 + def __init__(self): """Class constructor.""" diff --git a/siriuspy/siriuspy/fofb/main.py b/siriuspy/siriuspy/fofb/main.py index 5686b31c4..2af784aea 100644 --- a/siriuspy/siriuspy/fofb/main.py +++ b/siriuspy/siriuspy/fofb/main.py @@ -708,31 +708,25 @@ def set_corr_accdec(self, option, value): return True - def set_corr_accfilter(self, option, value): """Set corrector accumulator filter.""" + + num_biquads = self._llfofb_dev.fofbacc_filter_num_biquads + unit = self._const.FILTER_UNIT + sw2 = self._const.FILTER_SW_2 + sw4 = self._const.FILTER_SW_4 + if self._corr_accfilter_enm != self._const.FilterOpt.Custom and \ option == 'value': return False if option == 'enum': if value == self._const.FilterOpt.Unit: - filter = 20*[0.0] - filter[0] = 1 - filter[5] = 1 - filter[10] = 1 - filter[15] = 1 + filter = num_biquads * unit elif value == self._const.FilterOpt.Switching: - 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 = 20*[0.0] - filter[0:3] = b4 - filter[3:5] = a4 - filter[5:8] = b2 - filter[8:10] = a2 + filter = sw2 + sw4 + (num_biquads - 2) * unit + else: filter = self._corr_accfilter_val self._corr_accdfilter_enm = value From 0a0a0ef4b7941fcd7881405c59f3a29dca301206 Mon Sep 17 00:00:00 2001 From: juliacscarvalho Date: Thu, 9 May 2024 16:15:37 -0300 Subject: [PATCH 03/11] Add acc filter gain --- siriuspy/siriuspy/devices/fofb.py | 24 ++++++++++++++++++++++++ siriuspy/siriuspy/devices/pwrsupply.py | 11 ++++++++++- siriuspy/siriuspy/fofb/csdev.py | 10 ++++++---- siriuspy/siriuspy/fofb/main.py | 16 +++++++++++++++- 4 files changed, 55 insertions(+), 6 deletions(-) diff --git a/siriuspy/siriuspy/devices/fofb.py b/siriuspy/siriuspy/devices/fofb.py index 5d5fe3768..4ecefe00b 100644 --- a/siriuspy/siriuspy/devices/fofb.py +++ b/siriuspy/siriuspy/devices/fofb.py @@ -715,6 +715,7 @@ class FamFastCorrs(_DeviceSet): DEF_ATOL_CURRENT_RB = 1e-6 DEF_ATOL_CURRENT_MON = 2e-2 DEF_ATOL_ACCFILTER = 2**-17 + DEF_ATOL_ACCFILTERGAIN = 2**-12 def __init__(self, psnames=None): """Init.""" @@ -1112,6 +1113,29 @@ def check_fofbacc_filter( if not _np.allclose(values[i], 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, (list, tuple, _np.ndarray)): + raise ValueError('Value must be iterable.') + devs = self._get_devices(psnames, psindices) + for i, dev in enumerate(devs): + dev.fofbacc_filter_gain = value + return True + + def check_fofbacc_filter_gain( + self, values, psnames=None, psindices=None, + atol=DEF_ATOL_ACCFILTERGAIN): + """Check accumulator filter gain.""" + if not self.connected: + return False + devs = self._get_devices(psnames, psindices) + impltd = _np.asarray([d.fofbacc_filter_gain for d in devs]) + if isinstance(values, (int, float)): + values = len(devs) * [values] + if _np.allclose(values, impltd, atol=atol): + return True + return False # ----- private methods ----- diff --git a/siriuspy/siriuspy/devices/pwrsupply.py b/siriuspy/siriuspy/devices/pwrsupply.py index 214095f14..445d4ae08 100644 --- a/siriuspy/siriuspy/devices/pwrsupply.py +++ b/siriuspy/siriuspy/devices/pwrsupply.py @@ -65,7 +65,8 @@ class _PSDev(_Device): 'FOFBAccSatMin-SP', 'FOFBAccSatMin-RB', 'FOFBAcc-Mon', 'FOFBAccDecimation-SP', 'FOFBAccDecimation-RB', - 'FOFBAccFilter-SP', 'FOFBAccFilter-RB', + 'FOFBAccFilter-SP', 'FOFBAccFilter-RB', + 'FOFBAccFilterGain-SP', 'FOFBAccFilterGain-RB', ) _properties_pulsed = ( 'Voltage-SP', 'Voltage-RB', 'Voltage-Mon', @@ -1041,6 +1042,14 @@ def fofbacc_filter(self): def fofbacc_filter(self, value): self['FOFBAccFilter-SP'] = value + @property + def fofbacc_filter_gain(self): + """FOFB accumulator filter gain.""" + return self['FOFBAccFilterGain-RB'] + + @fofbacc_filter_gain.setter + def fofbacc_filter_gain(self, value): + self['FOFBAccFilterGain-SP'] = value class PowerSupplyFBP(PowerSupply): """FBP Power Supply Device.""" diff --git a/siriuspy/siriuspy/fofb/csdev.py b/siriuspy/siriuspy/fofb/csdev.py index 4f56d0865..f613bd718 100644 --- a/siriuspy/siriuspy/fofb/csdev.py +++ b/siriuspy/siriuspy/fofb/csdev.py @@ -130,10 +130,6 @@ def __init__(self): self.dccenbl_min = _np.array([ bpm.sub[2:] in ['M1', 'M2'] for bpm in self.bpm_names]) - # acc filters - # self.acc_filter_unit = 50*[1] - # self - def get_hlfofb_database(self): """Return Soft IOC database.""" pvs_database = { @@ -287,6 +283,12 @@ def get_hlfofb_database(self): 'FOFBAccFilter-RB': { 'type': 'float', 'value': 50*[0], 'prec': 5, 'count': 50, 'unit': 'coef'}, + 'FOFBAccFilterGain-SP': { + 'type': 'float', 'value': 1.0, 'prec': 5, + 'lolim': 0, 'hilim': 1000,'unit': 'gain'}, + 'FOFBAccFilterGain-RB': { + 'type': 'float', 'value': 1.0, 'prec': 5, + 'unit': 'gain'}, # Reference Orbit (same order of SOFB) 'RefOrbX-SP': { diff --git a/siriuspy/siriuspy/fofb/main.py b/siriuspy/siriuspy/fofb/main.py index 2af784aea..1e838e91e 100644 --- a/siriuspy/siriuspy/fofb/main.py +++ b/siriuspy/siriuspy/fofb/main.py @@ -74,6 +74,7 @@ def __init__(self, tests=False): self._corr_accdec_enm = self._const.DecOpt.FOFB self._corr_accfilter_val = 20*[0.0] self._corr_accfilter_enm = self._const.FilterOpt.Unit + self._corr_accfilter_gain = 1.0 self._thread_enbllist = None self._abort_thread_enbllist = False self._min_sing_val = self._const.MIN_SING_VAL @@ -156,6 +157,7 @@ def __init__(self, tests=False): 'FOFBAccDecimation-SP': _part(self.set_corr_accdec, 'value'), 'FOFBAccFilter-Sel': _part(self.set_corr_accfilter, 'enum'), 'FOFBAccFilter-SP': _part(self.set_corr_accfilter, 'value'), + 'FOFBAccFilterGain-SP': self.set_corr_accfilter_gain, 'RefOrbX-SP': _part(self.set_reforbit, 'x'), 'RefOrbY-SP': _part(self.set_reforbit, 'y'), 'RespMat-SP': self.set_respmat, @@ -729,7 +731,7 @@ def set_corr_accfilter(self, option, value): else: filter = self._corr_accfilter_val - self._corr_accdfilter_enm = value + self._corr_accfilter_enm = value self.run_callbacks('FOFBAccFilter-Sts', value) self.run_callbacks('FOFBAccFilter-SP', filter) else: @@ -743,6 +745,18 @@ def set_corr_accfilter(self, option, value): return True + def set_corr_accfilter_gain(self, value): + """Set corrector accumulator filter gain.""" + + self._corr_accfilter_gain = value + self.run_callbacks('FOFBAccFilterGain-RB', value) + + self._update_log('Setting FOFB Acc filter gain...') + self._corrs_dev.set_fofbacc_filter_gain(value) + self._update_log('...done!') + + return True + def _thread_corr_currzero(self): if self._corrs_dev.check_current(0): self._update_log('Current of all correctors already zeroed.') From 6ebce1dd1d008970968f710355bb4516324118ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BAlia=20Carvalho?= <97030556+juliacscarvalho@users.noreply.github.com> Date: Sat, 18 May 2024 12:42:45 -0300 Subject: [PATCH 04/11] Update csdev.py The low level is implemented in a way that it returns a 20 element array only. --- siriuspy/siriuspy/fofb/csdev.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/siriuspy/siriuspy/fofb/csdev.py b/siriuspy/siriuspy/fofb/csdev.py index f613bd718..39270dd2d 100644 --- a/siriuspy/siriuspy/fofb/csdev.py +++ b/siriuspy/siriuspy/fofb/csdev.py @@ -278,10 +278,10 @@ def get_hlfofb_database(self): 'type': 'enum', 'enums': _et.FILTER_OPT, 'value': self.FilterOpt.Unit, 'unit': 'Unit_Switching_Custom'}, 'FOFBAccFilter-SP': { - 'type': 'float', 'value': 50*[0], 'prec': 5, 'count': 50, + 'type': 'float', 'value': 20*[0], 'prec': 5, 'count': 20, 'unit': 'coef'}, 'FOFBAccFilter-RB': { - 'type': 'float', 'value': 50*[0], 'prec': 5, 'count': 50, + 'type': 'float', 'value': 20*[0], 'prec': 5, 'count': 20, 'unit': 'coef'}, 'FOFBAccFilterGain-SP': { 'type': 'float', 'value': 1.0, 'prec': 5, From fda8bb085991d6ba7e72be933052b50980a923c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BAlia=20Carvalho?= <97030556+juliacscarvalho@users.noreply.github.com> Date: Sat, 18 May 2024 14:43:05 -0300 Subject: [PATCH 05/11] Update fofb.py S --- siriuspy/siriuspy/devices/fofb.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/siriuspy/siriuspy/devices/fofb.py b/siriuspy/siriuspy/devices/fofb.py index 4ecefe00b..2de85609c 100644 --- a/siriuspy/siriuspy/devices/fofb.py +++ b/siriuspy/siriuspy/devices/fofb.py @@ -1119,7 +1119,7 @@ def set_fofbacc_filter_gain(self, value, psnames=None, psindices=None): if not isinstance(value, (list, tuple, _np.ndarray)): raise ValueError('Value must be iterable.') devs = self._get_devices(psnames, psindices) - for i, dev in enumerate(devs): + for dev in devs: dev.fofbacc_filter_gain = value return True From 5cf80273034f72ad7e7fc6f876807691e90cf6f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BAlia=20Carvalho?= <97030556+juliacscarvalho@users.noreply.github.com> Date: Mon, 20 May 2024 10:42:21 -0300 Subject: [PATCH 06/11] Update fofb.py set_fofbacc_filter_gain is now expecting a int or float. --- siriuspy/siriuspy/devices/fofb.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/siriuspy/siriuspy/devices/fofb.py b/siriuspy/siriuspy/devices/fofb.py index 2de85609c..c2b2df205 100644 --- a/siriuspy/siriuspy/devices/fofb.py +++ b/siriuspy/siriuspy/devices/fofb.py @@ -1116,7 +1116,7 @@ def check_fofbacc_filter( def set_fofbacc_filter_gain(self, value, psnames=None, psindices=None): """Command to set accumulator filter gain.""" - if not isinstance(value, (list, tuple, _np.ndarray)): + if not isinstance(value, (int, float)): raise ValueError('Value must be iterable.') devs = self._get_devices(psnames, psindices) for dev in devs: From db18afe149885696bbca3c409d94b9b48ef5bc8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BAlia=20Carvalho?= <97030556+juliacscarvalho@users.noreply.github.com> Date: Mon, 20 May 2024 10:48:32 -0300 Subject: [PATCH 07/11] Update main.py Update the callback after calling set_fofbacc_filter and set_fofbaccfilter_gain. --- siriuspy/siriuspy/fofb/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/siriuspy/siriuspy/fofb/main.py b/siriuspy/siriuspy/fofb/main.py index 1e838e91e..e2d492882 100644 --- a/siriuspy/siriuspy/fofb/main.py +++ b/siriuspy/siriuspy/fofb/main.py @@ -737,11 +737,11 @@ def set_corr_accfilter(self, option, value): else: filter = value self._corr_accfilter_val = filter - self.run_callbacks('FOFBAccFilter-RB', filter) self._update_log('Setting FOFB Acc filter...') self._corrs_dev.set_fofbacc_filter(filter) self._update_log('...done!') + self.run_callbacks('FOFBAccFilter-RB', filter) return True @@ -749,11 +749,11 @@ def set_corr_accfilter_gain(self, value): """Set corrector accumulator filter gain.""" self._corr_accfilter_gain = value - self.run_callbacks('FOFBAccFilterGain-RB', value) self._update_log('Setting FOFB Acc filter gain...') self._corrs_dev.set_fofbacc_filter_gain(value) self._update_log('...done!') + self.run_callbacks('FOFBAccFilterGain-RB', value) return True From 08a95f5edfe0756c2eb75f6e8647e8850b016575 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BAlia=20Carvalho?= <97030556+juliacscarvalho@users.noreply.github.com> Date: Mon, 20 May 2024 10:50:20 -0300 Subject: [PATCH 08/11] Update main.py Adding check routines to the acc filter and acc filter gain. --- siriuspy/siriuspy/fofb/main.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/siriuspy/siriuspy/fofb/main.py b/siriuspy/siriuspy/fofb/main.py index e2d492882..a637d1c41 100644 --- a/siriuspy/siriuspy/fofb/main.py +++ b/siriuspy/siriuspy/fofb/main.py @@ -1887,8 +1887,14 @@ 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): + value = _updt_bit(value, 8, 1) + # AccFilterGain + if not self._corrs_dev.check_fofbacc_filter_gain(self._corr_accfilter_gain): + value = _updt_bit(value, 9, 1) else: - value = 0b11111111 + value = 0b1111111111 self._corr_status = value self.run_callbacks('CorrStatus-Mon', self._corr_status) From abbb35c25939b2b3673037dbeecf4466126ff0a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BAlia=20Carvalho?= Date: Mon, 20 May 2024 16:01:31 -0300 Subject: [PATCH 09/11] Fixing some acc filter bugs --- siriuspy/siriuspy/devices/fofb.py | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/siriuspy/siriuspy/devices/fofb.py b/siriuspy/siriuspy/devices/fofb.py index c2b2df205..bd9556184 100644 --- a/siriuspy/siriuspy/devices/fofb.py +++ b/siriuspy/siriuspy/devices/fofb.py @@ -1085,32 +1085,28 @@ def cmd_fofbacc_clear(self, psnames=None, psindices=None): dev.cmd_fofbacc_clear() return True - def set_fofbacc_filter(self, values, psnames=None, psindices=None): + def set_fofbacc_filter(self, value, psnames=None, psindices=None): """Command to set power supply filter coefficients values.""" - if not isinstance(values, (list, tuple, _np.ndarray)): + if not isinstance(value, (list, tuple, _np.ndarray)): raise ValueError('Value must be iterable.') devs = self._get_devices(psnames, psindices) - if not len(values) == len(devs): - raise ValueError('Values and indices must have the same size.') - for i, dev in enumerate(devs): - dev.fofbacc_filter = values[i] + for dev in devs: + dev.fofbacc_filter = value return True def check_fofbacc_filter( - self, values, psnames=None, psindices=None, + self, value, psnames=None, psindices=None, atol=DEF_ATOL_ACCFILTER): """Check power supplies filter coefficients.""" if not self.connected: return False - if not isinstance(values, (list, tuple, _np.ndarray)): + if not isinstance(value, (list, tuple, _np.ndarray)): raise ValueError('Value must be iterable.') devs = self._get_devices(psnames, psindices) - if not len(values) == len(devs): - raise ValueError('Values and indices must have the same size.') - for i, dev in enumerate(devs): - if len(values[i]) != len(dev.fofbacc_filter): + for dev in devs: + if len(value) != len(dev.fofbacc_filter): return False - if not _np.allclose(values[i], dev.fofbacc_filter, atol=atol): + if not _np.allclose(value, dev.fofbacc_filter, atol=atol): return False return True @@ -1124,16 +1120,16 @@ def set_fofbacc_filter_gain(self, value, psnames=None, psindices=None): return True def check_fofbacc_filter_gain( - self, values, psnames=None, psindices=None, + self, value, psnames=None, psindices=None, atol=DEF_ATOL_ACCFILTERGAIN): """Check accumulator filter gain.""" if not self.connected: return False devs = self._get_devices(psnames, psindices) impltd = _np.asarray([d.fofbacc_filter_gain for d in devs]) - if isinstance(values, (int, float)): - values = len(devs) * [values] - if _np.allclose(values, impltd, atol=atol): + if isinstance(value, (int, float)): + value = len(devs) * [value] + if _np.allclose(value, impltd, atol=atol): return True return False From b922e5e566a55ed6d295ced2541332284cdf2745 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BAlia=20Carvalho?= Date: Mon, 20 May 2024 16:16:17 -0300 Subject: [PATCH 10/11] Fix the error message in check and set filter funtions --- siriuspy/siriuspy/devices/fofb.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/siriuspy/siriuspy/devices/fofb.py b/siriuspy/siriuspy/devices/fofb.py index bd9556184..79e60739b 100644 --- a/siriuspy/siriuspy/devices/fofb.py +++ b/siriuspy/siriuspy/devices/fofb.py @@ -1113,7 +1113,7 @@ def check_fofbacc_filter( def set_fofbacc_filter_gain(self, value, psnames=None, psindices=None): """Command to set accumulator filter gain.""" if not isinstance(value, (int, float)): - raise ValueError('Value must be iterable.') + raise ValueError('Value must be integer or float.') devs = self._get_devices(psnames, psindices) for dev in devs: dev.fofbacc_filter_gain = value @@ -1125,10 +1125,11 @@ def check_fofbacc_filter_gain( """Check accumulator filter gain.""" if not self.connected: return False + if not isinstance(value, (int, float)): + raise ValueError('Value must be integer or float.') devs = self._get_devices(psnames, psindices) impltd = _np.asarray([d.fofbacc_filter_gain for d in devs]) - if isinstance(value, (int, float)): - value = len(devs) * [value] + value = len(devs) * [value] if _np.allclose(value, impltd, atol=atol): return True return False From e6b848aa9e28620e2295aa9a90fc66a62d26140a Mon Sep 17 00:00:00 2001 From: Ana Clara Oliveira Date: Mon, 20 May 2024 17:29:49 -0300 Subject: [PATCH 11/11] Update version to 2.88.0 --- siriuspy/siriuspy/VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/siriuspy/siriuspy/VERSION b/siriuspy/siriuspy/VERSION index ece2083a6..093fd27dc 100644 --- a/siriuspy/siriuspy/VERSION +++ b/siriuspy/siriuspy/VERSION @@ -1 +1 @@ -2.87.1 +2.88.0