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

Generalize SOFBMode #660

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
16 changes: 8 additions & 8 deletions siriuspy/siriuspy/cycle/conn.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ class PSCyclerFBP(PSCycler):
'Current-SP', 'Current-RB', 'CurrentRef-Mon',
'PwrState-Sel', 'PwrState-Sts',
'OpMode-Sel', 'OpMode-Sts',
'SOFBMode-Sel', 'SOFBMode-Sts',
'StandByMode-Sel', 'StandByMode-Sts',
'CycleType-Sel', 'CycleType-Sts',
'CycleFreq-SP', 'CycleFreq-RB',
'CycleAmpl-SP', 'CycleAmpl-RB',
Expand All @@ -609,19 +609,19 @@ class PSCyclerFBP(PSCycler):
'SyncPulse-Cmd'
]

def set_sofbmode(self, state):
"""Set SOFBMode."""
def set_standbymode(self, state):
"""Set StandByMode."""
state = _PSConst.OffOn.On if state == 'on' else _PSConst.OffOn.Off
return _pv_conn_put(self['SOFBMode-Sel'], state)
return _pv_conn_put(self['StandByMode-Sel'], state)

def check_sofbmode(self, state, wait=1):
"""Check if SOFBMode."""
def check_standbymode(self, state, wait=1):
"""Check if StandByMode."""
state = _PSConst.OffOn.On if state == 'on' else _PSConst.OffOn.Off
return _pv_timed_get(self['SOFBMode-Sts'], state, wait=wait)
return _pv_timed_get(self['StandByMode-Sts'], state, wait=wait)

def prepare(self, mode):
"""Config power supply to cycling mode."""
if not self.check_sofbmode('off', wait=1):
if not self.check_standbymode('off', wait=1):
return False

if not self.check_opmode_slowref(wait=1):
Expand Down
40 changes: 20 additions & 20 deletions siriuspy/siriuspy/cycle/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ def prepare_timing_size(self):
return 3

@property
def prepare_ps_sofbmode_size(self):
"""Prepare PS SOFBMode task size."""
def prepare_ps_standbymode_size(self):
"""Prepare PS StandByMode task size."""
prepare_ps_size = 2*(len(self.psnames)+1)
if 'SI' in self._sections and not self._isadv:
prepare_ps_size += 2*len(self.trimnames)
Expand Down Expand Up @@ -295,8 +295,8 @@ def prepare_timing_max_duration(self):
return 10

@property
def prepare_ps_sofbmode_max_duration(self):
"""Prepare PS SOFBMode task maximum duration."""
def prepare_ps_standbymode_max_duration(self):
"""Prepare PS StandByMode task maximum duration."""
prepare_ps_max_duration = 5 + TIMEOUT_CHECK
if 'SI' in self._sections and not self._isadv:
prepare_ps_max_duration += TIMEOUT_CHECK
Expand Down Expand Up @@ -648,30 +648,30 @@ def check_pwrsupplies_finalsts(self, psnames):
all_ok = False
return all_ok

def set_pwrsupplies_sofbmode(self, psnames):
"""Set power supplies SOFBMode."""
def set_pwrsupplies_standbymode(self, psnames):
"""Set power supplies StandByMode."""
if self._only_linac:
return True
psnames = {ps for ps in psnames
if _PSSearch.conv_psname_2_psmodel(ps) == 'FBP'}

self._update_log('Turning off power supplies SOFBMode...')
self._update_log('Turning off power supplies StandByMode...')
for idx, psname in enumerate(psnames):
cycler = self._get_cycler(psname)
cycler.set_sofbmode('off')
cycler.set_standbymode('off')
if idx % 5 == 4 or idx == len(psnames)-1:
self._update_log(
'Sent SOFBMode preparation to {0}/{1}'.format(
'Sent StandByMode preparation to {0}/{1}'.format(
str(idx+1), str(len(psnames))))

def check_pwrsupplies_sofbmode(self, psnames, timeout=TIMEOUT_CHECK):
"""Check power supplies SOFBMode."""
def check_pwrsupplies_standbymode(self, psnames, timeout=TIMEOUT_CHECK):
"""Check power supplies StandByMode."""
if self._only_linac:
return True
psnames = {ps for ps in psnames
if _PSSearch.conv_psname_2_psmodel(ps) == 'FBP'}

self._update_log('Checking power supplies SOFBMode...')
self._update_log('Checking power supplies StandByMode...')
self._checks_result = {psn: False for psn in psnames}
msg = 'Successfully checked SOFBMode preparation for {}/' + \
str(len(psnames))
Expand All @@ -682,7 +682,7 @@ def check_pwrsupplies_sofbmode(self, psnames, timeout=TIMEOUT_CHECK):
if self._checks_result[psname]:
continue
cycler = self._get_cycler(psname)
if cycler.check_sofbmode('off', 0.05):
if cycler.check_standbymode('off', 0.05):
self._checks_result[psname] = True
checked = sum(self._checks_result.values())
if not checked % 5:
Expand All @@ -698,7 +698,7 @@ def check_pwrsupplies_sofbmode(self, psnames, timeout=TIMEOUT_CHECK):
for psname, sts in self._checks_result.items():
if sts:
continue
self._update_log(psname+' is in SOFBMode.', error=True)
self._update_log(psname+' is in StandByMode.', error=True)
status &= False
return status

Expand Down Expand Up @@ -815,21 +815,21 @@ def prepare_timing(self):
return
self._update_log('Timing preparation finished!')

def prepare_pwrsupplies_sofbmode(self):
"""Prepare SOFBMode."""
def prepare_pwrsupplies_standbymode(self):
"""Prepare StandByMode."""
psnames = self.psnames
timeout = TIMEOUT_CHECK
if 'SI' in self._sections and not self._isadv:
self.create_trims_cyclers()
psnames.extend(self.trimnames)
timeout += TIMEOUT_CHECK

self.set_pwrsupplies_sofbmode(psnames)
if not self.check_pwrsupplies_sofbmode(psnames, timeout):
self.set_pwrsupplies_standbymode(psnames)
if not self.check_pwrsupplies_standbymode(psnames, timeout):
self._update_log(
'There are power supplies in SOFBMode.', error=True)
'There are power supplies in StandByMode.', error=True)
return
self._update_log('Power supplies SOFBMode preparation finished!')
self._update_log('Power supplies StandByMode preparation finished!')

def prepare_pwrsupplies_opmode_slowref(self):
"""Prepare OpMode to slowref."""
Expand Down
14 changes: 8 additions & 6 deletions siriuspy/siriuspy/pwrsupply/csdev.py
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,13 @@ def _get_ps_common_propty_database():
'unit': 'count',
'low': -1, 'lolo': -1,
'high': 50, 'hihi': 50},
# StandBy
'StandByMode-Sel': {
'type': 'enum', 'enums': _et.DSBL_ENBL,
'value': Const.DsblEnbl.Dsbl, 'unit': 'standbymode'},
'StandByMode-Sts': {
'type': 'enum', 'enums': _et.DSBL_ENBL,
'value': Const.DsblEnbl.Dsbl, 'unit': 'standbymode'},
# Interlocks
'IntlkSoft-Mon': {'type': 'int', 'value': 0, 'unit': 'interlock'},
'IntlkHard-Mon': {'type': 'int', 'value': 0, 'unit': 'interlock'},
Expand Down Expand Up @@ -1029,6 +1036,7 @@ def _get_ps_common_propty_database():
'type': 'float', 'value': 0.0, 'unit': 'Hz'},
'ParamScopeDataSource-Cte': {'type': 'float', 'value': 0.0},
}

return dbase


Expand Down Expand Up @@ -1115,12 +1123,6 @@ def _get_ps_sofb_propty_database():
"""Return PSSOFB properties."""
count = _UDC_MAX_NR_DEV * PSSOFB_MAX_NR_UDC
dbase = {
'SOFBMode-Sel': {
'type': 'enum', 'enums': _et.DSBL_ENBL,
'value': Const.DsblEnbl.Dsbl, 'unit': 'sofbmode'},
'SOFBMode-Sts': {
'type': 'enum', 'enums': _et.DSBL_ENBL,
'value': Const.DsblEnbl.Dsbl, 'unit': 'sofbmode'},
'SOFBCurrent-SP': {
'type': 'float', 'count': count,
'unit': 'A', 'prec': PS_CURRENT_PRECISION,
Expand Down
26 changes: 13 additions & 13 deletions siriuspy/siriuspy/pwrsupply/pructrl/prucontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def __init__(self,
t0_ = _time()

# init sofb mode to false
self._sofb_mode = False
self._standby_mode = False

# index of device in self._device_ids for next update in SOFB mode
self._sofb_update_dev_idx = 0 # cyclical updates!
Expand Down Expand Up @@ -244,11 +244,11 @@ def exec_functions(self, device_ids, function_id, args=None):
-------
status : bool
True is operation was queued or False, if operation was rejected
because of the SOFBMode state.
because of the StandByMode state.

"""
# if in SOFBMode on, do not accept exec functions
if self._sofb_mode:
# if in StandByMode on, do not accept exec functions
if self._standby_mode:
return False

# prepare arguments
Expand Down Expand Up @@ -289,8 +289,8 @@ def wfm_update(self, device_ids, interval=None):

def wfmref_write(self, device_ids, data):
"""Write wfm curves."""
# if in SOFBMode on, do not accept exec functions
if self._sofb_mode:
# if in StandByMode on, do not accept exec functions
if self._standby_mode:
return False

# prepare arguments
Expand Down Expand Up @@ -331,17 +331,17 @@ def scope_read(self, device_id):

# --- SOFBCurrent parameters ---

def sofb_mode_set(self, state):
def standby_mode_set(self, state):
"""Change SOFB mode: True or False."""
self._sofb_mode = state
self._standby_mode = state
if state:
while self._queue: # wait until queue is empty
pass

@property
def sofb_mode(self):
def standby_mode(self):
"""Return SOFB mode."""
return self._sofb_mode
return self._standby_mode

def sofb_current_set(self, value):
"""."""
Expand Down Expand Up @@ -371,8 +371,8 @@ def sofb_current_mon(self):

def sofb_update_variables_state(self):
"""Update variables state mirror."""
# do sofb update only if in SOFBMode On
if not self._sofb_mode:
# do sofb update only if in StandByMode On
if not self._standby_mode:
return

# wait until queue is empty
Expand Down Expand Up @@ -509,7 +509,7 @@ def _loop_scan(self):
# run scan method once
if self.scanning and \
self._scan_interval != 0 and \
not self._sofb_mode:
not self._standby_mode:
self.bsmp_scan()

# update scan interval
Expand Down
4 changes: 2 additions & 2 deletions siriuspy/siriuspy/pwrsupply/psctrl/pscontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ 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:
# update all setpoint properties upon return from StandByMode
if 'StandByMode-Sel' in field and value == 0:
self._update_setpoints(devname)

# return priority pvs
Expand Down
8 changes: 4 additions & 4 deletions siriuspy/siriuspy/pwrsupply/psctrl/pscwriters.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,26 +381,26 @@ def execute(self, value=None):
self.pru_controller.sofb_current_set(value)


class SOFBMode(Function):
class StandByMode(Function):
"""."""

def __init__(self, pru_controller, setpoints=None):
"""Create command to set SOFBMode."""
"""Create command to set StandByMode."""
self.pru_controller = pru_controller
self.setpoints = setpoints

def execute(self, value=None):
"""Execute command."""
if not self.setpoints or \
(self.setpoints and self.setpoints.apply(value)):
self.pru_controller.sofb_mode_set(value)
self.pru_controller.standby_mode_set(value)


class SOFBUpdate(Function):
"""."""

def __init__(self, pru_controller, setpoints=None):
"""Create command to set SOFBMode."""
"""Create command to set StandByMode."""
self.pru_controller = pru_controller
self.setpoints = setpoints

Expand Down
6 changes: 3 additions & 3 deletions siriuspy/siriuspy/pwrsupply/psctrl/psmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ class PSModelFBP(_PSModel):
}

_pruc_properties = {
'SOFBMode-Sts': 'sofb_mode',
'StandByMode-Sts': 'standby_mode',
'SOFBCurrent-RB': 'sofb_current_rb',
'SOFBCurrentRef-Mon': 'sofb_current_refmon',
'SOFBCurrent-Mon': 'sofb_current_mon',
Expand All @@ -328,8 +328,8 @@ def writer(self, device_ids, epics_field, pru_controller, setpoints):
if epics_field == 'SOFBCurrent-SP':
return _writers.SOFBCurrent(
device_ids, pru_controller, setpoints)
if epics_field == 'SOFBMode-Sel':
return _writers.SOFBMode(pru_controller, setpoints)
if epics_field == 'StandByMode-Sel':
return _writers.StandByMode(pru_controller, setpoints)
if epics_field == 'SOFBUpdate-Cmd':
return _writers.SOFBUpdate(pru_controller, setpoints)
return super().writer(
Expand Down
20 changes: 10 additions & 10 deletions siriuspy/siriuspy/pwrsupply/tests/test_stress_pwrsupplies.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,30 +37,30 @@ def value(self, value):
class Cmd:
def __init__(self, devs):
self.devs = devs
self.sofbmode_sp = PVGroup(devs, 'SOFBMode-Sel')
self.sofbmode_rb = PVGroup(devs, 'SOFBMode-Sts')
self.standbymode_sp = PVGroup(devs, 'StandByMode-Sel')
self.standbymode_rb = PVGroup(devs, 'StandByMode-Sts')
self.opmode_sp = PVGroup(devs, 'OpMode-Sel')
self.opmode_rb = PVGroup(devs, 'OpMode-Sts')


def wait_for_connection(cmd):
cmd.sofbmode_sp.wait_for_connection()
cmd.sofbmode_rb.wait_for_connection()
cmd.standbymode_sp.wait_for_connection()
cmd.standbymode_rb.wait_for_connection()
cmd.opmode_sp.wait_for_connection()
cmd.opmode_rb.wait_for_connection()


def connected(cmd):
conn = True
conn &= cmd.sofbmode_sp.connected
conn &= cmd.sofbmode_rb.connected
conn &= cmd.standbymode_sp.connected
conn &= cmd.standbymode_rb.connected
conn &= cmd.opmode_sp.connected
conn &= cmd.opmode_rb.connected
return conn


def is_stressed(cmd):
values = cmd.sofbmode_rb.value
values = cmd.standbymode_rb.value
for i in range(len(values)):
if values[i] != 0:
print(cmd.devs[i])
Expand All @@ -85,7 +85,7 @@ def try_to_stress(pssofb, cmd, nr_iters=100, rate=25.14):

pssofb.bsmp_sofb_current_set(curr)
time.sleep(0.1)
cmd.sofbmode_sp.value = 1
cmd.standbymode_sp.value = 1
time.sleep(1)

for i in range(nr_iters):
Expand All @@ -96,7 +96,7 @@ def try_to_stress(pssofb, cmd, nr_iters=100, rate=25.14):
time.sleep(1/rate)

time.sleep(1)
cmd.sofbmode_sp.value = 0
cmd.standbymode_sp.value = 0
cmd.opmode_sp.value = 0
time.sleep(1)
return is_stressed(cmd)
Expand Down Expand Up @@ -141,7 +141,7 @@ def try_to_stress(pssofb, cmd, nr_iters=100, rate=25.14):
time.sleep(2)
# print(connected(cmd))

# cmd.sofbmode_sp.value = 0
# cmd.standbymode_sp.value = 0
# cmd.opmode_sp.value = 0

print(is_stressed(cmd))
Expand Down
Loading