From eb0e2cbc6096400f1148bc9c958bd2f36f61200f Mon Sep 17 00:00:00 2001 From: Ximenes Rocha Resende Date: Tue, 28 May 2024 15:07:33 -0300 Subject: [PATCH 1/2] Add WfmOffsetKick PV --- siriuspy/siriuspy/pwrsupply/beaglebone.py | 86 +++++++++++-------- siriuspy/siriuspy/pwrsupply/csdev.py | 19 +++- .../pwrsupply/pructrl/prucontroller.py | 27 +++--- .../siriuspy/pwrsupply/psctrl/pscontroller.py | 18 +++- siriuspy/siriuspy/pwrsupply/tests/utils.py | 2 +- 5 files changed, 100 insertions(+), 52 deletions(-) diff --git a/siriuspy/siriuspy/pwrsupply/beaglebone.py b/siriuspy/siriuspy/pwrsupply/beaglebone.py index dd5a806a7..15607210b 100644 --- a/siriuspy/siriuspy/pwrsupply/beaglebone.py +++ b/siriuspy/siriuspy/pwrsupply/beaglebone.py @@ -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. @@ -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) @@ -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): @@ -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 @@ -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_))) diff --git a/siriuspy/siriuspy/pwrsupply/csdev.py b/siriuspy/siriuspy/pwrsupply/csdev.py index ab5c25b9f..8a3117943 100644 --- a/siriuspy/siriuspy/pwrsupply/csdev.py +++ b/siriuspy/siriuspy/pwrsupply/csdev.py @@ -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}, @@ -3148,6 +3149,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'} @@ -3157,6 +3162,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'} @@ -3166,6 +3175,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'} @@ -3175,6 +3188,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: diff --git a/siriuspy/siriuspy/pwrsupply/pructrl/prucontroller.py b/siriuspy/siriuspy/pwrsupply/pructrl/prucontroller.py index cd29daf12..e2396aa58 100644 --- a/siriuspy/siriuspy/pwrsupply/pructrl/prucontroller.py +++ b/siriuspy/siriuspy/pwrsupply/pructrl/prucontroller.py @@ -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 @@ -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 @@ -393,7 +393,7 @@ 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 --- @@ -401,7 +401,7 @@ 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: @@ -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: @@ -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 @@ -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) @@ -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.""" diff --git a/siriuspy/siriuspy/pwrsupply/psctrl/pscontroller.py b/siriuspy/siriuspy/pwrsupply/psctrl/pscontroller.py index 731945893..f8b22116c 100644 --- a/siriuspy/siriuspy/pwrsupply/psctrl/pscontroller.py +++ b/siriuspy/siriuspy/pwrsupply/psctrl/pscontroller.py @@ -15,7 +15,11 @@ 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', + } def __init__(self, readers, writers, pru_controller, devname2devid): @@ -51,6 +55,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 @@ -154,7 +168,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 diff --git a/siriuspy/siriuspy/pwrsupply/tests/utils.py b/siriuspy/siriuspy/pwrsupply/tests/utils.py index 804cb59ac..76eb310bd 100644 --- a/siriuspy/siriuspy/pwrsupply/tests/utils.py +++ b/siriuspy/siriuspy/pwrsupply/tests/utils.py @@ -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() From 220f2547beac760ecf25b2c0311525d8db56e86f Mon Sep 17 00:00:00 2001 From: ximenes Date: Mon, 10 Jun 2024 14:58:18 -0300 Subject: [PATCH 2/2] Fix PSController for WfmOffsetEnergy-* --- siriuspy/siriuspy/pwrsupply/psctrl/pscontroller.py | 1 + 1 file changed, 1 insertion(+) diff --git a/siriuspy/siriuspy/pwrsupply/psctrl/pscontroller.py b/siriuspy/siriuspy/pwrsupply/psctrl/pscontroller.py index f8b22116c..bb43fac85 100644 --- a/siriuspy/siriuspy/pwrsupply/psctrl/pscontroller.py +++ b/siriuspy/siriuspy/pwrsupply/psctrl/pscontroller.py @@ -19,6 +19,7 @@ class PSController: 'WfmOffsetKick-SP', 'WfmOffsetKick-RB', 'WfmOffsetKL-SP', 'WfmOffsetKL-RB', 'WfmOffsetSL-SP', 'WfmOffsetSL-RB', + 'WfmOffsetEnergy-SP', 'WfmOffsetEnergy-RB', } def __init__(self, readers, writers,