Skip to content

Commit

Permalink
Merge pull request #853 from lnls-sirius/fix-sofb-again
Browse files Browse the repository at this point in the history
Fix fix SOFB
  • Loading branch information
anacso17 authored Oct 17, 2022
2 parents 23be762 + ebae8e9 commit 4323ee5
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 23 deletions.
2 changes: 1 addition & 1 deletion siriuspy/siriuspy/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.56.0
2.56.1
73 changes: 60 additions & 13 deletions siriuspy/siriuspy/devices/fofb.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,8 @@ def linkpartners_connected(self):
if 'FMC' not in dev.dccname:
continue
ctl = _PVName(dcc).device_name
if not dev.linkpartners & self._ctl_part[ctl]:
nrpart = len(self._ctl_part[ctl])
if not len(dev.linkpartners & self._ctl_part[ctl]) == nrpart:
return False
return True

Expand Down Expand Up @@ -830,13 +831,17 @@ class DEVICES:

_properties = (
'LoopState-Sel', 'LoopState-Sts',
'LoopGain-SP', 'LoopGain-RB', 'LoopGain-Mon',
'CorrStatus-Mon', 'CorrConfig-Cmd',
'LoopGainH-SP', 'LoopGainH-RB', 'LoopGainH-Mon',
'LoopGainV-SP', 'LoopGainV-RB', 'LoopGainV-Mon',
'CorrStatus-Mon', 'CorrConfig-Cmd', 'CorrSetCurrZero-Cmd',
'CorrSetOpModeManual-Cmd', 'CorrSetAccFreezeDsbl-Cmd',
'CorrSetAccFreezeEnbl-Cmd', 'CorrSetAccClear-Cmd',
'CHAccSatMax-SP', 'CHAccSatMax-RB',
'CVAccSatMax-SP', 'CVAccSatMax-RB',
'FOFBCtrlStatus-Mon', 'FOFBCtrlSyncNet-Cmd', 'FOFBCtrlSyncRefOrb-Cmd',
'FOFBCtrlConfTFrameLen-Cmd', 'FOFBCtrlConfBPMLogTrg-Cmd',
'KickBufferSize-SP', 'KickBufferSize-RB', 'KickCH-Mon', 'KickCV-Mon',
'KickBufferSize-SP', 'KickBufferSize-RB', 'KickBufferSize-Mon',
'KickCH-Mon', 'KickCV-Mon',
'RefOrbX-SP', 'RefOrbX-RB', 'RefOrbY-SP', 'RefOrbY-RB',
'RefOrbHwX-Mon', 'RefOrbHwY-Mon',
'BPMXEnblList-SP', 'BPMXEnblList-RB',
Expand Down Expand Up @@ -888,18 +893,32 @@ def loop_state(self, value):
self['LoopState-Sel'] = value

@property
def loop_gain(self):
"""Loop gain."""
return self['LoopGain-RB']
def loop_gain_h(self):
"""Loop gain H."""
return self['LoopGainH-RB']

@loop_gain.setter
def loop_gain(self, value):
self['LoopGain-SP'] = value
@loop_gain_h.setter
def loop_gain_h(self, value):
self['LoopGainH-SP'] = value

@property
def loop_gain_mon(self):
"""Implemented loop gain."""
return self['LoopGain-Mon']
def loop_gain_h_mon(self):
"""Implemented horizontal loop gain."""
return self['LoopGainH-Mon']

@property
def loop_gain_v(self):
"""Loop gain V."""
return self['LoopGainV-RB']

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

@property
def loop_gain_v_mon(self):
"""Implemented vertical loop gain."""
return self['LoopGainV-Mon']

@property
def corr_status(self):
Expand Down Expand Up @@ -931,6 +950,29 @@ def cmd_corr_accclear(self):
self['CorrSetAccClear-Cmd'] = 1
return True

def cmd_corr_set_current_zero(self):
"""Command to set correctors current to zero."""
self['CorrSetCurrZero-Cmd'] = 1
return True

@property
def ch_accsatmax(self):
"""CH accumulator maximum saturation limit."""
return self['CHAccSatMax-RB']

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

@property
def cv_accsatmax(self):
"""CH accumulator maximum saturation limit."""
return self['CVAccSatMax-RB']

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

@property
def fofbctrl_status(self):
"""FOFB controller status."""
Expand All @@ -956,6 +998,11 @@ def cmd_fofbctrl_conf_bpmlogtrig(self):
self['FOFBCtrlConfBPMLogTrg-Cmd'] = 1
return True

@property
def kick_buffer_size_mon(self):
"""Return actual kicks buffer size."""
return self['KickBufferSize-Mon']

@property
def kick_buffer_size(self):
"""Return kicks buffer size."""
Expand Down
3 changes: 2 additions & 1 deletion siriuspy/siriuspy/devices/injsys.py
Original file line number Diff line number Diff line change
Expand Up @@ -967,8 +967,9 @@ def _do_delta_posang(self, delta):
if self.posang.need_ref_update:
self.posang.cmd_update_reference()
_time.sleep(InjSysPUModeHandler._DEF_SLEEP)
desval = self.posang.delta_angx + delta
self.posang.delta_angx += delta
if not self._wait(self.posang, 'delta_angx', delta):
if not self._wait(self.posang, 'delta_angx', desval):
self._update_status('ERR:Could not do delta AngX.')
return False
return True
Expand Down
6 changes: 4 additions & 2 deletions siriuspy/siriuspy/devices/pwrsupply.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,11 +368,13 @@ def cycle_aux_param(self):
- AuxParams[2] --> rampdown time [s]
- AuxParams[3] --> not used
"""
return self['CycleAuxParam-RB']
value = self['CycleAuxParam-RB']
if value is not None:
return value.copy()
return None

@cycle_aux_param.setter
def cycle_aux_param(self, value):
"""."""
self['CycleAuxParam-SP'] = value

@property
Expand Down
4 changes: 4 additions & 0 deletions siriuspy/siriuspy/fofb/csdev.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ def get_hlfofb_database(self):
'type': 'float', 'value': self.DEF_KICK_BUFFER_SIZE, 'prec': 0,
'lolim': 1, 'hilim': 1000,
'unit': 'Size of the buffer to calculate kicks average.'},
'KickBufferSize-Mon': {
'type': 'float', 'value': self.DEF_KICK_BUFFER_SIZE, 'prec': 0,
'lolim': 1, 'hilim': 1000,
'unit': 'Actual buffer size used to calculate kicks average.'},
'KickCH-Mon': {
'type': 'float', 'unit': 'urad', 'count': self.nr_ch,
'value': self.nr_ch*[0]},
Expand Down
50 changes: 47 additions & 3 deletions siriuspy/siriuspy/fofb/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ def init_database(self):
'FOFBCtrlConfBPMLogTrg-Cmd', self._fofbctrl_confbpmlogtrg_count)
self.run_callbacks('KickBufferSize-SP', self._kick_buffer_size)
self.run_callbacks('KickBufferSize-RB', self._kick_buffer_size)
self.run_callbacks('KickBufferSize-Mon', self._kick_buffer_size)
self.run_callbacks(
'KickCH-Mon', _np.zeros(self._const.nr_ch, dtype=float))
self.run_callbacks(
Expand Down Expand Up @@ -461,6 +462,8 @@ def set_loopgain(self, plane, value):
def cmd_corr_configure(self, _):
"""Configure corrector command."""
self._update_log('Received configure corrector command...')
if not self._check_corr_connection():
return False

# opmode
self._check_set_corrs_opmode()
Expand All @@ -478,6 +481,8 @@ def cmd_corr_configure(self, _):
def cmd_corr_opmode_manual(self, _):
"""Set all corrector opmode."""
self._update_log('Received set corrector opmode to manual...')
if not self._check_corr_connection():
return False

self._update_log('Setting all corrector opmode to manual...')
self._corrs_dev.set_opmode(self._corrs_dev.OPMODE_STS.manual)
Expand All @@ -491,6 +496,8 @@ def cmd_corr_opmode_manual(self, _):
def cmd_corr_accfreeze_dsbl(self, _):
"""Set all corrector accumulator freeze state to Dsbl."""
self._update_log('Received set corrector AccFreeze to Dsbl...')
if not self._check_corr_connection():
return False

self._update_log('Setting AccFreeze to Dsbl...')
self._corrs_dev.set_fofbacc_freeze(self._const.DsblEnbl.Dsbl)
Expand All @@ -504,6 +511,8 @@ def cmd_corr_accfreeze_dsbl(self, _):
def cmd_corr_accfreeze_enbl(self, _):
"""Set all corrector accumulator freeze state to Enbl."""
self._update_log('Received set corrector AccFreeze to Enbl...')
if not self._check_corr_connection():
return False

self._update_log('Setting AccFreeze to Enbl...')
self._corrs_dev.set_fofbacc_freeze(self._const.DsblEnbl.Enbl)
Expand All @@ -517,6 +526,8 @@ def cmd_corr_accfreeze_enbl(self, _):
def cmd_corr_accclear(self, _):
"""Clear all corrector accumulator."""
self._update_log('Received clear all corrector accumulator...')
if not self._check_corr_connection():
return False

self._update_log('Sending clear accumulator command...')
self._corrs_dev.cmd_fofbacc_clear()
Expand All @@ -530,6 +541,8 @@ def cmd_corr_accclear(self, _):
def cmd_corr_currzero(self, _):
"""Set all corrector current to zero."""
self._update_log('Received set corrector current to zero...')
if not self._check_corr_connection():
return False

self._update_log('Sending all corrector current to zero...')
self._corrs_dev.set_current(0)
Expand All @@ -542,6 +555,8 @@ def cmd_corr_currzero(self, _):

def set_corr_accsatmax(self, device, value):
"""Set device FOFB accumulator saturation limits."""
if not self._check_corr_connection():
return False
if not 0 <= value <= 0.95:
return False

Expand All @@ -559,6 +574,8 @@ def set_corr_accsatmax(self, device, value):

def set_timeframelen(self, value):
"""Set FOFB controllers TimeFrameLen."""
if not self._check_fofbctrl_connection():
return False
if not 3000 <= value <= 7500:
return False

Expand All @@ -574,6 +591,8 @@ def set_timeframelen(self, value):
def cmd_fofbctrl_syncnet(self, _):
"""Sync FOFB net command."""
self._update_log('Received sync FOFB net command...')
if not self._check_fofbctrl_connection():
return False
self._update_log('Checking...')
if not self._llfofb_dev.net_synced:
self._update_log('Syncing FOFB net...')
Expand All @@ -592,6 +611,8 @@ def cmd_fofbctrl_syncnet(self, _):
def cmd_fofbctrl_syncreforb(self, _):
"""Sync FOFB RefOrb command."""
self._update_log('Received sync FOFB RefOrb command...')
if not self._check_fofbctrl_connection():
return False
self._update_log('Checking...')
reforb = _np.hstack([self._reforbhw_x, self._reforbhw_y])
if not self._llfofb_dev.check_reforb(reforb):
Expand All @@ -609,6 +630,8 @@ def cmd_fofbctrl_syncreforb(self, _):
def cmd_fofbctrl_conftframelen(self, _):
"""Configure FOFB controllers TimeFrameLen command."""
self._update_log('Received configure FOFB controllers')
if not self._check_fofbctrl_connection():
return False
self._update_log('TimeFrameLen command... Checking...')
timeframe = self._time_frame_len
if not _np.all(self._llfofb_dev.time_frame_len == timeframe):
Expand All @@ -628,6 +651,8 @@ def cmd_fofbctrl_conftframelen(self, _):
def cmd_fofbctrl_confbpmlogtrg(self, _):
"""Configure BPM logical triggers command."""
self._update_log('Received configure BPM Logical')
if not self._check_fofbctrl_connection():
return False
self._update_log('triggers command... Checking...')
if not self._llfofb_dev.bpm_trigs_configured:
self._update_log('Configuring BPM logical triggers...')
Expand Down Expand Up @@ -667,23 +692,28 @@ def _update_kick_buffer(self, pvname, value, ps_index, **kwargs):
if val is None:
return
self._kick_buffer[ps_index].append(val)
del self._kick_buffer[ps_index][:-self._kick_buffer_size]
buff_size = self._kick_buffer_size if self._loop_state else 1
del self._kick_buffer[ps_index][:-buff_size]

def _update_kicks(self):
kickch, kickcv = [], []
lenb = 0

for i in range(self._const.nr_ch):
buff = self._kick_buffer[i]
lenb = max(len(buff), lenb)
val = _np.mean(buff) if buff else 0.0
kickch.append(val)

for i in range(self._const.nr_ch, self._const.nr_chcv):
buff = self._kick_buffer[i]
lenb = max(len(buff), lenb)
val = _np.mean(buff) if buff else 0.0
kickcv.append(val)

self.run_callbacks('KickCH-Mon', kickch)
self.run_callbacks('KickCV-Mon', kickcv)
self.run_callbacks('KickBufferSize-Mon', lenb)

# --- reference orbit ---

Expand Down Expand Up @@ -843,8 +873,7 @@ def set_invrespmat_normmode(self, value):
def _calc_matrices(self):
self._update_log('Calculating Inverse Matrix...')

if not self._corrs_dev.connected:
self._update_log('ERR:Correctors not connected... aborted.')
if not self._check_corr_connection():
return False

selbpm = self.bpm_enbllist
Expand Down Expand Up @@ -1125,6 +1154,19 @@ def _callback_havebeam(self, value, **kws):

# --- auxiliary corrector and fofbcontroller methods ---

def _check_corr_connection(self):
if self._corrs_dev.connected:
return True
self._update_log('ERR:Correctors not connected... aborted.')
return False

def _check_fofbctrl_connection(self):
if self._llfofb_dev.connected:
return True
self._update_log('ERR:FOFB Controllers not connected...')
self._update_log('ERR:aborted.')
return False

def _check_set_corrs_opmode(self):
"""Check and configure opmode.
Expand Down Expand Up @@ -1222,6 +1264,8 @@ def _set_corrs_coeffs(self, log=True):
"""Set corrector coefficients and gains."""
if log:
self._update_log('Setting corrector gains and coefficients...')
if not self._check_corr_connection():
return False
self._corrs_dev.set_invrespmat_row(self._pscoeffs)
self._corrs_dev.set_fofbacc_gain(self._psgains)
if log:
Expand Down
8 changes: 7 additions & 1 deletion siriuspy/siriuspy/sofb/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,8 @@ def _update_status(self):
self._correctors.status | self._matrix.status | self._orbit.status)
self.run_callbacks('Status-Mon', self._status)

if self.acc != 'SI':
return
# Update PVs related to interaction with FOFB:
fofb_state = self.fofb.connected and self.fofb.loop_state
download = self._download_fofb_kicks and fofb_state
Expand Down Expand Up @@ -1048,7 +1050,11 @@ def _interact_with_fofb_in_apply_kicks(
if self._download_fofb_kicks and fofb.loop_state:
kicks_fofb = _np.r_[fofb.kickch, fofb.kickcv, 0]
dorb = _np.dot(fofb.respmat, kicks_fofb)
dkicks2 = -self.matrix.calc_kicks(dorb)
# NOTE: calc_kicks return the kicks to correct dorb, which means
# that a minus sign is already applied by this method. To negate
# this correction, we need an extra minus sign here:
dkicks2 = self.matrix.calc_kicks(dorb)
dkicks2 *= -1

kicks, dkicks2 = self._process_kicks(
self._ref_corr_kicks+dkicks, dkicks2, apply_gain=False)
Expand Down
5 changes: 3 additions & 2 deletions siriuspy/siriuspy/sofb/orbit.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,8 +701,9 @@ def _synchronize_bpms(self):
bpm.monit_sync_enbl = _csbpm.EnbldDsbld.disabled
bpm.monit1_sync_enbl = _csbpm.EnbldDsbld.disabled

if self.sofb.fofb.connected:
self.sofb.fofb.cmd_sync_net()
if self.acc == 'SI' and self.sofb.fofb.connected:
_time.sleep(0.2)
self.sofb.fofb.cmd_fofbctrl_syncnet()

def set_trig_acq_control(self, value):
"""."""
Expand Down

0 comments on commit 4323ee5

Please sign in to comment.