173 lines
5.3 KiB
Python
173 lines
5.3 KiB
Python
LED_LEVEL_ROOM_TEMPERATURE = 0.4
|
|
LED_LEVEL_LN2 = 1.0
|
|
|
|
|
|
"""
|
|
wago=ch.psi.pshell.modbus.ModbusTCP|wago-mxsc-1:502|||
|
|
relays=ch.psi.pshell.modbus.DigitalOutputArray|wago 0 16||1000|
|
|
release_local_safety=ch.psi.pshell.modbus.DigitalOutput|wago 0|||
|
|
release_psys_safety=ch.psi.pshell.modbus.DigitalOutput|wago 1|||
|
|
ln2_main_power=ch.psi.pshell.modbus.DigitalOutput|wago 2|||
|
|
rim_heater=ch.psi.pshell.modbus.DigitalOutput|wago 3|||
|
|
phase_separator_ln2=ch.psi.pshell.modbus.DigitalOutput|wago 4|||
|
|
dewar_ln2=ch.psi.pshell.modbus.DigitalOutput|wago 5|||false
|
|
valve_he_chamber=ch.psi.pshell.modbus.DigitalOutput|wago 6|||
|
|
gripper_dryer=ch.psi.pshell.modbus.DigitalOutput|wago 7|||
|
|
valve_1=ch.psi.pshell.modbus.DigitalOutput|wago 8|||
|
|
valve_2=ch.psi.pshell.modbus.DigitalOutput|wago 9|||
|
|
valve_3=ch.psi.pshell.modbus.DigitalOutput|wago 10|||
|
|
valve_4=ch.psi.pshell.modbus.DigitalOutput|wago 11|||
|
|
#spare_do_1=ch.psi.pshell.modbus.DigitalOutput|wago 12|||
|
|
#spare_do_2=ch.psi.pshell.modbus.DigitalOutput|wago 13|||
|
|
#spare_do_3=ch.psi.pshell.modbus.DigitalOutput|wago 14|||
|
|
#spare_do_4=ch.psi.pshell.modbus.DigitalOutput|wago 15|||
|
|
phase_separator_level=ch.psi.pshell.modbus.ReadonlyProcessVariable|wago 0||1000|
|
|
dewar_level=ch.psi.pshell.modbus.ReadonlyProcessVariable|wago 1||1000|
|
|
rim_heater_temp=ch.psi.pshell.modbus.ReadonlyProcessVariable|wago 2||1000|
|
|
air_pressure=ch.psi.pshell.modbus.ReadonlyProcessVariable|wago 3||1000|
|
|
n2_pressure=ch.psi.pshell.modbus.ReadonlyProcessVariable|wago 4||1000|
|
|
#spare_ai_1=ch.psi.pshell.modbus.AnalogInput|wago 5|||
|
|
#spare_ai_2=ch.psi.pshell.modbus.AnalogInput|wago 6|||
|
|
#spare_ai_3=ch.psi.pshell.modbus.AnalogInput|wago 7|||
|
|
led_ctrl_1=ch.psi.pshell.modbus.ProcessVariable|wago 0|||
|
|
led_ctrl_2=ch.psi.pshell.modbus.ProcessVariable|wago 1|||
|
|
led_ctrl_3=ch.psi.pshell.modbus.ProcessVariable|wago 2|||
|
|
"""
|
|
###################################################################################################
|
|
# Leds
|
|
###################################################################################################
|
|
|
|
def set_led_level(level):
|
|
level = max(min(float(level),100.0),0.0)
|
|
set_setting("led_level", level)
|
|
led_ctrl_1.write(led_ctrl_1.config.maxValue * level / 100.0)
|
|
led_ctrl_2.write(led_ctrl_2.config.maxValue * level / 100.0)
|
|
led_ctrl_3.write(led_ctrl_3.config.maxValue * level / 100.0)
|
|
|
|
def get_led_level():
|
|
level = get_setting("led_level")
|
|
return float(0 if level is None else level)
|
|
|
|
def set_led_state(value):
|
|
"""
|
|
Turn leds on and off
|
|
"""
|
|
if value:
|
|
set_led_level(100.0)
|
|
else:
|
|
set_led_level(0.0)
|
|
|
|
def get_led_state():
|
|
"""
|
|
Returns led state (on/off)
|
|
"""
|
|
return led_ctrl_1.read() > 0
|
|
|
|
#TODO: The range should be set automatically reading LN2 sensor.
|
|
def set_led_range(room_temp = True):
|
|
"""
|
|
Led range should be limitted in room temperature
|
|
"""
|
|
max_val = LED_LEVEL_ROOM_TEMPERATURE if room_temp else LED_LEVEL_LN2
|
|
led_ctrl_1.config.maxValue = max_val
|
|
led_ctrl_1.config.save()
|
|
led_ctrl_2.config.maxValue = max_val
|
|
led_ctrl_2.config.save()
|
|
led_ctrl_3.config.maxValue = max_val
|
|
led_ctrl_3.config.save()
|
|
led_ctrl_1.initialize()
|
|
led_ctrl_2.initialize()
|
|
led_ctrl_3.initialize()
|
|
if led_ctrl_1.read() > max_val:
|
|
led_ctrl_1.write(max_val)
|
|
if led_ctrl_2.read() > max_val:
|
|
led_ctrl_2.write(max_val)
|
|
if led_ctrl_3.read() > max_val:
|
|
led_ctrl_3.write(max_val)
|
|
set_led_level(get_led_level())
|
|
|
|
|
|
def is_led_room_temp():
|
|
return led_ctrl_1.config.maxValue <= LED_LEVEL_ROOM_TEMPERATURE
|
|
|
|
|
|
|
|
|
|
###################################################################################################
|
|
# Safety release
|
|
###################################################################################################
|
|
|
|
def release_local():
|
|
"""
|
|
Release local safety
|
|
"""
|
|
release_local_safety.write(False)
|
|
time.sleep(0.01)
|
|
release_local_safety.write(True)
|
|
time.sleep(0.01)
|
|
release_local_safety.write(False)
|
|
|
|
def release_psys():
|
|
"""
|
|
Release psys safety
|
|
"""
|
|
if is_manual_mode():
|
|
raise Exception ("Cannot release PSYS in manual mode")
|
|
release_psys_safety.write(False)
|
|
time.sleep(0.01)
|
|
release_psys_safety.write(True)
|
|
time.sleep(0.01)
|
|
release_psys_safety.write(False)
|
|
|
|
|
|
|
|
###################################################################################################
|
|
# Drier
|
|
###################################################################################################
|
|
MAX_HEATER_TIME = 60000
|
|
|
|
def set_air_stream(state):
|
|
"""
|
|
"""
|
|
valve_1.write(state)
|
|
valve_2.write(not state)
|
|
|
|
|
|
set_heater_chrono = None
|
|
|
|
def monitor_heater_time():
|
|
time.sleep(0.5)
|
|
try:
|
|
while get_heater():
|
|
if set_heater_chrono.isTimeout(MAX_HEATER_TIME):
|
|
set_heater(False)
|
|
log("Heater timeout expired: turned off", False)
|
|
return
|
|
time.sleep(0.1)
|
|
except:
|
|
print sys.exc_info()
|
|
|
|
|
|
def get_heater():
|
|
"""
|
|
"""
|
|
return gripper_dryer.read()
|
|
|
|
|
|
def set_heater(state):
|
|
"""
|
|
"""
|
|
global set_heater_chrono
|
|
if get_heater() != state:
|
|
gripper_dryer.write(state)
|
|
if state:
|
|
set_heater_chrono = Chrono()
|
|
fork(monitor_heater_time)
|
|
|
|
|
|
def get_air_stream():
|
|
"""
|
|
"""
|
|
return valve_1.read()
|
|
|