- for this use frappy_psi.PRtransmitter instead of ionopimax.CurrentInput - add disabled_checks parameter
179 lines
6.9 KiB
Python
179 lines
6.9 KiB
Python
# *****************************************************************************
|
|
# This program is free software; you can redistribute it and/or modify it under
|
|
# the terms of the GNU General Public License as published by the Free Software
|
|
# Foundation; either version 2 of the License, or (at your option) any later
|
|
# version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
# details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License along with
|
|
# this program; if not, write to the Free Software Foundation, Inc.,
|
|
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
#
|
|
# Module authors:
|
|
# Markus Zolliker <markus.zolliker@psi.ch>
|
|
# *****************************************************************************
|
|
|
|
"""interlocks for furnace"""
|
|
|
|
from frappy.core import Module, Writable, Attached, Parameter, FloatRange, Readable,\
|
|
BoolType, ERROR, IDLE, Command, StringType
|
|
from frappy.errors import ImpossibleError
|
|
from frappy.ctrlby import WrapControlledBy
|
|
from frappy_psi.picontrol import PImixin
|
|
from frappy_psi.convergence import HasConvergence
|
|
from frappy_psi.ionopimax import CurrentInput, LogVoltageInput
|
|
import frappy_psi.tdkpower as tdkpower
|
|
import frappy_psi.bkpower as bkpower
|
|
|
|
|
|
class Interlocks(Writable):
|
|
value = Parameter('interlock o.k.', BoolType(), default=True)
|
|
target = Parameter('set to true to confirm', BoolType(), readonly=False)
|
|
input = Attached(Readable, 'the input module', mandatory=False) # TODO: remove
|
|
vacuum = Attached(Readable, 'the vacuum pressure', mandatory=False)
|
|
wall_T = Attached(Readable, 'the wall temperature', mandatory=False)
|
|
htr_T = Attached(Readable, 'the heater temperature', mandatory=False)
|
|
main_T = Attached(Readable, 'the main temperature')
|
|
extra_T = Attached(Readable, 'the extra temperature')
|
|
control = Attached(Module, 'the control module')
|
|
htr = Attached(Module, 'the heater module', mandatory=False)
|
|
relais = Attached(Writable, 'the interlock relais', mandatory=False)
|
|
flowswitch = Attached(Readable, 'the flow switch', mandatory=False)
|
|
wall_limit = Parameter('maximum wall temperature', FloatRange(0, unit='degC'),
|
|
default = 50, readonly = False)
|
|
vacuum_limit = Parameter('maximum vacuum pressure', FloatRange(0, unit='mbar'),
|
|
default = 0.1, readonly = False)
|
|
htr_T_limit = Parameter('maximum htr temperature', FloatRange(0, unit='degC'),
|
|
default = 530, readonly = False)
|
|
main_T_limit = Parameter('maximum main temperature', FloatRange(0, unit='degC'),
|
|
default = 530, readonly = False)
|
|
extra_T_limit = Parameter('maximum extra temperature', FloatRange(0, unit='degC'),
|
|
default = 530, readonly = False)
|
|
disabled_checks = Parameter('checks to disable', StringType(),
|
|
value = '', readonly = False)
|
|
|
|
_off_reason = None # reason triggering interlock
|
|
_conditions = '' # summary of reasons why locked now
|
|
_sensor_checks = ()
|
|
|
|
SENSOR_MAP = {
|
|
'wall_T': 'wall_limit',
|
|
'main_T': 'main_T_limit',
|
|
'extra_T': 'extra_T_limit',
|
|
'htr_T': 'htr_T_limit',
|
|
'vacuum': 'vacuum_limit',
|
|
}
|
|
|
|
def write_target(self, value):
|
|
if value:
|
|
self.read_status()
|
|
if self._conditions:
|
|
raise ImpossibleError('not ready to start')
|
|
self._off_reason = None
|
|
self.value = True
|
|
elif self.value:
|
|
self.switch_off()
|
|
self._off_reason = 'switched off'
|
|
self.value = False
|
|
self.read_status()
|
|
|
|
def switch_off(self):
|
|
if self.value:
|
|
self._off_reason = self._conditions
|
|
self.value = False
|
|
if self.control.control_active:
|
|
self.log.error('switch control off %r', self.control.status)
|
|
self.control.write_control_active(False)
|
|
if self.htr and self.htr.target:
|
|
self.htr.write_target(0)
|
|
if self.relais.value or self.relais.target:
|
|
self.log.warning('switch off relais %r %r', self.relais.value, self.relais.target)
|
|
self.relais.write_target(False)
|
|
|
|
def write_disabled_checks(self, value):
|
|
disabled = set(value.split())
|
|
self._sensor_checks = []
|
|
for att, limitname in self.SENSOR_MAP.items():
|
|
obj = getattr(self, att)
|
|
if obj and obj.name not in disabled:
|
|
self.log.info('info %r %r %r', att, obj.name, disabled)
|
|
self._sensor_checks.append((obj, limitname))
|
|
|
|
def read_status(self):
|
|
conditions = []
|
|
if self.flowswitch and self.flowswitch.value == 0:
|
|
conditions.append('no cooling water')
|
|
|
|
for sensor, limitname in self._sensor_checks:
|
|
if sensor.value > getattr(self, limitname):
|
|
conditions.append(f'above {sensor.name} limit')
|
|
if sensor.status[0] >= ERROR:
|
|
conditions.append(f'error at {sensor.name}: {sensor.status[1]}')
|
|
break
|
|
self._conditions = ', '.join(conditions)
|
|
if conditions and (self.control.control_active or self.htr.target):
|
|
self.switch_off()
|
|
if self.value:
|
|
return IDLE, '; '.join(conditions)
|
|
return ERROR, self._off_reason
|
|
|
|
@Command
|
|
def reset(self):
|
|
"""reset interlock after error
|
|
|
|
will fail if error conditions still apply
|
|
"""
|
|
self.write_target(1)
|
|
|
|
|
|
class PI(HasConvergence, PImixin, Writable):
|
|
input_module = Attached(Readable, 'the input module')
|
|
relais = Attached(Writable, 'the interlock relais', mandatory=False)
|
|
|
|
def read_value(self):
|
|
return self.input_module.value
|
|
|
|
def read_status(self):
|
|
return self.input_module.status
|
|
|
|
def set_target(self, value):
|
|
super().set_target(value)
|
|
if self.relais:
|
|
if not self.relais.value or not self.relais.target:
|
|
self.log.warning('switch on relais %r %r', self.relais.value, self.relais.target)
|
|
self.relais.write_target(1)
|
|
|
|
|
|
class PIctrl(WrapControlledBy, PI):
|
|
pass
|
|
|
|
|
|
class PI2(PI):
|
|
maxovershoot = Parameter('max. overshoot', FloatRange(0, 100, unit='%'), readonly=False, default=20)
|
|
|
|
def doPoll(self):
|
|
self.output_max = self.target * (1 + 0.01 * self.maxovershoot)
|
|
self.output_min = self.target * (1 - 0.01 * self.maxovershoot)
|
|
super().doPoll()
|
|
|
|
def write_target(self, target):
|
|
if not self.control_active:
|
|
self.output_module.write_target(target)
|
|
super().write_target(target)
|
|
|
|
|
|
class PRtransmitter(CurrentInput):
|
|
rawrange = (0.004, 0.02)
|
|
extendedrange = (0.0036, 0.021)
|
|
|
|
|
|
class PKRgauge(LogVoltageInput):
|
|
rawrange = (1.82, 8.6)
|
|
valuerange = (5e-9, 1000)
|
|
extendedrange = (0.5, 9.5)
|
|
value = Parameter(unit='mbar')
|