Skip to content

Commit

Permalink
ghs program WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
dleshchev authored and Eli Stavitski committed May 22, 2023
1 parent 975a2af commit 2502145
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 12 deletions.
20 changes: 12 additions & 8 deletions iocs/ioc_ramping.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,16 @@ class RamperIOC(PVGroup):

pvprog = pvproperty(
value=[25.0, 25.0],
doc='pv setpoint array of the ramp program',
doc='pv setpoint array of the pv (usually temperature) ramp program',
max_length=25
)

step = pvproperty(
value=0,
doc="step of the program executed right now"
)


dwell = pvproperty(
value=0.05,
doc="dwell time for the pv setpoint update"
Expand Down Expand Up @@ -117,14 +123,18 @@ async def pv_sp(self, instance, async_lib):
self.time_start = ttime.time()

if self.pause.value == 0:

await self.time_elapsed.write(ttime.time() - self.time_start)
dt = self.time_elapsed.value - self.time_paused.value

if dt < np.max(self.tprog.value):
pv_sp = np.interp(dt, self.tprog.value, self.pvprog.value)
_step_value = np.where(dt<np.array(self.tprog.value))[0][0]
else:
pv_sp = self.pvprog.value[-1]
_step_value = len(self.tprog.value) - 1

if self.step.value != _step_value:
await self.step.write(_step_value)

if self._previous_elapsed_time is not None:
rate = (pv_sp - self.pv_sp.value) / (dt - self._previous_elapsed_time) * 60
Expand Down Expand Up @@ -195,12 +205,6 @@ async def time_paused(self, instance, async_lib):
await async_lib.sleep(self.dwell.value)








if __name__ == '__main__':
ioc_options, run_options = ioc_arg_parser(
default_prefix='XF:08IDB-Ramping:',
Expand Down
9 changes: 9 additions & 0 deletions startup/01-mfc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ class MFC(Device):
rb = Cpt(EpicsSignal, '-I', write_pv='-SP')
sp = Cpt(EpicsSignal,'-SP')

def set(self, flow_rate):
return self.sp.set(flow_rate)


mfc_cart_1 = MFC('XF:08IDB-CT{GC:1-MFC:1}Gas:Flow', name='mfc_cart_CH4')
mfc_cart_1.rb.tolerance = 0.1
Expand All @@ -25,6 +28,12 @@ class ShutoffValve(Device):
close = Cpt(EpicsSignal, 'Cmd:Cls-Cmd')
status =Cpt(EpicsSignal, 'Pos-Sts')

def set(self,status):
if status == 0:
return self.close.set(1)
else:
return self.open.set(1)

# valve_ch4 = ShutoffValve('XF:08IDB-VA{LDOCK-BV:1}', name = 'valve_CH4')
# valve_co = ShutoffValve('XF:08IDB-VA{SPEC:2-BV:1}', name = 'valve_CO')
# valve_h2 = ShutoffValve('XF:08IDB-VA{SCHM-BV:1}', name = 'valve_H2')
Expand Down
29 changes: 26 additions & 3 deletions startup/03_temp.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class Ramper(Device):

tprog = Cpt(EpicsSignal, 'tprog', name='tprog')
pvprog = Cpt(EpicsSignal, 'pvprog', name='pvprog')

step = Cpt(EpicsSignal, 'step', name='step')
dwell = Cpt(EpicsSignal, 'dwell', name='dwell')
safety_thresh = Cpt(EpicsSignal, 'safety_thresh', name='safety_thresh')
safety_timer = Cpt(EpicsSignal, 'safety_timer', name='safety_timer')
Expand Down Expand Up @@ -104,6 +106,7 @@ def __init__(self, human_name, pv_name, pv_units,
pv_output_units='',
ramper=None, *args, **kwargs):
super().__init__(*args, **kwargs)
self.process_program = None
self.human_name = human_name
self.pv_name = pv_name
self.pv_units = pv_units
Expand All @@ -126,6 +129,22 @@ def subscription(value, **kwargs):
self.ramper.pid_enable_name.put(self.enabled.pvname)
self.ramper.pid_output_name.put(self.pv_output.pvname)

def _handle_gas_flow_program(value, old_value, **kwargs):
if value != old_value:
self.handle_gas_flow_program(value, old_value, **kwargs)

self.ramper.step.subscribe(_handle_gas_flow_program)

def handle_gas_flow_program(self, value, old_value, **kwargs):
# print(f'step subscription: {value=}, {old_value=}, {kwargs=}')
if self.process_program is not None:
for i in range(1, 6): # number of gases is hardcoded to 5!
gas, channel, program = self.process_program[f'flowgas{i}'], self.process_program[f'flowchannel{i}'], self.process_program[f'flowprog{i}']
if (gas is not None) and (gas != -1) and (gas != '') and (gas != 'None'):
flow_rate = program[value]
print(f'Program step {value}: Setting {gas} flow to {flow_rate}')
flow(gas, channel=channel, flow_rate=flow_rate)

def enable(self):
self.pid_pv_outout_str.put(self.pv_output.pvname)
self.enabled.put(1)
Expand All @@ -142,11 +161,12 @@ def _check_pid_values(self, kp, ki, kd):
def current_pv_reading(self, offset=0.5):
return (self.pv.get() - offset)

def ramp_start(self, times_list, pv_sp_list):
def ramp_start(self, process_program):
self.process_program = process_program.copy()
self.I.put(0, wait=True)
self.ramper.disable(pv_sp_value=None)
self.ramper.tprog.put(times_list)
self.ramper.pvprog.put(pv_sp_list)
self.ramper.tprog.put(process_program['times'])
self.ramper.pvprog.put(process_program['setpoints'])
self.enable()
self.ramper.enable()

Expand All @@ -159,6 +179,9 @@ def ramp_continue(self):
def ramp_stop(self):
self.disable()
self.ramper.disable()
self.process_program = None





Expand Down
112 changes: 111 additions & 1 deletion startup/04_ghs.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
ghs_ch2_reactor = EpicsSignal('XF:08IDB-UT{Gas:1-Vlv:PSV0101}Cmd', name='ghs_ch2_reactor')
ghs_ch2_exhaust = EpicsSignal('XF:08IDB-UT{Gas:1-Vlv:VSV0101}Cmd', name='ghs_ch2_reactor')


ghs_mnf1_upstream = EpicsSignal('XF:08IDB-UT{Gas:1-Vlv:IIV0109}Cmd', name='ghs_mnf1_upstream')
ghs_mnf2_upstream = EpicsSignal('XF:08IDB-UT{Gas:1-Vlv:IIV0210}Cmd', name='ghs_mnf2_upstream')
ghs_mnf3_upstream = EpicsSignal('XF:08IDB-UT{Gas:1-Vlv:IIV0311}Cmd', name='ghs_mnf3_upstream')
Expand Down Expand Up @@ -253,4 +254,113 @@
arch_iss.pvs.update({ghs_ch2_mfc5_rb.name : ghs_ch2_mfc5_rb.pvname})
arch_iss.pvs.update({ghs_ch2_mfc6_rb.name : ghs_ch2_mfc6_rb.pvname})
arch_iss.pvs.update({ghs_ch2_mfc7_rb.name : ghs_ch2_mfc7_rb.pvname})
arch_iss.pvs.update({ghs_ch2_mfc8_rb.name : ghs_ch2_mfc8_rb.pvname})
arch_iss.pvs.update({ghs_ch2_mfc8_rb.name : ghs_ch2_mfc8_rb.pvname})

def flow(gas, channel=0, flow_rate=0):
if channel == 1:
ch_name = 'ch1'
else:
ch_name = 'ch2'
gases = {'He': {'ch1': {
'mfc':ghs_ch1_mfc1_sp,
'selector': ghs_mnf1_gas_selector,
'manifold':'1',
'valves': [ghs_mnf1_upstream, ghs_mnf1_ch1_dnstream]},
'ch2': {
'mfc': ghs_ch2_mfc1_sp,
'selector': ghs_mnf1_gas_selector,
'manifold': '1',
'valves': [ghs_mnf1_upstream, ghs_mnf1_ch2_dnstream]},
'full_gas_name': 'Helium'},
'Ar': {'ch1': {
'mfc':ghs_ch1_mfc1_sp,
'selector': ghs_mnf1_gas_selector,
'manifold': '1',
'valves': [ghs_mnf1_upstream, ghs_mnf1_ch1_dnstream]},
'ch2': {
'mfc': ghs_ch2_mfc1_sp,
'selector': ghs_mnf1_gas_selector,
'manifold': '1',
'valves': [ghs_mnf1_upstream, ghs_mnf1_ch2_dnstream]},
'full_gas_name': 'Argon'},
'N2': {'ch1': {
'mfc':ghs_ch1_mfc1_sp,
'selector': ghs_mnf1_gas_selector,
'manifold': '1',
'valves': [ghs_mnf1_upstream, ghs_mnf1_ch1_dnstream]},
'ch2': {
'mfc': ghs_ch2_mfc1_sp,
'selector': ghs_mnf1_gas_selector,
'manifold': '1',
'valves': [ghs_mnf1_upstream, ghs_mnf1_ch2_dnstream]},
'full_gas_name': 'Nitrogen'},
'O2': {'ch1': {
'mfc': ghs_ch1_mfc6_sp,
'selector': None,
'manifold': None,
'valves': [ghs_mnf6_upstream, ghs_mnf6_ch1_dnstream]},
'ch2': {
'mfc': ghs_ch2_mfc6_sp,
'selector': None,
'manifold': None,
'valves': [ghs_mnf6_upstream, ghs_mnf6_ch2_dnstream]},
'full_gas_name': 'Oxygen'},
'CO2': {'ch1': {
'mfc': ghs_ch1_mfc8_sp,
'selector': None,
'manifold': None,
'valves': [ghs_mnf8_upstream, ghs_mnf8_ch1_dnstream]},
'ch2': {
'mfc': ghs_ch2_mfc8_sp,
'selector': None,
'manifold': None,
'valves': [ghs_mnf8_upstream, ghs_mnf8_ch2_dnstream]},
'full_gas_name': 'Carbon Dioxide'},
'CH4': {'ch1': {
'mfc': mfc_cart_1,
'selector': None,
'manifold': None,
'valves': [valve_ch4]},
'ch2': {
'mfc': mfc_cart_1,
'selector': None,
'manifold': None,
'valves': [valve_ch4]},
'full_gas_name': 'Methane'},
'CO': {'ch1': {
'mfc': mfc_cart_2,
'selector': None,
'manifold': None,
'valves': [valve_co]},
'ch2': {
'mfc': mfc_cart_2,
'selector': None,
'manifold': None,
'valves': [valve_co]},
'full_gas_name': 'Carbon Monoxide'},
'H2': {'ch1': {
'mfc': mfc_cart_3,
'selector': None,
'manifold': None,
'valves': [valve_h2]},
'ch2': {
'mfc': mfc_cart_3,
'selector': None,
'manifold': None,
'valves': [valve_h2]},
'full_gas_name': 'Hydrogen'}
}
#open or close valves
for valve in gases[gas][ch_name]['valves']:
if flow_rate > 0:
valve.set(1)
else:
valve.set(0)
if gases[gas][ch_name]['manifold']:
indx_mnf = gases[gas][ch_name]['manifold']
gas_command = ghs['manifolds'][indx_mnf]['gases'][gases[gas]['full_gas_name']]
# print(f'Gas command {gas_command}')
ghs['manifolds'][indx_mnf]['gas_selector'].set(gas_command)

gases[gas][ch_name]['mfc'].set(flow_rate)

2 changes: 2 additions & 0 deletions startup/98_safety_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ def full_stop_for_sample_envs():
print('DISABLING ALL SAMPLE ENVIRONMENTS')
print()
print()
# disable_all_envs() # from /03_temp.py
try:
disable_all_envs() # from /03_temp.py
except Exception as e:
print(e)
print('COULD NOT DISABLE SAMPLE ENVIRONMENTS: IOCs NOT FOUND')
ttime.sleep(0.5)
# kill_pid_ioc() # from /00_startup.py
try:
kill_pid_ioc() # from /00_startup.py
except Exception as e:
Expand Down

0 comments on commit 2502145

Please sign in to comment.