Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update PV setpoints when SOFBMode changes to Disabled #737

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 48 additions & 13 deletions siriuspy/siriuspy/pwrsupply/beaglebone.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ def __init__(self, controllers, databases):
# psnames
self._psnames = tuple(self._controllers.keys())

# SOFB mode on
self._sofbps = 'SOFBMode-Sts' in self._databases[self._psnames[0]]

# strength property names
self._strenames = self._get_strength_names()

Expand Down Expand Up @@ -101,6 +104,8 @@ def read(self, devname, field=None, force_update=False):
updated = False

if field is None:
if self._sofbps:
self._sofb_mode_update_setpoints(devname)
return self._dev2mirror[devname], updated
else:
pvname = devname + ':' + field
Expand All @@ -123,6 +128,8 @@ def write(self, devname, field, value):
else:
priority_pvs = self._controllers[devname].write(
devname, field, value)
if field == 'SOFBMode-Sel' and value == 0:
self._sofb_mode_disable()
return priority_pvs

def get_strength_limits(self, devname):
Expand Down Expand Up @@ -217,27 +224,27 @@ def _create_streconvs(self):
strelims[psname] = [None, None]
return streconvs, strec, strelims

def _update_strengths(self, psname):
def _update_strengths(self, devname):
# t0_ = _time.time()
if 'DCLink' in psname or psname.startswith('IT'):
if 'DCLink' in devname or devname.startswith('IT'):
return
streconv = self._streconvs[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']
streconv = self._streconvs[devname]
strelims = self._strelims[devname]
mirror = self._dev2mirror[devname]
dbase = self._databases[devname]
curr0 = mirror[devname + ':Current-SP']
curr1 = mirror[devname + ':Current-RB']
curr2 = mirror[devname + ':CurrentRef-Mon']
curr3 = mirror[devname + ':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
self._streconnected[devname] = False
else:
self._streconnected[psname] = True
propname = psname + ':' + self._strenames[psname]
self._streconnected[devname] = True
propname = devname + ':' + self._strenames[devname]
mirror[propname + '-SP'] = strengths[0]
mirror[propname + '-RB'] = strengths[1]
mirror[propname + 'Ref-Mon'] = strengths[2]
Expand All @@ -249,3 +256,31 @@ def _update_strengths(self, psname):
strelims[0], strelims[1] = strengths[5], strengths[4]
# t1_ = _time.time()
# print('update_strengths: {:.3f}'.format(1000*(t1_-t0_)))

def _sofb_mode_disable(self):

# update variables in prucontrollers and controllers
pruc_initialized = set()
psc_initialized = set()
for controller in self._controllers.values():
pruc = controller.prucontroller
if pruc not in pruc_initialized:
pruc.update_variables() # update mirrored variables
pruc_initialized.add(pruc)
if controller not in psc_initialized:
controller.init_setpoints() # set controller setpoint values
psc_initialized.add(controller)

# update mirror in beaglebone and strengths
for devname in self._dev2mirror:
self._dev2mirror[devname] = \
self._controllers[devname].read_all_fields(devname)
self._update_strengths(devname)

def _sofb_mode_update_setpoints(self, devname):
mirror = self._dev2mirror[devname]
controller = self._controllers[devname]
if controller.prucontroller.sofb_mode:
# If power supply in SOFBMode, update Current-SP
pvpref = devname + ':Current-'
mirror[pvpref + 'SP'] = mirror[pvpref + 'RB']
13 changes: 8 additions & 5 deletions siriuspy/siriuspy/pwrsupply/pructrl/prucontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,10 @@ def exec_functions(self, device_ids, function_id, args=None):
self._queue.append(operation)
return True

def update_variables(self, device_id=None):
"""Update variable."""
self._bsmp_update_variables(device_id)

# --- wfmref and scope curves ---

def scope_update_auto_enable(self):
Expand Down Expand Up @@ -390,7 +394,7 @@ def sofb_update_variables_state(self):
# --- scan and process loop methods ---

def bsmp_scan(self):
"""Run scan one."""
"""Run scan once."""
# select devices and variable group, defining the read group
# operation to be performed
operation = (self._bsmp_update, ())
Expand Down Expand Up @@ -611,12 +615,11 @@ def _bsmp_update(self):
except _socket_timeout:
print('!!! {} : socket timeout !!!'.format(_get_timestamp()))


def _bsmp_update_variables(self, dev_id=None):
if dev_id is None:
def _bsmp_update_variables(self, device_id=None):
if device_id is None:
psupplies = self._psupplies.values()
else:
psupplies = (self._psupplies[dev_id], )
psupplies = (self._psupplies[device_id], )

for psupply in psupplies:
try:
Expand Down
20 changes: 6 additions & 14 deletions siriuspy/siriuspy/pwrsupply/psctrl/pscontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ def write(self, devname, field, value):
if pvname in self._writers:
self._writers[pvname].execute(value)

# update all setpoint properties upon return from SOFBMode
if 'SOFBMode-Sel' in field and value == 0:
self._update_setpoints(devname)

# return priority pvs
return priority_pvs

Expand Down Expand Up @@ -127,11 +123,16 @@ def init_setpoints(self, devname=None):
if key.endswith('OpMode-Sel'):
# OpModel-Sel is shifted in 3 units relative OpMode-Sts
if value is not None:
value = 0 if value < 3 else value - 3
value = PSController.get_opmode_sts2sel(value)

# apply value to setpoint using its reader
reader_sp.apply(value)

@staticmethod
def get_opmode_sts2sel(value):
# OpModel-Sel is shifted in 3 units relative OpMode-Sts
return 0 if value < 3 else value - 3

# --- private methods ---

def _get_udc2dev(self):
Expand All @@ -149,11 +150,6 @@ def _get_fields(self):
split = name.split(':')
fields.add(split[-1])
return fields

def _update_setpoints(self, devname):
"""."""
self.read_all_fields(devname)
self.init_setpoints(devname)

@staticmethod
def _get_readback_field(field):
Expand Down Expand Up @@ -191,10 +187,6 @@ def write(self, devname, field, value):
else:
self._writers[pvname].execute(value)

# update all setpoint properties upon return from SOFBMode
if 'SOFBMode-Sel' in field and value == 0:
self._update_setpoints(devname)

# return priority pvs
return priority_pvs

Expand Down
1 change: 1 addition & 0 deletions siriuspy/siriuspy/pwrsupply/psctrl/pscwriters.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ def execute(self, value=None):
(self.setpoints and self.setpoints.apply(value)):
self.set_current.execute(value)


class Voltage(Function):
"""Command to set voltage in DCLink type PS."""

Expand Down