From 8de9274f0129d72ff360eb199b4de0dff9c6013d Mon Sep 17 00:00:00 2001 From: Ana Clara Oliveira Date: Fri, 14 Oct 2022 16:17:33 -0300 Subject: [PATCH 01/10] fofb.FIX: fix bug in FOFBAccFreeze checks --- siriuspy/siriuspy/devices/fofb.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/siriuspy/siriuspy/devices/fofb.py b/siriuspy/siriuspy/devices/fofb.py index 4b292c90f..7bb994de2 100644 --- a/siriuspy/siriuspy/devices/fofb.py +++ b/siriuspy/siriuspy/devices/fofb.py @@ -723,6 +723,9 @@ def check_fofbacc_freeze( if not self.connected: return False devs = self._get_devices(psnames, psindices) + if isinstance(values, (int, float, bool)): + values = len(devs) * [values] + values = list(values) return self._wait_devices_propty( devs, 'FOFBAccFreeze-Sts', values, timeout=timeout) From 2a8ed1679b6b67435b8748770e28edeecbc0d8b8 Mon Sep 17 00:00:00 2001 From: Ana Clara Oliveira Date: Fri, 14 Oct 2022 16:23:23 -0300 Subject: [PATCH 02/10] fofb.ENH: change IOC to set RefOrb X and Y using only one setpoint in controllers RefOrb PVs, on sync RefOrb command --- siriuspy/siriuspy/devices/fofb.py | 30 ++++++++++++++++++++++++++++-- siriuspy/siriuspy/fofb/main.py | 14 +++++--------- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/siriuspy/siriuspy/devices/fofb.py b/siriuspy/siriuspy/devices/fofb.py index 7bb994de2..b8daa71e4 100644 --- a/siriuspy/siriuspy/devices/fofb.py +++ b/siriuspy/siriuspy/devices/fofb.py @@ -81,6 +81,11 @@ def refy(self, value): var[NR_BPM:] = _np.array(value, dtype=int) self.ref = var + def set_ref(self, value): + """Set RefOrb.""" + self.ref = value + return True + def set_refx(self, value): """Set RefOrb X.""" self.refx = value @@ -91,12 +96,18 @@ def set_refy(self, value): self.refy = value return True + def check_ref(self, value): + """Check whether RefOrb is equal to value.""" + if not _np.all(self.ref == value): + return False + return True + def check_refx(self, value): - """Check if first half of RefOrb is equal to value.""" + """Check whether first half of RefOrb is equal to value.""" return self._check_reforbit('x', value) def check_refy(self, value): - """Check if second half of RefOrb is equal to value.""" + """Check whether second half of RefOrb is equal to value.""" return self._check_reforbit('y', value) def _check_reforbit(self, plane, value): @@ -272,6 +283,12 @@ def __init__(self): super().__init__('SI-Glob:BS-FOFB', devices) + def set_reforb(self, value): + """Set RefOrb for all FOFB controllers.""" + for ctrl in self._ctl_refs.values(): + ctrl.set_ref(value) + return True + def set_reforbx(self, value): """Set RefOrbX for all FOFB controllers.""" return self._set_reforb('x', value) @@ -286,6 +303,15 @@ def _set_reforb(self, plane, value): fun(value) return True + def check_reforb(self, value): + """Check whether RefOrb is equal to value.""" + if not self.connected: + return False + for ctrl in self._ctl_refs.values(): + if not ctrl.check_ref(value): + return False + return True + def check_reforbx(self, value): """Check whether RefOrbX is equal to value.""" return self._check_reforb('x', value) diff --git a/siriuspy/siriuspy/fofb/main.py b/siriuspy/siriuspy/fofb/main.py index b6f948868..753b5d45d 100644 --- a/siriuspy/siriuspy/fofb/main.py +++ b/siriuspy/siriuspy/fofb/main.py @@ -570,12 +570,10 @@ def cmd_fofbctrl_syncreforb(self, _): """Sync FOFB RefOrb command.""" self._update_log('Received sync FOFB RefOrb command...') self._update_log('Checking...') - if not self._llfofb_dev.check_reforbx(self._reforbhw_x) or \ - not self._llfofb_dev.check_reforby(self._reforbhw_y): + reforb = _np.hstack([self._reforbhw_x, self._reforbhw_y]) + if not self._llfofb_dev.check_reforb(reforb): self._update_log('Syncing FOFB RefOrb...') - self._llfofb_dev.set_reforbx(self._reforbhw_x) - _time.sleep(self._const.DEF_TIMEWAIT) - self._llfofb_dev.set_reforby(self._reforbhw_y) + self._llfofb_dev.set_reforb(reforb) self._update_log('Sent RefOrb to FOFB controllers.') else: self._update_log('FOFB RefOrb already synced.') @@ -684,8 +682,6 @@ def set_reforbit(self, plane, value): refhw = _np.round(refhw) # round, low level expect it to be int refhw = _np.roll(refhw, 1) # make BPM 01M1 the first element setattr(self, '_reforbhw_' + plane.lower(), refhw) - fun = getattr(self._llfofb_dev, 'set_reforb' + plane.lower()) - fun(refhw) # update readback PV self.run_callbacks(f'RefOrb{plane.upper()}-RB', list(ref.ravel())) @@ -1270,8 +1266,8 @@ def _check_configs(self): if not self._llfofb_dev.linkpartners_connected: value = _updt_bit(value, 3, 1) # RefOrbSynced - if not self._llfofb_dev.check_reforbx(self._reforbhw_x) or \ - not self._llfofb_dev.check_reforby(self._reforbhw_y): + reforb = _np.hstack([self._reforbhw_x, self._reforbhw_y]) + if not self._llfofb_dev.check_reforb(reforb): value = _updt_bit(value, 4, 1) # TimeFrameLenConfigured tframelen = self._time_frame_len From 0f89b5b57f193138d74198f808ade5b8725d9cd3 Mon Sep 17 00:00:00 2001 From: Ana Clara Oliveira Date: Fri, 14 Oct 2022 17:07:17 -0300 Subject: [PATCH 03/10] fofb.ENH: separate LoopGain and AccSatMax setpoints for H and V planes --- siriuspy/siriuspy/fofb/csdev.py | 33 ++++++-- siriuspy/siriuspy/fofb/main.py | 137 ++++++++++++++++++++------------ 2 files changed, 109 insertions(+), 61 deletions(-) diff --git a/siriuspy/siriuspy/fofb/csdev.py b/siriuspy/siriuspy/fofb/csdev.py index 410fbb954..3866200ad 100644 --- a/siriuspy/siriuspy/fofb/csdev.py +++ b/siriuspy/siriuspy/fofb/csdev.py @@ -113,17 +113,28 @@ def get_hlfofb_database(self): 'LoopState-Sts': { 'type': 'enum', 'enums': _et.OPEN_CLOSED, 'value': self.LoopState.Open}, - 'LoopGain-SP': { + 'LoopGainH-SP': { 'type': 'float', 'value': 1, 'prec': 4, 'lolim': -2**3, 'hilim': 2**3-1, - 'unit': 'Global FOFB pre-accumulator gain.'}, - 'LoopGain-RB': { + 'unit': 'Horizontal FOFB pre-accumulator gain.'}, + 'LoopGainH-RB': { 'type': 'float', 'value': 1, 'prec': 4, 'lolim': -2**3, 'hilim': 2**3-1, - 'unit': 'Global FOFB pre-accumulator gain.'}, - 'LoopGain-Mon': { + 'unit': 'Horizontal FOFB pre-accumulator gain.'}, + 'LoopGainH-Mon': { 'type': 'float', 'value': 0, 'prec': 4, - 'unit': 'Global FOFB pre-accumulator gain.'}, + 'unit': 'Horizontal FOFB pre-accumulator gain.'}, + 'LoopGainV-SP': { + 'type': 'float', 'value': 1, 'prec': 4, + 'lolim': -2**3, 'hilim': 2**3-1, + 'unit': 'Vertical FOFB pre-accumulator gain.'}, + 'LoopGainV-RB': { + 'type': 'float', 'value': 1, 'prec': 4, + 'lolim': -2**3, 'hilim': 2**3-1, + 'unit': 'Vertical FOFB pre-accumulator gain.'}, + 'LoopGainV-Mon': { + 'type': 'float', 'value': 0, 'prec': 4, + 'unit': 'Vertical FOFB pre-accumulator gain.'}, # Correctors 'CHPosS-Cte': { @@ -148,10 +159,16 @@ def get_hlfofb_database(self): 'CorrSetAccFreezeEnbl-Cmd': {'type': 'int', 'value': 0}, 'CorrSetAccClear-Cmd': {'type': 'int', 'value': 0}, 'CorrSetCurrZero-Cmd': {'type': 'int', 'value': 0}, - 'CorrAccSatMax-SP': { + 'CHAccSatMax-SP': { + 'type': 'float', 'prec': 6, 'value': 0.95, 'unit': 'A', + 'lolim': 0, 'hilim': 0.95}, + 'CHAccSatMax-RB': { + 'type': 'float', 'prec': 6, 'value': 0.95, 'unit': 'A', + 'lolim': 0, 'hilim': 0.95}, + 'CVAccSatMax-SP': { 'type': 'float', 'prec': 6, 'value': 0.95, 'unit': 'A', 'lolim': 0, 'hilim': 0.95}, - 'CorrAccSatMax-RB': { + 'CVAccSatMax-RB': { 'type': 'float', 'prec': 6, 'value': 0.95, 'unit': 'A', 'lolim': 0, 'hilim': 0.95}, diff --git a/siriuspy/siriuspy/fofb/main.py b/siriuspy/siriuspy/fofb/main.py index 753b5d45d..425116aef 100644 --- a/siriuspy/siriuspy/fofb/main.py +++ b/siriuspy/siriuspy/fofb/main.py @@ -33,8 +33,10 @@ def __init__(self, tests=False): # internal states self._loop_state = self._const.LoopState.Open - self._loop_gain = 1 - self._loop_gain_mon = 0 + self._loop_gain_h = 1 + self._loop_gain_mon_h = 0 + self._loop_gain_v = 1 + self._loop_gain_mon_v = 0 self._thread_loopstate = None self._abort_thread = False self._corr_status = self._pvs_database['CorrStatus-Mon']['value'] @@ -44,7 +46,8 @@ def __init__(self, tests=False): self._corr_setaccfreezedsbl_count = 0 self._corr_setaccclear_count = 0 self._corr_setcurrzero_count = 0 - self._corr_maxacccurr = self._pvs_database['CorrAccSatMax-RB']['value'] + self._ch_maxacccurr = self._pvs_database['CHAccSatMax-RB']['value'] + self._cv_maxacccurr = self._pvs_database['CVAccSatMax-RB']['value'] self._time_frame_len = self._pvs_database['TimeFrameLen-RB']['value'] self._fofbctrl_status = \ self._pvs_database['FOFBCtrlStatus-Mon']['value'] @@ -124,14 +127,16 @@ def __init__(self, tests=False): # pvs to write methods self.map_pv2write = { 'LoopState-Sel': self.set_loopstate, - 'LoopGain-SP': self.set_loopgain, + 'LoopGainH-SP': _part(self.set_loopgain, 'h'), + 'LoopGainV-SP': _part(self.set_loopgain, 'v'), 'CorrConfig-Cmd': self.cmd_corr_configure, 'CorrSetOpModeManual-Cmd': self.cmd_corr_opmode_manual, 'CorrSetAccFreezeDsbl-Cmd': self.cmd_corr_accfreeze_dsbl, 'CorrSetAccFreezeEnbl-Cmd': self.cmd_corr_accfreeze_enbl, 'CorrSetAccClear-Cmd': self.cmd_corr_accclear, 'CorrSetCurrZero-Cmd': self.cmd_corr_currzero, - 'CorrAccSatMax-SP': self.set_corr_accsatmax, + 'CHAccSatMax-SP': _part(self.set_corr_accsatmax, 'ch'), + 'CVAccSatMax-SP': _part(self.set_corr_accsatmax, 'cv'), 'TimeFrameLen-SP': self.set_timeframelen, 'FOFBCtrlSyncNet-Cmd': self.cmd_fofbctrl_syncnet, 'FOFBCtrlSyncRefOrb-Cmd': self.cmd_fofbctrl_syncreforb, @@ -167,9 +172,12 @@ def init_database(self): """Set initial PV values.""" self.run_callbacks('LoopState-Sel', self._loop_state) self.run_callbacks('LoopState-Sts', self._loop_state) - self.run_callbacks('LoopGain-SP', self._loop_gain) - self.run_callbacks('LoopGain-RB', self._loop_gain) - self.run_callbacks('LoopGain-Mon', self._loop_gain_mon) + self.run_callbacks('LoopGainH-SP', self._loop_gain_h) + self.run_callbacks('LoopGainH-RB', self._loop_gain_h) + self.run_callbacks('LoopGainH-Mon', self._loop_gain_mon_h) + self.run_callbacks('LoopGainV-SP', self._loop_gain_v) + self.run_callbacks('LoopGainV-RB', self._loop_gain_v) + self.run_callbacks('LoopGainV-Mon', self._loop_gain_mon_v) self.run_callbacks('CorrStatus-Mon', self._corr_status) self.run_callbacks('CorrConfig-Cmd', self._corr_confall_count) self.run_callbacks( @@ -182,8 +190,10 @@ def init_database(self): 'CorrSetAccClear-Cmd', self._corr_setaccclear_count) self.run_callbacks( 'CorrSetCurrZero-Cmd', self._corr_setcurrzero_count) - self.run_callbacks('CorrAccSatMax-SP', self._corr_maxacccurr) - self.run_callbacks('CorrAccSatMax-RB', self._corr_maxacccurr) + self.run_callbacks('CHAccSatMax-SP', self._ch_maxacccurr) + self.run_callbacks('CHAccSatMax-RB', self._ch_maxacccurr) + self.run_callbacks('CVAccSatMax-SP', self._cv_maxacccurr) + self.run_callbacks('CVAccSatMax-RB', self._cv_maxacccurr) self.run_callbacks('TimeFrameLen-SP', self._time_frame_len) self.run_callbacks('TimeFrameLen-RB', self._time_frame_len) self.run_callbacks('FOFBCtrlStatus-Mon', self._fofbctrl_status) @@ -324,7 +334,7 @@ def _thread_set_loop_state(self, value): if value: # closing the loop # set gains to zero, recalculate gains and coeffs self._update_log('Setting Loop Gain to zero...') - self._loop_gain_mon = 0 + self._loop_gain_mon_h, self._loop_gain_mon_v = 0, 0 self._calc_corrs_coeffs(log=False) # set and wait corrector gains and coeffs to zero self._set_corrs_coeffs(log=False) @@ -384,21 +394,26 @@ def _do_loop_gain_ramp(self, ramp='up'): xdata = _np.linspace(0, 1, self._const.LOOPGAIN_RMP_NPTS) if ramp == 'up': ydata = xdata**3 - ydata *= self._loop_gain + ydata_h = ydata * self._loop_gain_h + ydata_v = ydata * self._loop_gain_v else: ydata = (1-xdata)**3 - ydata *= self._loop_gain_mon - for i, val in enumerate(ydata): + ydata_h = ydata * self._loop_gain_mon_h + ydata_v = ydata * self._loop_gain_mon_v + for i in range(self._const.LOOPGAIN_RMP_NPTS): if not self.havebeam: self._update_log('ERR: Do not have stored beam. Aborted.') return False if self._check_abort_thread(): return False - self._loop_gain_mon = val - self.run_callbacks('LoopGain-Mon', self._loop_gain_mon) + self._loop_gain_mon_h = ydata_h[i] + self._loop_gain_mon_v = ydata_v[i] + self.run_callbacks('LoopGainH-Mon', self._loop_gain_mon_h) + self.run_callbacks('LoopGainV-Mon', self._loop_gain_mon_v) self._update_log( - f'{i+1:02d}/{len(ydata):02d} -> Loop Gain = {val:.3f}') + f'{i+1:02d}/{len(ydata):02d} -> Loop Gain: ' + f'H={ydata_h[i]:.3f}, V={ydata_v[i]:.3f}') self._calc_corrs_coeffs(log=False) self._set_corrs_coeffs(log=False) _time.sleep(1/self._const.LOOPGAIN_RMP_FREQ) @@ -411,7 +426,7 @@ def _check_abort_thread(self): return True return False - def set_loopgain(self, value): + def set_loopgain(self, plane, value): """Set loop gain.""" if not -2**3 <= value <= 2**3-1: return False @@ -422,17 +437,17 @@ def set_loopgain(self, value): self._update_log('ERR:setting new value.') return False - self._loop_gain = value + setattr(self, '_loop_gain_' + plane, value) # if loop closed, calculate new gains and coefficients if self._loop_state: - self._loop_gain_mon = value - self.run_callbacks('LoopGain-Mon', self._loop_gain_mon) + setattr(self, '_loop_gain_mon_' + plane, value) + self.run_callbacks(f'LoopGain{plane.upper()}-Mon', value) self._calc_corrs_coeffs() self._set_corrs_coeffs() - self._update_log('Changed Loop Gain to '+str(value)+'.') - self.run_callbacks('LoopGain-RB', self._loop_gain) + self._update_log(f'Changed Loop Gain {plane.upper()} to {value}.') + self.run_callbacks(f'LoopGain{plane.upper()}-RB', value) return True # --- devices configuration --- @@ -519,20 +534,21 @@ def cmd_corr_currzero(self, _): 'CorrSetCurrZero-Cmd', self._corr_setcurrzero_count) return False - def set_corr_accsatmax(self, value): - """Set corrector FOFB accumulator saturation limits.""" + def set_corr_accsatmax(self, device, value): + """Set device FOFB accumulator saturation limits.""" if not 0 <= value <= 0.95: return False - self._corr_maxacccurr = value - self._update_log('Setting corrector saturation limits...') - self._corrs_dev.set_fofbacc_satmax(self._corr_maxacccurr) - self._corrs_dev.set_fofbacc_satmin(-self._corr_maxacccurr) + setattr(self, '_'+device+'_maxacccurr', value) + self._update_log('Setting '+device.upper()+' saturation limits...') + psnames = getattr(self._const, device+'_names') + self._corrs_dev.set_fofbacc_satmax(value, psnames=psnames) + self._corrs_dev.set_fofbacc_satmin(-value, psnames=psnames) self._update_log('...done!') - self._update_log('Changed corrector saturation limits to ') - self._update_log(str(value)+'A.') - self.run_callbacks('CorrAccSatMax-RB', self._corr_maxacccurr) + self._update_log( + 'Changed '+device.upper()+' saturation limits to '+str(value)+'A.') + self.run_callbacks(device.upper()+'AccSatMax-RB', value) return True def set_timeframelen(self, value): @@ -1150,24 +1166,35 @@ def _calc_corrs_coeffs(self, log=True): # calculate coefficients and gains invmat = self._invrespmatconv[:-1] # remove RF line coeffs = _np.zeros(invmat.shape) - loop_gain = self._loop_gain_mon - if loop_gain == 0: - gains = _np.zeros(self._const.nr_chcv) - else: - reso = self._const.ACCGAIN_RESO - if self._invrespmat_normmode == self._const.GlobIndiv.Global: - maxval = _np.amax(abs(invmat)) - gain = _np.ceil(maxval * loop_gain / reso) * reso - norm = gain / loop_gain - if norm != 0: - coeffs = invmat / norm - gains = gain * _np.ones(self._const.nr_chcv) - elif self._invrespmat_normmode == self._const.GlobIndiv.Individual: - maxval = _np.amax(abs(invmat), axis=1) - gains = _np.ceil(maxval * loop_gain / reso) * reso - norm = gains / loop_gain - idcs = norm > 0 - coeffs[idcs] = invmat[idcs] / norm[idcs][:, None] + gains = _np.zeros(self._const.nr_chcv) + + loop_gain_h, loop_gain_v = self._loop_gain_mon_h, self._loop_gain_mon_v + nrch, nrcv = self._const.nr_ch, self._const.nr_cv + slch, slcv = slice(0, nrch), slice(nrch, nrch+nrcv) + + reso = self._const.ACCGAIN_RESO + + if self._invrespmat_normmode == self._const.GlobIndiv.Global: + maxval = _np.amax(abs(invmat)) + gain_h = _np.ceil(maxval * loop_gain_h / reso) * reso + if gain_h != 0: + norm_h = gain_h / loop_gain_h + coeffs[slch, :] = invmat[slch, :] / norm_h + gains[slch] = gain_h * _np.ones(nrch) + gain_v = _np.ceil(maxval * loop_gain_v / reso) * reso + if gain_v != 0: + norm_v = gain_v / loop_gain_v + coeffs[slcv, :] = invmat[slcv, :] / norm_v + gains[slcv] = gain_v * _np.ones(nrcv) + elif self._invrespmat_normmode == self._const.GlobIndiv.Individual: + maxval = _np.amax(abs(invmat), axis=1) + gains[slch] = _np.ceil(maxval[slch] * loop_gain_h / reso) * reso + gains[slcv] = _np.ceil(maxval[slcv] * loop_gain_v / reso) * reso + norm = _np.zeros(self._const.nr_chcv) + norm[slch] = gains[slch] / loop_gain_h + norm[slcv] = gains[slcv] / loop_gain_v + idcs = norm > 0 + coeffs[idcs] = invmat[idcs] / norm[idcs][:, None] # handle FOFB BPM ordering nrbpm = self._const.nr_bpms @@ -1243,9 +1270,13 @@ def _check_configs(self): if not self._corrs_dev.check_fofbacc_gain(self._psgains): value = _updt_bit(value, 5, 1) # AccSatLimsSynced - lim = self._corr_maxacccurr - if not self._corrs_dev.check_fofbacc_satmax(lim) or \ - not self._corrs_dev.check_fofbacc_satmin(-lim): + chn, chl = self._const.ch_names, self._ch_maxacccurr + cvn, cvl = self._const.cv_names, self._cv_maxacccurr + isok = self._corrs_dev.check_fofbacc_satmax(chl, psnames=chn) + isok &= self._corrs_dev.check_fofbacc_satmin(-chl, psnames=chn) + isok &= self._corrs_dev.check_fofbacc_satmax(cvl, psnames=cvn) + isok &= self._corrs_dev.check_fofbacc_satmin(-cvl, psnames=cvn) + if not isok: value = _updt_bit(value, 6, 1) else: value = 0b1111111 From 46343e1018e76cde38fd8ad4eb807a9c92875b78 Mon Sep 17 00:00:00 2001 From: Ana Clara Oliveira Date: Fri, 14 Oct 2022 17:08:02 -0300 Subject: [PATCH 04/10] fofb.MNT: return DCC TimeFrameLen default value to 5000 --- 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 b8daa71e4..79b37ff45 100644 --- a/siriuspy/siriuspy/devices/fofb.py +++ b/siriuspy/siriuspy/devices/fofb.py @@ -239,7 +239,7 @@ class FamFOFBControllers(_Devices): """Family of FOFBCtrl and related BPM devices.""" DEF_TIMEOUT = 10 # [s] - DEF_DCC_TIMEFRAMELEN = 6000 + DEF_DCC_TIMEFRAMELEN = 5000 DEF_BPMTRIG_RCVSRC = 0 DEF_BPMTRIG_RCVIN = 5 BPM_TRIGS_IDS = [1, 2, 20] From 4891891b2f9ae4b404dba22040ed3c42293f7a95 Mon Sep 17 00:00:00 2001 From: Ana Clara Oliveira Date: Fri, 14 Oct 2022 17:35:05 -0300 Subject: [PATCH 05/10] fofb.MNT: cleanup code --- siriuspy/siriuspy/devices/fofb.py | 3 +-- siriuspy/siriuspy/fofb/csdev.py | 8 ++++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/siriuspy/siriuspy/devices/fofb.py b/siriuspy/siriuspy/devices/fofb.py index 79b37ff45..be0d44274 100644 --- a/siriuspy/siriuspy/devices/fofb.py +++ b/siriuspy/siriuspy/devices/fofb.py @@ -262,8 +262,7 @@ def __init__(self): self._ctl_dccs[ctl + ':' + dcc] = FOFBCtrlDCC(ctl, dcc) # BPM DCCs and triggers bpmnames = _BPMSearch.get_names({'sec': 'SI', 'dev': 'BPM'}) - bpmids = _np.roll( - _np.array([i-1 if i % 2 == 1 else i for i in range(NR_BPM)]), -1) + bpmids = [((i + 1) // 2) * 2 % 160 for i in range(NR_BPM)] self._bpm_dccs, self._bpm_trgs, self._bpm_ids = dict(), dict(), dict() for idx, bpm in enumerate(bpmnames): self._bpm_ids[bpm] = bpmids[idx] diff --git a/siriuspy/siriuspy/fofb/csdev.py b/siriuspy/siriuspy/fofb/csdev.py index 3866200ad..1db587b8e 100644 --- a/siriuspy/siriuspy/fofb/csdev.py +++ b/siriuspy/siriuspy/fofb/csdev.py @@ -174,9 +174,9 @@ def get_hlfofb_database(self): # FOFB Controllers 'TimeFrameLen-SP': { - 'type': 'int', 'value': 5000, 'lolim': 3000, 'hilim': 7500,}, + 'type': 'int', 'value': 5000, 'lolim': 3000, 'hilim': 7500}, 'TimeFrameLen-RB': { - 'type': 'int', 'value': 5000, 'lolim': 3000, 'hilim': 7500,}, + 'type': 'int', 'value': 5000, 'lolim': 3000, 'hilim': 7500}, 'FOFBCtrlStatus-Mon': {'type': 'int', 'value': 0b1111111}, 'FOFBCtrlStatusLabels-Cte': { 'type': 'string', 'count': len(_et.STS_LBLS_FOFBCTRL), @@ -186,7 +186,7 @@ def get_hlfofb_database(self): 'FOFBCtrlConfTFrameLen-Cmd': {'type': 'int', 'value': 0}, 'FOFBCtrlConfBPMLogTrg-Cmd': {'type': 'int', 'value': 0}, - # Kicks and Kick buffer configuration: + # Kicks and Kick buffer configuration 'KickBufferSize-SP': { 'type': 'float', 'value': self.DEF_KICK_BUFFER_SIZE, 'prec': 0, 'lolim': 1, 'hilim': 1000, @@ -202,7 +202,7 @@ def get_hlfofb_database(self): 'type': 'float', 'unit': 'urad', 'count': self.nr_cv, 'value': self.nr_cv*[0]}, - # Reference Orbit (same order os SOFB) + # Reference Orbit (same order of SOFB) 'RefOrbX-SP': { 'type': 'float', 'unit': 'um', 'count': self.nr_bpms, 'value': self.nr_bpms*[0]}, From 52b66f018ead2969354c60a172f94e8b6ade0de3 Mon Sep 17 00:00:00 2001 From: Ana Clara Oliveira Date: Fri, 14 Oct 2022 17:35:28 -0300 Subject: [PATCH 06/10] fofb.MNT: return scan frequency to 1Hz --- siriuspy/siriuspy/fofb/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/siriuspy/siriuspy/fofb/main.py b/siriuspy/siriuspy/fofb/main.py index 425116aef..7def4699b 100644 --- a/siriuspy/siriuspy/fofb/main.py +++ b/siriuspy/siriuspy/fofb/main.py @@ -21,7 +21,7 @@ class App(_Callback): """High Level FOFB main application.""" - SCAN_FREQUENCY = 0.5 # [Hz] + SCAN_FREQUENCY = 1 # [Hz] def __init__(self, tests=False): """Class constructor.""" From df6b495ad86485edeb3173ce4b0ee101beb60a78 Mon Sep 17 00:00:00 2001 From: Ana Clara Oliveira Date: Fri, 14 Oct 2022 17:37:53 -0300 Subject: [PATCH 07/10] fofb.MNT: remove unnecessary timeouts --- siriuspy/siriuspy/fofb/main.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/siriuspy/siriuspy/fofb/main.py b/siriuspy/siriuspy/fofb/main.py index 7def4699b..f8433add9 100644 --- a/siriuspy/siriuspy/fofb/main.py +++ b/siriuspy/siriuspy/fofb/main.py @@ -112,10 +112,7 @@ def __init__(self, tests=False): self._llfofb_dev = _FamFOFBCtrls() - self._sisofb_dev.wait_for_connection(self._const.DEF_TIMEWAIT) self._corrs_dev.wait_for_connection(self._const.DEF_TIMEWAIT) - self._rf_dev.wait_for_connection(self._const.DEF_TIMEWAIT) - self._llfofb_dev.wait_for_connection(self._const.DEF_TIMEWAIT) havebeam_pvname = _PVName( 'SI-Glob:AP-CurrInfo:StoredEBeam-Mon').substitute( @@ -558,7 +555,8 @@ def set_timeframelen(self, value): self._time_frame_len = value self._update_log(f'Setting TimeFrameLen to {value}...') - self._llfofb_dev.set_time_frame_len(value=self._time_frame_len) + self._llfofb_dev.set_time_frame_len( + value=self._time_frame_len, timeout=self._const.DEF_TIMEWAIT) self._update_log('...done!') self.run_callbacks('TimeFrameLen-RB', self._time_frame_len) From 35cad7c2432835cd128d60bb3d16e3b9bb09a0f2 Mon Sep 17 00:00:00 2001 From: Ana Clara Oliveira Date: Fri, 14 Oct 2022 17:39:10 -0300 Subject: [PATCH 08/10] fofb.ENH: improve loop state thread --- siriuspy/siriuspy/fofb/main.py | 49 ++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/siriuspy/siriuspy/fofb/main.py b/siriuspy/siriuspy/fofb/main.py index f8433add9..db1fb3035 100644 --- a/siriuspy/siriuspy/fofb/main.py +++ b/siriuspy/siriuspy/fofb/main.py @@ -335,15 +335,8 @@ def _thread_set_loop_state(self, value): self._calc_corrs_coeffs(log=False) # set and wait corrector gains and coeffs to zero self._set_corrs_coeffs(log=False) - _t0 = _time.time() - while _time.time() - _t0 < self._const.DEF_TIMEOUT: - _time.sleep(self._const.DEF_TIMESLEEP) - if self._corrs_dev.check_invrespmat_row(self._pscoeffs) and \ - self._corrs_dev.check_fofbacc_gain(self._psgains): - break - else: - self._update_log('ERR:Timed out waiting for correctors to') - self._update_log('ERR:implement gains and coefficients.') + self._update_log('Waiting for coefficients and gains...') + if not self._wait_coeffs_and_gains(): self.run_callbacks('LoopState-Sel', self._loop_state) return @@ -368,16 +361,10 @@ def _thread_set_loop_state(self, value): self._update_log('LoopGain ramp up finished!') else: # opening the loop - if self.havebeam: - # do ramp down - self._update_log('Starting Loop Gain ramp down...') - if self._do_loop_gain_ramp(ramp='down'): - self._update_log('Loop Gain ramp down finished!') - else: - self._loop_gain_mon = 0.0 - self.run_callbacks('LoopGain-Mon', self._loop_gain_mon) - self._calc_corrs_coeffs() - self._set_corrs_coeffs() + # do ramp down + self._update_log('Starting Loop Gain ramp down...') + if self._do_loop_gain_ramp(ramp='down'): + self._update_log('Loop Gain ramp down finished!') if self._check_abort_thread(): return @@ -400,6 +387,12 @@ def _do_loop_gain_ramp(self, ramp='up'): for i in range(self._const.LOOPGAIN_RMP_NPTS): if not self.havebeam: self._update_log('ERR: Do not have stored beam. Aborted.') + self._loop_gain_mon_h, self._loop_gain_mon_v = 0, 0 + self.run_callbacks('LoopGainH-Mon', self._loop_gain_mon_h) + self.run_callbacks('LoopGainV-Mon', self._loop_gain_mon_v) + self._calc_corrs_coeffs() + self._set_corrs_coeffs() + self._wait_coeffs_and_gains() return False if self._check_abort_thread(): return False @@ -413,9 +406,25 @@ def _do_loop_gain_ramp(self, ramp='up'): f'H={ydata_h[i]:.3f}, V={ydata_v[i]:.3f}') self._calc_corrs_coeffs(log=False) self._set_corrs_coeffs(log=False) - _time.sleep(1/self._const.LOOPGAIN_RMP_FREQ) + _t0 = _time.time() + if not self._wait_coeffs_and_gains(): + return False + _td = 1/self._const.LOOPGAIN_RMP_FREQ - (_time.time() - _t0) + if _td > 0: + _time.sleep(_td) return True + def _wait_coeffs_and_gains(self): + _t0 = _time.time() + while _time.time() - _t0 < self._const.DEF_TIMEOUT: + _time.sleep(self._const.DEF_TIMESLEEP) + if self._corrs_dev.check_invrespmat_row(self._pscoeffs) and \ + self._corrs_dev.check_fofbacc_gain(self._psgains): + return True + self._update_log('ERR:Timed out waiting for correctors to') + self._update_log('ERR:implement gains and coefficients.') + return False + def _check_abort_thread(self): if self._abort_thread: self._update_log('WARN: Loop state thread aborted.') From b6e7c2ba9c13ff08565e37284c24eb03786d1a91 Mon Sep 17 00:00:00 2001 From: Ana Clara Oliveira Date: Mon, 17 Oct 2022 08:17:58 -0300 Subject: [PATCH 09/10] Update version to 2.56.0 --- siriuspy/siriuspy/VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/siriuspy/siriuspy/VERSION b/siriuspy/siriuspy/VERSION index c2576f162..5f46e11ee 100644 --- a/siriuspy/siriuspy/VERSION +++ b/siriuspy/siriuspy/VERSION @@ -1 +1 @@ -2.55.0 +2.56.0 From df9474d040463c5ba00ae9d682609ec02fa5bd36 Mon Sep 17 00:00:00 2001 From: Ana Clara Oliveira Date: Mon, 17 Oct 2022 09:15:14 -0300 Subject: [PATCH 10/10] fofb.MNT: use same unit in LoopGain PVs --- siriuspy/siriuspy/fofb/csdev.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/siriuspy/siriuspy/fofb/csdev.py b/siriuspy/siriuspy/fofb/csdev.py index 1db587b8e..012e39bd2 100644 --- a/siriuspy/siriuspy/fofb/csdev.py +++ b/siriuspy/siriuspy/fofb/csdev.py @@ -116,25 +116,25 @@ def get_hlfofb_database(self): 'LoopGainH-SP': { 'type': 'float', 'value': 1, 'prec': 4, 'lolim': -2**3, 'hilim': 2**3-1, - 'unit': 'Horizontal FOFB pre-accumulator gain.'}, + 'unit': 'FOFB pre-accumulator gain.'}, 'LoopGainH-RB': { 'type': 'float', 'value': 1, 'prec': 4, 'lolim': -2**3, 'hilim': 2**3-1, - 'unit': 'Horizontal FOFB pre-accumulator gain.'}, + 'unit': 'FOFB pre-accumulator gain.'}, 'LoopGainH-Mon': { 'type': 'float', 'value': 0, 'prec': 4, - 'unit': 'Horizontal FOFB pre-accumulator gain.'}, + 'unit': 'FOFB pre-accumulator gain.'}, 'LoopGainV-SP': { 'type': 'float', 'value': 1, 'prec': 4, 'lolim': -2**3, 'hilim': 2**3-1, - 'unit': 'Vertical FOFB pre-accumulator gain.'}, + 'unit': 'FOFB pre-accumulator gain.'}, 'LoopGainV-RB': { 'type': 'float', 'value': 1, 'prec': 4, 'lolim': -2**3, 'hilim': 2**3-1, - 'unit': 'Vertical FOFB pre-accumulator gain.'}, + 'unit': 'FOFB pre-accumulator gain.'}, 'LoopGainV-Mon': { 'type': 'float', 'value': 0, 'prec': 4, - 'unit': 'Vertical FOFB pre-accumulator gain.'}, + 'unit': 'FOFB pre-accumulator gain.'}, # Correctors 'CHPosS-Cte': {