Skip to content

Commit

Permalink
Merge pull request #1124 from lnls-sirius/update-injctrl
Browse files Browse the repository at this point in the history
Add protection to open topup loop when the beam is dumped
  • Loading branch information
anacso17 authored Nov 1, 2024
2 parents 8d32261 + b3371ea commit 9375bcc
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 37 deletions.
2 changes: 1 addition & 1 deletion siriuspy/siriuspy/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.91.0
2.92.0
48 changes: 12 additions & 36 deletions siriuspy/siriuspy/devices/rf.py
Original file line number Diff line number Diff line change
Expand Up @@ -1335,53 +1335,29 @@ def set_frequency(self, value, timeout=10, tol=0.05):
return self.dev_rfgen.set_frequency(value, tol=tol, timeout=timeout)


class RFKillBeam(_SILLRF):
class RFKillBeam(_DeviceSet):
"""RF Kill Beam Button."""

TIMEOUT_WAIT = 20.0 # [s]
INCRATE_VALUE = ASLLRF.VoltIncRates.vel_50p0 # [mV/s]
REFMIN_VALUE = 60 # Minimum Amplitude Reference [mV]
TIMEOUT_WAIT = 10 # [s]

def __init__(self):
"""Init."""
super().__init__(ASLLRF.DEVICES.SIA)
props2init = ASLLRF.PROPERTIES_INTERLOCK
si_a = ASLLRF(devname=ASLLRF.DEVICES.SIA, props2init=props2init)
si_b = ASLLRF(devname=ASLLRF.DEVICES.SIB, props2init=props2init)
devs = [si_a, si_b]
super().__init__(devices=devs, devname='SI-Glob:RF-KillBeam')

def cmd_kill_beam(self):
"""Kill beam."""
if not self.wait_for_connection(self.TIMEOUT_WAIT):
return [False, 'Could not read RF PVs.']

# get initial values
amp_incrate_init = self.voltage_incrate
amp_init = self.voltage

# set Amplitude Increase Rate to 50 mV/s and wait
self.voltage_incrate = self.INCRATE_VALUE
if not self._wait(
'AmpIncRate-RB', self.INCRATE_VALUE,
timeout=self.TIMEOUT_WAIT):
return [False, 'Could not set RF Amplitude Increase Rate.']

# set Amplitude Reference to 60mV and wait
self.voltage = self.REFMIN_VALUE
if not self._wait_float(
'SLInpAmp-Mon', self.REFMIN_VALUE, abs_tol=1,
timeout=self.TIMEOUT_WAIT):
return [False, 'Could not set RF Voltage to low value.']

# set Amplitude Reference to initial value
self.voltage = amp_init
if not self._wait_float(
'SLInpAmp-Mon', amp_init,
abs_tol=1, timeout=self.TIMEOUT_WAIT):
return [False, 'Could not set RF Voltage back to original value.']

# set Amplitude Increase Rate to initial value
self.voltage_incrate = amp_incrate_init
if not self._wait(
'AmpIncRate-RB', self.INCRATE_VALUE,
timeout=self.TIMEOUT_WAIT):
return [False, 'Could not set RF Amplitude Increase Rate back.']
for llrf in self.devices:
llrf.interlock_manual = 1
_time.sleep(1)
for llrf in self.devices:
llrf.interlock_manual = 0
return [True, '']


Expand Down
19 changes: 19 additions & 0 deletions siriuspy/siriuspy/injctrl/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def __init__(self):
self._topup_nrpulses = 1
self._topup_job = None
self._accum_job = None
self._stop_topup_job = None
self._abort = False
self._setting_mode = False

Expand Down Expand Up @@ -192,6 +193,9 @@ def __init__(self):
curr_pvo = self.currinfo_dev.pv_object('Current-Mon')
curr_pvo.add_callback(self._callback_autostop)
curr_pvo.connection_callbacks.append(self._callback_conn_autostop)
self.currinfo_dev.set_auto_monitor('StoredEBeam-Mon', True)
stored_pvo = self.currinfo_dev.pv_object('StoredEBeam-Mon')
stored_pvo.add_callback(self._callback_havebeam)

self._pu_names, self._pu_devs = list(), list()
self._pu_refvolt = list()
Expand Down Expand Up @@ -1174,6 +1178,21 @@ def _thread_is_injecting(self):
_time.sleep(self._isinj_duration/1000)
self.run_callbacks('IsInjecting-Mon', _Const.IdleInjecting.Idle)

def _callback_havebeam(self, value, **kws):
if value:
return
if self._mode != _Const.InjMode.TopUp:
return
if self._stop_topup_job is not None and \
self._stop_topup_job.is_alive():
return
if self._topup_state_sts != _Const.TopUpSts.Off:
self._update_log('FATAL:We do not have stored beam!')
self._update_log('FATAL:Opening TopUp loop...')
self._stop_topup_job = _epics.ca.CAThread(
target=self.set_topup_state, args=[_Const.OffOn.Off, ], daemon=True)
self._stop_topup_job.start()

# --- auxiliary injection methods ---

def _check_allok_2_inject(self, show_warn=True):
Expand Down

0 comments on commit 9375bcc

Please sign in to comment.