Skip to content

Commit

Permalink
Merge pull request #829 from lnls-sirius/update-injctrl-topup
Browse files Browse the repository at this point in the history
Update InjCtrl IOC for new topup procedure
  • Loading branch information
anacso17 authored Aug 1, 2022
2 parents 5b58aa2 + b2d3f5f commit e9da73a
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 80 deletions.
6 changes: 3 additions & 3 deletions siriuspy/siriuspy/devices/egun.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,8 @@ class EGun(_Devices, _Callback):
"""EGun device."""

DEF_TIMEOUT = 10 # [s]
BIAS_MULTI_BUNCH = -46.0 # [V]
BIAS_SINGLE_BUNCH = -80.0 # [V]
BIAS_MULTI_BUNCH = -56.0 # [V]
BIAS_SINGLE_BUNCH = -100.0 # [V]
BIAS_TOLERANCE = 1.0 # [V]
HV_OPVALUE = 90.0 # [kV]
HV_TOLERANCE = 1.0 # [kV]
Expand All @@ -455,7 +455,7 @@ class EGun(_Devices, _Callback):
HV_RAMPUP_NRPTS = 15
HV_RAMPDN_NRPTS = 6
HV_RAMP_DURATION = 70 # [s]
FILACURR_OPVALUE = 1.38 # [A]
FILACURR_OPVALUE = 1.39 # [A]
FILACURR_TOLERANCE = 0.20 # [A]
FILACURR_MAXVALUE = 1.42 # [A]
FILACURR_RAMP_NRPTS = 10
Expand Down
34 changes: 20 additions & 14 deletions siriuspy/siriuspy/devices/injsys.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def cmd_turn_off(self):

# set pulsed magnet pulse off
self._set_devices_propty(
self._pudevs, 'Pulse-Sel', _PSConst.DsblEnbl.Dsbl, wait=0.5)
self._pudevs, 'Pulse-Sel', _PSConst.DsblEnbl.Dsbl)

# wait for pulsed magnet pulse to be off
retval = self._wait_devices_propty(
Expand All @@ -160,7 +160,7 @@ def cmd_turn_off(self):

# set pulsed magnet power state off
self._set_devices_propty(
self._pudevs, 'PwrState-Sel', _PSConst.DsblEnbl.Dsbl, wait=1)
self._pudevs, 'PwrState-Sel', _PSConst.DsblEnbl.Dsbl)

# wait for pulsed magnet power state to be off
retval = self._wait_devices_propty(
Expand All @@ -171,6 +171,9 @@ def cmd_turn_off(self):
'timed out without success! Verify pulsed magnets!'
return [False, text, retval[1]]

# wait for modulators trig.out
_time.sleep(1)

# turn modulator charge off
self._set_devices_propty(
self._moddevs, 'CHARGE', _Const.DsblEnbl.Dsbl)
Expand Down Expand Up @@ -209,29 +212,30 @@ def cmd_turn_on(self):

devs = [dev for dev in self._pudevs if 'InjDpKckr' not in dev.devname]

# set pulsed magnet pulse on
self._set_devices_propty(
devs, 'Pulse-Sel', _PSConst.DsblEnbl.Enbl, wait=0.5)
# set pulsed magnet power state on
self._set_devices_propty(devs, 'PwrState-Sel', _PSConst.DsblEnbl.Enbl)

# wait for pulsed magnet pulse to be on
# wait for pulsed magnet power state to be on
retval = self._wait_devices_propty(
devs, 'Pulse-Sts', _PSConst.DsblEnbl.Enbl,
devs, 'PwrState-Sts', _PSConst.DsblEnbl.Enbl,
timeout=3, return_prob=True)
if not retval[0]:
text = 'Check for pulsed magnet Pulse to be enabled '\
text = 'Check for pulsed magnet PwrState to be on '\
'timed out without success! Verify pulsed magnets!'
return [False, text, retval[1]]

# set pulsed magnet power state on
self._set_devices_propty(
devs, 'PwrState-Sel', _PSConst.DsblEnbl.Enbl, wait=1)
# wait a moment for the PU high voltage and modulators charge
_time.sleep(1)

# wait for pulsed magnet power state to be on
# set pulsed magnet pulse on
self._set_devices_propty(devs, 'Pulse-Sel', _PSConst.DsblEnbl.Enbl)

# wait for pulsed magnet pulse to be on
retval = self._wait_devices_propty(
devs, 'PwrState-Sts', _PSConst.DsblEnbl.Enbl,
devs, 'Pulse-Sts', _PSConst.DsblEnbl.Enbl,
timeout=3, return_prob=True)
if not retval[0]:
text = 'Check for pulsed magnet PwrState to be on '\
text = 'Check for pulsed magnet Pulse to be enabled '\
'timed out without success! Verify pulsed magnets!'
return [False, text, retval[1]]

Expand Down Expand Up @@ -520,7 +524,9 @@ def cmd_turn_off(self):
return [False, text, retval[1]]

# update events
_time.sleep(1)
self.evg.cmd_update_events()
_time.sleep(1)

return True, '', []

Expand Down
12 changes: 6 additions & 6 deletions siriuspy/siriuspy/injctrl/csdev.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,12 @@ def get_injctrl_propty_database():
'TopUpNextInj-Mon': {
'type': 'float', 'value': 0.0, 'unit': 's'},
'TopUpNextInjRound-Cmd': {'type': 'int', 'value': 0},
'TopUpMaxNrPulses-SP': {
'type': 'int', 'value': 100, 'unit': 'pulses',
'lolim': 1, 'hilim': 1000},
'TopUpMaxNrPulses-RB': {
'type': 'int', 'value': 100, 'unit': 'pulses',
'lolim': 1, 'hilim': 1000},
'TopUpNrPulses-SP': {
'type': 'int', 'value': 1, 'unit': 'pulses',
'lolim': _ct.MIN_BKT, 'hilim': _ct.MAX_BKT},
'TopUpNrPulses-RB': {
'type': 'int', 'value': 1, 'unit': 'pulses',
'lolim': _ct.MIN_BKT, 'hilim': _ct.MAX_BKT},
'AutoStop-Sel': {
'type': 'enum', 'value': _ct.OffOn.Off, 'enums': _et.OFF_ON},
'AutoStop-Sts': {
Expand Down
92 changes: 35 additions & 57 deletions siriuspy/siriuspy/injctrl/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def __init__(self):
now = _Time.now().timestamp()
self._topupnext = now - (now % (24*60*60)) + 3*60*60
self._topupnextinjround_count = 0
self._topupmaxnrp = 100
self._topupnrpulses = 1
self._topup_thread = None
self._autostop = _Const.OffOn.Off
self._abort = False
Expand Down Expand Up @@ -181,7 +181,7 @@ def __init__(self):
'TopUpState-Sel': self.set_topupstate,
'TopUpPeriod-SP': self.set_topupperiod,
'TopUpNextInjRound-Cmd': self.cmd_nextinjround,
'TopUpMaxNrPulses-SP': self.set_topupmaxnrp,
'TopUpNrPulses-SP': self.set_topupnrpulses,
'AutoStop-Sel': self.set_autostop,
'InjSysTurnOn-Cmd': self.cmd_injsys_turn_on,
'InjSysTurnOff-Cmd': self.cmd_injsys_turn_off,
Expand Down Expand Up @@ -264,8 +264,8 @@ def init_database(self):
self.run_callbacks('TopUpNextInj-Mon', self._topupnext)
self.run_callbacks(
'TopUpNextInjRound-Cmd', self._topupnextinjround_count)
self.run_callbacks('TopUpMaxNrPulses-SP', self._topupmaxnrp)
self.run_callbacks('TopUpMaxNrPulses-RB', self._topupmaxnrp)
self.run_callbacks('TopUpNrPulses-SP', self._topupnrpulses)
self.run_callbacks('TopUpNrPulses-RB', self._topupnrpulses)
self.run_callbacks('AutoStop-Sel', self._autostop)
self.run_callbacks('AutoStop-Sts', self._autostop)
self.run_callbacks('InjSysTurnOn-Cmd', self._injsys_turn_on_count)
Expand Down Expand Up @@ -555,14 +555,14 @@ def set_topupperiod(self, value):
self.run_callbacks('TopUpPeriod-RB', self._topupperiod)
return True

def set_topupmaxnrp(self, value):
"""Set top-up maximum number of injection pulses."""
def set_topupnrpulses(self, value):
"""Set top-up number of injection pulses."""
if not 1 <= value <= 1000:
return False

self._topupmaxnrp = value
self._update_log('Changed top-up max.nr.pulses to '+str(value)+'.')
self.run_callbacks('TopUpMaxNrPulses-RB', self._topupmaxnrp)
self._topupnrpulses = value
self._update_log('Changed top-up nr.pulses to '+str(value)+'.')
self.run_callbacks('TopUpNrPulses-RB', self._topupnrpulses)
return True

def cmd_nextinjround(self, value):
Expand Down Expand Up @@ -591,7 +591,7 @@ def set_autostop(self, value):
self._callback_autostop()
return True

def cmd_injsys_turn_on(self, value):
def cmd_injsys_turn_on(self, value=None, wait_finish=False):
"""Set turn on Injection System."""
run = self._injsys_dev.is_running
if run:
Expand All @@ -602,13 +602,16 @@ def cmd_injsys_turn_on(self, value):
self.run_callbacks(
'InjSysCmdDone-Mon', ','.join(self._injsys_dev.done))
self._injsys_dev.cmd_turn_on(run_in_thread=True)
_Thread(target=self._watch_injsys, args=['on', ], daemon=True).start()
thr = _Thread(target=self._watch_injsys, args=['on', ], daemon=True)
thr.start()
if wait_finish:
thr.join()

self._injsys_turn_on_count += 1
self.run_callbacks('InjSysTurnOn-Cmd', self._injsys_turn_on_count)
return False

def cmd_injsys_turn_off(self, value):
def cmd_injsys_turn_off(self, value=None, wait_finish=False):
"""Set turn off Injection System."""
run = self._injsys_dev.is_running
if run:
Expand All @@ -619,7 +622,10 @@ def cmd_injsys_turn_off(self, value):
self.run_callbacks(
'InjSysCmdDone-Mon', ','.join(self._injsys_dev.done))
self._injsys_dev.cmd_turn_off(run_in_thread=True)
_Thread(target=self._watch_injsys, args=['off', ], daemon=True).start()
thr = _Thread(target=self._watch_injsys, args=['off', ], daemon=True)
thr.start()
if wait_finish:
thr.join()

self._injsys_turn_off_count += 1
self.run_callbacks('InjSysTurnOff-Cmd', self._injsys_turn_off_count)
Expand Down Expand Up @@ -762,7 +768,7 @@ def _run_autostop(self):

if self._stop_injection():
self._update_log('Injection Auto Stop done.')
self._update_bucket_list()
self._update_bucket_list_autostop()
else:
self._update_log('Injection Auto Stop failed.')

Expand Down Expand Up @@ -856,8 +862,8 @@ def _check_allok_2_inject(self, show_warn=True):
self._update_log('WARN:'+prob)

if self._mode == _Const.InjMode.TopUp:
if self._evg_dev.nrpulses != 0:
self._update_log('ERR:Aborted. Set RepeatBucketList to 0.')
if self._evg_dev.nrpulses == 0:
self._update_log('ERR:Aborted. RepeatBucketList cannot be 0.')
return False

if self._abort:
Expand All @@ -873,21 +879,6 @@ def _start_injection(self):
return False
self._update_log('Sent turn on to InjectionEvt.')

# turn on PU Pulse
self._update_log('Turning on PU Pulse...')
for pudev in self._pu_devs:
pudev.pulse = _Const.DsblEnbl.Enbl
_time.sleep(0.5)
_t0 = _time.time()
while _time.time() - _t0 < 3:
if all([pud.pulse == _Const.DsblEnbl.Enbl
for pud in self._pu_devs]):
self._update_log('Turned on PU Pulse.')
break
else:
self._update_log('ERR:Timed out waiting for PU to be on.')
return False

# wait for injectionevt to be ready
self._update_log('Waiting for InjectionEvt to be on...')
_t0 = _time.time()
Expand All @@ -897,7 +888,7 @@ def _start_injection(self):
return False
if self._evg_dev.injection_state:
break
_time.sleep(0.1)
_time.sleep(0.02)
else:
self._update_log('ERR:Timed out waiting for InjectionEvt.')
return False
Expand All @@ -919,10 +910,8 @@ def _wait_injection(self):
return False
# if in TopUp mode and max pulses exceeded, stop injection
if self._mode == _Const.InjMode.TopUp and \
self._evg_dev.injection_count >= self._topupmaxnrp:
self._update_log('ERR:Max.Nr.Pulses exceeded. Stopping.')
self._abort_injection()
return False
self._evg_dev.injection_count >= self._topupnrpulses:
break
_time.sleep(0.1)

self._update_log('Target current reached!')
Expand All @@ -936,24 +925,9 @@ def _stop_injection(self):
return False
self._update_log('Turned off InjectionEvt.')

if self._mode == _Const.InjMode.Decay:
return True

# turn off PU Pulse
self._update_log('Turning off PU Pulse...')
for pudev in self._pu_devs:
pudev.pulse = _Const.DsblEnbl.Dsbl
_time.sleep(0.5)
_t0 = _time.time()
while _time.time() - _t0 < 3:
if all([pud.pulse == _Const.DsblEnbl.Dsbl
for pud in self._pu_devs]):
self._update_log('Turned off PU Pulse.')
return True
self._update_log('ERR:Timed out waiting for PU to be off.')
return False
return True

def _update_bucket_list(self):
def _update_bucket_list_autostop(self):
old_bucklist = self._evg_dev.bucketlist_mon
injcount = self._evg_dev.injection_count
blistlen = self._evg_dev.bucketlist_len
Expand All @@ -965,6 +939,13 @@ def _update_bucket_list(self):
else:
self._update_log('Updated BucketList.')

def _update_bucket_list_topup(self):
bucket = _np.arange(self._topupnrpulses) + self._topupnrpulses
bucket *= self._bucketlist_step
bucket += self._evg_dev.bucketlist_mon[0] - 1
bucket %= 864
self._evg_dev.bucketlist = bucket + 1

def _abort_injection(self):
self._update_log('Turning off InjectionEvt...')
if self._evg_dev.cmd_turn_off_injection():
Expand Down Expand Up @@ -1017,10 +998,7 @@ def _do_topup(self):
break

self._update_topupsts(_Const.TopUpSts.TurningOff)
self._update_log('Stopping injection...')
if not self._stop_injection():
break
self._update_bucket_list()
self._update_bucket_list_topup()

self._update_topupsts(_Const.TopUpSts.Waiting)
self._update_log('Waiting for next injection...')
Expand Down

0 comments on commit e9da73a

Please sign in to comment.