Skip to content

Commit

Permalink
Merge pull request #1089 from lnls-sirius/add-wfmoffset-strengths
Browse files Browse the repository at this point in the history
Add wfmoffset strengths
  • Loading branch information
anacso17 authored Jun 18, 2024
2 parents 4891a16 + 220f254 commit d9f0c45
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 52 deletions.
86 changes: 51 additions & 35 deletions siriuspy/siriuspy/pwrsupply/beaglebone.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class BeagleBone:
aproppriate device.
"""

_STRENS_CUR = {'Energy', 'Kick', 'KL', 'SL'}
_STRENS_WFM = {'WfmOffset' + stren for stren in _STRENS_CUR}

def __init__(self, controllers, databases):
"""Init object.
Expand Down Expand Up @@ -115,20 +118,18 @@ def write(self, devname, field, value):
if not self._initialized:
return None

if field in {'Energy-SP', 'Kick-SP', 'KL-SP', 'SL-SP'}:
fnsp = field.replace('-SP', '')
if fnsp in BeagleBone._STRENS_CUR or fnsp in BeagleBone._STRENS_WFM:
streconv = self._streconvs[devname]
curr = streconv.conv_strength_2_current(value)
priority_pvs = self._controllers[devname].write(
devname, 'Current-SP', curr)
pv_sp = 'WfmOffset-SP' if 'WfmOffset' in field else 'Current-SP'
priority_pvs = \
self._controllers[devname].write(devname, pv_sp, curr)
else:
priority_pvs = self._controllers[devname].write(
devname, field, value)
return priority_pvs

def get_strength_limits(self, devname):
"""Return strength lower and upper limits."""
return self._strelims[devname]

def check_connected(self, devname):
"""Check wether device is connected."""
return self._controllers[devname].check_connected(devname)
Expand All @@ -137,8 +138,8 @@ def check_connected_strength(self, devname):
"""Check connection with PVs for strength calc."""
return self._streconnected[devname]

def strength_name(self, devname):
"""Return strength name."""
def strength_names(self, devname):
"""Return strength names."""
return self._strenames[devname]

def strength_limits(self, devname):
Expand Down Expand Up @@ -179,13 +180,13 @@ def _get_strength_names(self):
strenames = dict()
for psname, dbase in self._databases.items():
if 'Energy-SP' in dbase:
strenames[psname] = 'Energy'
strenames[psname] = ('Energy', 'WfmOffsetEnergy')
elif 'Kick-SP' in dbase:
strenames[psname] = 'Kick'
strenames[psname] = ('Kick', 'WfmOffsetKick')
elif 'KL-SP' in dbase:
strenames[psname] = 'KL'
strenames[psname] = ('KL', 'WfmOffsetKL')
elif 'SL-SP' in dbase:
strenames[psname] = 'SL'
strenames[psname] = ('SL', 'WfmOffsetSL')
else:
strenames[psname] = None
return strenames
Expand Down Expand Up @@ -225,27 +226,42 @@ def _update_strengths(self, psname):
strelims = self._strelims[psname]
mirror = self._dev2mirror[psname]
dbase = self._databases[psname]
curr0 = mirror[psname + ':Current-SP']
curr1 = mirror[psname + ':Current-RB']
curr2 = mirror[psname + ':CurrentRef-Mon']
curr3 = mirror[psname + ':Current-Mon']
curr4 = dbase['Current-SP']['lolo']
curr5 = dbase['Current-SP']['hihi']
currs = (curr0, curr1, curr2, curr3, curr4, curr5)
strengths = streconv.conv_current_2_strength(currents=currs)
if strengths is None or None in strengths:
self._streconnected[psname] = False
else:
self._streconnected[psname] = True
propname = psname + ':' + self._strenames[psname]
mirror[propname + '-SP'] = strengths[0]
mirror[propname + '-RB'] = strengths[1]
mirror[propname + 'Ref-Mon'] = strengths[2]
mirror[propname + '-Mon'] = strengths[3]
# update strength limits
if strengths[4] <= strengths[5]:
strelims[0], strelims[1] = strengths[4], strengths[5]
else:
strelims[0], strelims[1] = strengths[5], strengths[4]
self._streconnected[psname] = True
for strename in self._strenames[psname]:
if strename in BeagleBone._STRENS_CUR:
curr0 = mirror[psname + ':Current-SP']
curr1 = mirror[psname + ':Current-RB']
curr2 = mirror[psname + ':CurrentRef-Mon']
curr3 = mirror[psname + ':Current-Mon']
curr4 = dbase['Current-SP']['lolo']
curr5 = dbase['Current-SP']['hihi']
currs = (curr0, curr1, curr2, curr3, curr4, curr5)
strengths = streconv.conv_current_2_strength(currents=currs)
if strengths is None or None in strengths:
self._streconnected[psname] = False
else:
propname = psname + ':' + strename
mirror[propname + '-SP'] = strengths[0]
mirror[propname + '-RB'] = strengths[1]
mirror[propname + 'Ref-Mon'] = strengths[2]
mirror[propname + '-Mon'] = strengths[3]
# update strength limits
if strengths[4] <= strengths[5]:
strelims[0], strelims[1] = strengths[4], strengths[5]
else:
strelims[0], strelims[1] = strengths[5], strengths[4]
elif strename in BeagleBone._STRENS_WFM:
curr0 = mirror[psname + ':WfmOffset-SP']
curr1 = mirror[psname + ':WfmOffset-RB']
curr2 = dbase['WfmOffset-SP']['lolo']
curr3 = dbase['WfmOffset-SP']['hihi']
currs = (curr0, curr1, curr2, curr3)
strengths = streconv.conv_current_2_strength(currents=currs)
if strengths is None or None in strengths:
self._streconnected[psname] = False
else:
propname = psname + ':' + strename
mirror[propname + '-SP'] = strengths[0]
mirror[propname + '-RB'] = strengths[1]
# t1_ = _time.time()
# print('update_strengths: {:.3f}'.format(1000*(t1_-t0_)))
19 changes: 18 additions & 1 deletion siriuspy/siriuspy/pwrsupply/csdev.py
Original file line number Diff line number Diff line change
Expand Up @@ -1056,7 +1056,8 @@ def _get_ps_common_propty_database():
'Reset-Cmd': {'type': 'int', 'value': 0, 'unit': 'count'},
# Wfm
'WfmSelected-Mon': {
'type': 'int', 'value': 0, 'unit': 'wfmselected'},
'type': 'int', 'value': DEFAULT_WFM_SELECTED ,
'unit': 'wfmselected'},
'WfmSyncMode-Sel': {
'type': 'enum', 'enums': _et.WFMREF_SYNCMODE,
'value': _ConstPSBSMP.E_WFMREFSYNC_ONESHOT},
Expand Down Expand Up @@ -3150,6 +3151,10 @@ def _insert_strengths(database, pstype):
'type': 'float', 'value': 0.0, 'prec': prec_kl, 'unit': '1/m'}
database['KL-Mon'] = {
'type': 'float', 'value': 0.0, 'prec': prec_kl, 'unit': '1/m'}
database['WfmOffsetKL-SP'] = {
'type': 'float', 'value': 0.0, 'prec': prec_kl, 'unit': '1/m'}
database['WfmOffsetKL-RB'] = {
'type': 'float', 'value': 0.0, 'prec': prec_kl, 'unit': '1/m'}
elif magfunc == 'sextupole':
database['SL-SP'] = {
'type': 'float', 'value': 0.0, 'prec': prec_sl, 'unit': '1/m^2'}
Expand All @@ -3159,6 +3164,10 @@ def _insert_strengths(database, pstype):
'type': 'float', 'value': 0.0, 'prec': prec_sl, 'unit': '1/m^2'}
database['SL-Mon'] = {
'type': 'float', 'value': 0.0, 'prec': prec_sl, 'unit': '1/m^2'}
database['WfmOffsetSL-SP'] = {
'type': 'float', 'value': 0.0, 'prec': prec_sl, 'unit': '1/m^2'}
database['WfmOffsetSL-RB'] = {
'type': 'float', 'value': 0.0, 'prec': prec_sl, 'unit': '1/m^2'}
elif magfunc == 'dipole':
database['Energy-SP'] = {
'type': 'float', 'value': 0.0, 'prec': prec_energy, 'unit': 'GeV'}
Expand All @@ -3168,6 +3177,10 @@ def _insert_strengths(database, pstype):
'type': 'float', 'value': 0.0, 'prec': prec_energy, 'unit': 'GeV'}
database['Energy-Mon'] = {
'type': 'float', 'value': 0.0, 'prec': prec_energy, 'unit': 'GeV'}
database['WfmOffsetEnergy-SP'] = {
'type': 'float', 'value': 0.0, 'prec': prec_energy, 'unit': 'GeV'}
database['WfmOffsetEnergy-RB'] = {
'type': 'float', 'value': 0.0, 'prec': prec_energy, 'unit': 'GeV'}
elif magfunc in {'corrector-horizontal', 'corrector-vertical'}:
database['Kick-SP'] = {
'type': 'float', 'value': 0.0, 'prec': prec_kick, 'unit': 'urad'}
Expand All @@ -3177,6 +3190,10 @@ def _insert_strengths(database, pstype):
'type': 'float', 'value': 0.0, 'prec': prec_kick, 'unit': 'urad'}
database['Kick-Mon'] = {
'type': 'float', 'value': 0.0, 'prec': prec_kick, 'unit': 'urad'}
database['WfmOffsetKick-SP'] = {
'type': 'float', 'value': 0.0, 'prec': prec_kick, 'unit': 'urad'}
database['WfmOffsetKick-RB'] = {
'type': 'float', 'value': 0.0, 'prec': prec_kick, 'unit': 'urad'}

if pstype.startswith('li-'):
if 'KickRef-Mon' in database:
Expand Down
27 changes: 14 additions & 13 deletions siriuspy/siriuspy/pwrsupply/pructrl/prucontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def wfm_update(self, device_ids, interval=None):
"""Queue update wfm and scope curves."""
if isinstance(device_ids, int):
device_ids = (device_ids, )
operation = (self._bsmp_update_wfm, (device_ids, interval, ))
operation = (self.bsmp_update_wfm, (device_ids, interval, ))
self._queue.put(operation, block=False)
return True

Expand Down Expand Up @@ -359,7 +359,7 @@ def sofb_current_set(self, value):
pass

# execute SOFB setpoint
self._bsmp_update_sofb_setpoint(value)
self.bsmp_update_sofb_setpoint(value)

return True

Expand Down Expand Up @@ -393,15 +393,15 @@ def sofb_update_variables_state(self):
dev_id = self._device_ids[self._sofb_update_dev_idx]

# update variables state mirror for selected power supply
self._bsmp_update_variables(dev_id)
self.bsmp_update_variables(dev_id)

# --- scan and process loop methods ---

def bsmp_scan(self):
"""Run scan one."""
# select devices and variable group, defining the read group
# operation to be performed
operation = (self._bsmp_update, ())
operation = (self.bsmp_update, ())
if self._queue.empty() or operation != self._queue.last_operation:
self._queue.put(operation, block=False)
else:
Expand Down Expand Up @@ -587,23 +587,24 @@ def _bsmp_init_devices(self):
dt_ = _time() - t0_
print(fmt.format('bsmp_init_devices', 'bufsample_disable', 1e3*dt_))

def _bsmp_update(self):

def bsmp_update(self):
"""."""
try:
# update variables
self._bsmp_update_variables()
self.bsmp_update_variables()

# update device wfm curves cyclically
if self._scope_update:
self._scope_update_dev_idx = \
(self._scope_update_dev_idx + 1) % len(self._device_ids)
dev_id = self._device_ids[self._scope_update_dev_idx]
self._bsmp_update_wfm(dev_id)
self.bsmp_update_wfm(dev_id)

except _socket_timeout:
print('!!! {} : socket timeout !!!'.format(_get_timestamp()))

def _bsmp_update_variables(self, dev_id=None):
def bsmp_update_variables(self, dev_id=None):
"""."""
if dev_id is None:
psupplies = self._psupplies.values()
else:
Expand All @@ -621,7 +622,7 @@ def _bsmp_update_variables(self, dev_id=None):
f'it took {dt_*1000:.3f} ms in bsmp_update_variables.'
)

def _bsmp_update_wfm(self, device_id):
def bsmp_update_wfm(self, device_id):
"""Read curve from devices."""
psupplies = self._psupplies

Expand All @@ -640,7 +641,7 @@ def _bsmp_update_wfm(self, device_id):
# stores updated psupplies dict
self._psupplies = psupplies # atomic operation

def _bsmp_update_sofb_setpoint(self, value):
def bsmp_update_sofb_setpoint(self, value):

# execute sofb current setpoint
self._udc.sofb_current_set(value)
Expand All @@ -649,10 +650,10 @@ def _bsmp_update_sofb_setpoint(self, value):
self._udc.sofb_update()

# # update all other device parameters
# self._bsmp_update()
# self.bsmp_update()

# print('{:<30s} : {:>9.3f} ms'.format(
# 'PRUC._bsmp_update_sofb_setpoint (end)', 1e3*(_time() % 1)))
# 'PRUC.bsmp_update_sofb_setpoint (end)', 1e3*(_time() % 1)))

def _bsmp_wfmref_write(self, device_ids, curve):
"""Write wfmref curve to devices."""
Expand Down
19 changes: 17 additions & 2 deletions siriuspy/siriuspy/pwrsupply/psctrl/pscontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ class PSController:
'Energy-SP', 'Energy-RB', 'EnergyRef-Mon', 'Energy-Mon',
'Kick-SP', 'Kick-RB', 'KickRef-Mon', 'Kick-Mon',
'KL-SP', 'KL-RB', 'KLRef-Mon', 'KL-Mon',
'SL-SP', 'SL-RB', 'SLRef-Mon', 'SL-Mon'}
'SL-SP', 'SL-RB', 'SLRef-Mon', 'SL-Mon',
'WfmOffsetKick-SP', 'WfmOffsetKick-RB',
'WfmOffsetKL-SP', 'WfmOffsetKL-RB',
'WfmOffsetSL-SP', 'WfmOffsetSL-RB',
'WfmOffsetEnergy-SP', 'WfmOffsetEnergy-RB',
}

def __init__(self, readers, writers,
pru_controller, devname2devid):
Expand Down Expand Up @@ -51,6 +56,16 @@ def fields(self):
"""Field of ps controller."""
return self._fields

@property
def readers(self):
"""Return controller readers."""
return self._readers

@property
def writers(self):
"""Return controller writers."""
return self._writers

def read(self, devname, field):
"""Read pv value."""
pvname = devname + ':' + field
Expand Down Expand Up @@ -154,7 +169,7 @@ def _update_setpoints(self, devname):
"""."""
self.read_all_fields(devname)
self.init_setpoints(devname)

@staticmethod
def _get_readback_field(field):
# NOTE: to be updated
Expand Down
2 changes: 1 addition & 1 deletion siriuspy/siriuspy/pwrsupply/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,4 +348,4 @@ def update_bbb(bbb):
for psname in bbb.psnames:
controller = bbb.controllers[psname]
pruc = controller.pru_controller
pruc._bsmp_update()
pruc.bsmp_update()

0 comments on commit d9f0c45

Please sign in to comment.