-
Notifications
You must be signed in to change notification settings - Fork 0
/
gasControl.py
301 lines (255 loc) · 12.9 KB
/
gasControl.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
"""Valves, temperature, and Mass flow control module
__author__ = "Jorge Moncada Vivas"
__version__ = "3.0"
__email__ = "[email protected]"
__date__ = "10/24/2024"
Notes:
By Jorge Moncada Vivas and contributions of Ryuichi Shimogawa
"""
import time
import logging
import json
from valves import create_valves
from eurothermSerial import EuroSerial
from eurothermTCP import EuroTCP
from flowSMS import FlowSMS
from utils import convert_com_port
from pathlib import Path
try:
import tomllib
except ImportError:
import tomli as tomllib
logging.basicConfig(
level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s"
)
# ███████╗ █████╗ ███████╗███████╗████████╗ ██████╗ █████╗ ████████╗
# ██╔════╝██╔══██╗██╔════╝██╔════╝╚══██╔══╝██╔════╝██╔══██╗╚══██╔══╝
# █████╗ ███████║███████╗███████╗ ██║ ██║ ███████║ ██║
# ██╔══╝ ██╔══██║╚════██║╚════██║ ██║ ██║ ██╔══██║ ██║
# ██║ ██║ ██║███████║███████║ ██║ ╚██████╗██║ ██║ ██║
# ╚═╝ ╚═╝ ╚═╝╚══════╝╚══════╝ ╚═╝ ╚═════╝╚═╝ ╚═╝ ╚═╝
def create_eurotherm(config, flowSMS):
if "HOST_EURO" in config and "PORT_EURO" in config:
return EuroTCP(config["HOST_EURO"], config["PORT_EURO"], flowSMS)
else:
euro_comport = convert_com_port(config["COM_TMP"])
euro_sub = config["SUB_ADD_TMP"]
return EuroSerial(euro_comport, euro_sub, flowSMS)
class GasControl:
def __init__(self, config_file="config.json") -> None:
"""Initialize the gas control system.
Args:
config_file (str): Path to configuration file [default: "config.json"]
"""
with open(config_file, "r") as file:
config = json.load(file)
gas_config_path = Path(__file__).parent / "gases.toml"
with open(gas_config_path, "rb") as f:
self.gas_config = tomllib.load(f)
self.config = config
self.valves = create_valves(config, self.gas_config)
self.flowSMS = FlowSMS(config, self.gas_config, self.valves)
self.eurotherm = create_eurotherm(config, self.flowSMS)
# ██╗ ██╗ █████╗ ██╗ ██╗ ██╗███████╗███████╗
# ██║ ██║██╔══██╗██║ ██║ ██║██╔════╝██╔════╝
# ██║ ██║███████║██║ ██║ ██║█████╗ ███████╗
# ╚██╗ ██╔╝██╔══██║██║ ╚██╗ ██╔╝██╔══╝ ╚════██║
# ╚████╔╝ ██║ ██║███████╗╚████╔╝ ███████╗███████║
# ╚═══╝ ╚═╝ ╚═╝╚══════╝ ╚═══╝ ╚══════╝╚══════╝
def valve_C(self, position: str):
"""Function that selects the position of Valve C (Reaction mode selection module)
Args:
position (str): Position of the valve, can be "off" or "on"
"off" means that the valve is in the position Gas Line A/B -> reactor
"on" means that the valve is in the position Gas Line A/B -> gas loop
"""
if position == "OFF":
self.valves.move_valve_to_position("C", position)
print("Gas Line A/B valve position: off (Gas Line A/B -> reactor)")
elif position == "ON":
self.valves.move_valve_to_position("C", position)
print("Gas Line A/B valve position: on (Gas Line A/B -> loop)")
def valve_B(self, position: str):
"""Function that selects the position of Valve B (Reaction mode selection module)
Args:
position (str): Position of the valve, can be "off" or "on"
"off" means that the valve is in the position Gas Line A -> reactor
"on" means that the valve is in the position Gas Line B -> reactor
"""
if position == "OFF":
self.valves.move_valve_to_position("B", position)
print(
"Valve B position: off \n(Gas Line A -> reactor)\n(Gas Line B -> pulses)"
)
elif position == "ON":
self.valves.move_valve_to_position("B", position)
print(
"Valve B position: off \n(Gas Line B -> reactor)\n(Gas Line A -> pulses)"
)
def valve_A(self, position: str):
"""Function that selects the position of Valve A (Reaction mode selection module)
Args:
position (str): Position of the valve, can be "off" or "on"
"off" means that the valve is in the loop 1 -> reactor, loop 2 -> vent
"on" means that the valve is in the loop 2 -> reactor, loop 1 -> vent
"""
if position == "OFF":
self.valves.move_valve_to_position("A", position)
print(
"Pulses line valve position: off (Gas Line A -> loop 1 -> vent / Gas Line B -> loop 2 -> reactor)"
)
elif position == "ON":
self.valves.move_valve_to_position("A", position)
print(
"Pulses line valve position: on (Gas Line B -> loop 2 -> vent / Gas Line A -> loop 1 -> reactor)"
)
def cont_mode_A(self, verbose: bool = True):
"""Function that selects the position of the valves in the reaction mode selection
module to the continuous mode gas line A mode
Gas Line A -> reactor ... Gas Line B -> loops -> vent
Args:
verbose (bool): If True, prints the valve status [default: True]
"""
self.valves.move_valve_to_position("A", "OFF")
self.valves.move_valve_to_position("B", "OFF")
self.valves.move_valve_to_position("C", "OFF")
if verbose:
print("Valves operation mode: continuous mode Gas Line A")
print("Gas Line A -> reactor ... Gas Line B -> loops -> vent")
def cont_mode_B(self, verbose: bool = True):
"""Function that selects the position of the valves in the reaction mode selection
module to the continuous mode gas line B mode
Gas Line B -> reactor ... Gas Line A -> loops -> waste
Args:
verbose (bool): If True, prints the valve status [default: True]
"""
self.valves.move_valve_to_position("A", "OFF")
self.valves.move_valve_to_position("B", "ON")
self.valves.move_valve_to_position("C", "OFF")
if verbose:
print("Valves operation mode: continuous mode Gas Line B")
print("Gas Line B -> reactor ... Gas Line A -> loops -> waste")
def pulses_loop_mode_A(self, verbose=True):
"""Function that selects the position of the valves in the reaction mode selection
module to the pulses loop mode
Gas Line B -> loop 2 -> reactor ... Gas Line A -> loop 1 -> vent
Args:
verbose (bool): If True, prints the valve status [default: True]
"""
self.valves.move_valve_to_position("A", "ON")
self.valves.move_valve_to_position("B", "OFF")
self.valves.move_valve_to_position("C", "ON")
if verbose:
print("Valves operation mode: pulses with gas loops")
print("Gas Line B -> loop 2 -> reactor ... Gas Line A -> loop 1 -> vent")
def pulses_loop_mode_B(self, verbose=True):
"""Function that selects the position of the valves in the reaction mode selection
module to the pulses loop mode
Gas Line B -> loop 2 -> reactor ... Gas Line A -> loop 1 -> vent
Args:
verbose (bool): If True, prints the valve status [default: True]
"""
self.valves.move_valve_to_position("A", "ON")
self.valves.move_valve_to_position("B", "ON")
self.valves.move_valve_to_position("C", "ON")
if verbose:
print("Valves operation mode: pulses with gas loops")
print("Gas Line B -> loop 2 -> reactor ... Gas Line A -> loop 1 -> vent")
def send_pulses_loop_A(self, pulses, time_bp):
# total_time_loop = float(pulses) * float(time_bp)
# total_time.append(total_time_loop)
# tmp.pulse_ON()
self.pulses_loop_mode_A()
int_pulses = int(pulses)
float_time = float(time_bp)
print("Valves operation mode: pulses (dual loop alternation)")
print(
f"Number of pulses (loop): {pulses}\nTime in between pulses (s): {time_bp}"
)
print(
"Valve Position Off: Gas Line B -> loop 2 -> reactor /// Gas Line A -> loop 1 -> vent"
)
print(
"Valve Position On: Gas line B -> loop 1 -> reactor /// Gas Line A -> loop 2 -> vent"
)
for pulse in range(0, int_pulses):
# tmp.pulse_ON()
self.valves.write(
b"/ATO"
) # Comand that executes the pulses valve actuation
print(
f"Sending pulse number {pulse+1} of {int_pulses}", end="\r"
) # Pulse status message for terminal window
time.sleep(float_time) # Conversion of seconds to miliseconds
# tmp.pulse_OFF()
print("Pulses have finished") # End of the pulses message
def send_pulses_loop_B(self, pulses, time_bp):
# total_time_loop = float(pulses) * float(time_bp)
# total_time.append(total_time_loop)
# tmp.pulse_ON()
self.pulses_loop_mode_B()
int_pulses = int(pulses)
float_time = float(time_bp)
print("Valves operation mode: pulses (dual loop alternation)")
print(
f"Number of pulses (loop): {pulses}\nTime in between pulses (s): {time_bp}"
)
print(
"Valve Position Off: Gas Line A -> loop 2 -> reactor /// Gas Line B -> loop 1 -> vent"
)
print(
"Valve Position On: Gas Line A -> loop 1 -> reactor /// Gas Line B -> loop 2 -> vent"
)
for pulse in range(0, int_pulses):
# tmp.pulse_ON()
self.valves.write(
b"/ATO"
) # Comand that executes the pulses valve actuation
print(
f"Sending pulse number {pulse+1} of {int_pulses}", end="\r"
) # Pulse status message for terminal window
time.sleep(float_time) # Conversion of seconds to miliseconds
# tmp.pulse_OFF()
print("Pulses have finished") # End of the pulses message
def send_pulses_valve_A(self, pulses, time_vo, time_bp):
# total_time_loop = (float(pulses) * float(time_bp)) + (float(pulses) * float(time_vo))
# total_time.append(total_time_loop)
valve_actuation_time = 0.145
self.cont_mode_A()
int_pulses = int(pulses) # Preparing the integer input for the loop range
float_time_vo = float(
time_vo
) # Preparing the float input for the sleep function vo
float_time_bp = float(
time_bp
) # Preparing the float input for the sleep function bp
print("Valves operation mode: pulses (valve)")
print(
f"Number of pulses (valve): {pulses}\nTime valve open (s): {time_vo}\nTime in between pulses (s): {time_bp}"
)
print(
"Valve Position Off: mixing line -> reactor /// pulses line carrier -> loop 2 -> loop 1 -> waste"
)
print(
"Valve Position On: pulses line carrier -> reactor /// mixing line -> loop 2 -> loop 1 -> waste"
)
for pulse in range(0, int_pulses):
self.cont_mode_B() # Comand that executes the pulses valve actuation
time.sleep(
float_time_vo + valve_actuation_time
) # Conversion of seconds to miliseconds
self.cont_mode_A() # Comand that executes the pulses valve actuation
print(
f"Sending pulse number {pulse+1} of {int_pulses}", end="\r"
) # Pulse status message for terminal window
time.sleep(float_time_bp) # Conversion of seconds to miliseconds
print("Pulses have finished") # End of the pulses message
if __name__ == "__main__":
gc = GasControl()
gc.cont_mode_A()
gc.valves.display_valve_positions()
gc.flowSMS.setpoints(
Ar_A=15,
Ar_B=15,
)
gc.flowSMS.status()