-
Notifications
You must be signed in to change notification settings - Fork 0
/
Monaco.py
278 lines (228 loc) · 9.14 KB
/
Monaco.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
#Noah Telerman
#19/10/2020
#Class to interface with Coherent's Monaco laser
from SerialCommander import SerialCommander
import time
import sys
class Monaco(SerialCommander):
def __init__(self, Port_id, baudrate = 19200, power = 80, pulse_freq = 1000, pulse_width = 286, RepRateDivisor = 1, PulsesPerMicroburst = 1, timeout = 5, EOF_string = '\r\n'):
super().__init__(Port_id, baudrate, timeout, EOF_string)
self.power = power
self.pulse_freq = pulse_freq
self.pulse_width = pulse_width
self.RepRateDivisor = RepRateDivisor
self.PulsesPerMicroburst = PulsesPerMicroburst
#dictionary of amplifier rep rates with accepted corresponding no. of microbursts
self.MRR_dictionary = {50000:1, 10000:1, 4000:1, 2000:1, 1000:1, 500:2, 330:3, 250:4, 200:5}
#internal checks - find out the current state of the laser
self.update_internal_states()
#check if serial port is open
if self.check_open() == False:
print('Opening Port \n')
self.openPort()
else:
print('Port Open \n')
#Quick test to make sure serial connection to laser works as expected
#Gives basic info re the laser
def hello_laser(self):
laser_model = self.query('?LM')
print('Laser Model = ', laser_model)
laser_temp = self.query('?BT')
print('Laser temperature = ', laser_temp)
def update_internal_states(self):
self.key_status = self.query('?K')
self.shutter_position = self.query('?S')
self.chiller_status = self.query('?CHEN')
self.diode_status = self.query('?ST')
self.pulse_mode = self.query('?PM')
self.pulse_status = self.query('?PC')
#laser ready check - ready to turn on diodes
if self.key_status == '1' and self.shutter_position == '0' and self.chiller_status == '1':
self.laser_ready = True
else:
self.laser_ready = False
#Diode Ready check - ready to open shutters and fire laser
if self.diode_status == 'On' and self.pulse_status == '1':
self.diode_ready = True
else:
self.diode_ready = False
def status_report(self):
self.update_internal_states()
#display results
print('KEY STATUS: ', self.key_status)
print('Shutter Position: ', self.shutter_position)
print('Chiller Stat: ', self.chiller_status)
print('Diode Status: ', self.diode_status)
print('Pulse Mode: ', self.pulse_mode)
print('Pulse Stat: ', self.pulse_status)
print('diode ready: ', self.diode_ready)
print('laser ready: ', self.laser_ready)
#Pre-flight checks
def start_up(self):
# protocol to power on the laser safely - doesnt turn on diodes
# will need safety checks here
#review laser status
self.update_internal_states()
#Step 1 - Check Chillers Are On
if self.chiller_status == '1':
print('CHILLERS: ', self.chiller_status, 'OK \n')
elif self.chiller_status == '0':
print('CHILLERS: ', self.chiller_status, 'NOT ENABLED - TURN ON CHILLERS \n')
else:
print('Bad Response')
#Step 2 - check keyswitch
if self.key_status == '1':
print('KEY STATUS: ', self.key_status, 'OK \n')
elif self.key_status == '0':
print('KEY STATUS: ', self.key_status, 'KEY NOT TURNED ON \n')
else:
print('Bad Response')
#Check for Faults
faults_status = self.query('?F')
print('FAULT STATUS: ', faults_status)
#check for warnings
warning_status = self.query('?W')
print('WARNING STATUS: ', warning_status)
#Close Shutters
if self.shutter_position == '0':
print('Shutter Position: ', self.shutter_position, 'CLOSED')
elif self.shutter_position == '1':
print('Shutter Position: ', self.shutter_position, 'OPEN')
self.serial_write('P=0')
else:
print('Bad Response')
#Final Laser Checks
print('LASER READY: ', self.laser_ready)
if self.laser_ready == False:
sys.exit()
else:
#Manual Confirmation
laserCheck = input('\n !Confirm Laser Ready! [y/n] \n')
if laserCheck != 'y':
sys.exit()
#Update Laser States (mostly redundant)
self.update_internal_states()
#needs to be run AFTER the setup function, should include checks or include in
#the same function as start_up()
def activate_laser(self, pulsemode):
self.update_internal_states()
if self.laser_ready == True:
#set pulse mode - should add a valueSet function to serial commander to handle this concatonation
pulse_mode = 'PM=' + str(pulsemode)
print('pm = ', pulsemode)
print(self.serial_write(pulse_mode))
for i in range(5):
print(self.serial_read())
print('Pulse Mode: ', self.query('?PM'))
#set power
power_command = 'RL=' + str(self.power)
self.serial_write(power_command)
#Turn on diodes
if self.query('?S') == '0':
self.serial_write('L=1')
elif self.query('?S') != '0':
self.serial_write('S=0')
self.serial_write('L=1')
print('\n Warming Diodes \n')
#wait for diodes to warm
diode_ready = 'OFF'
while diode_ready != 'On':
diode_ready = self.query('?ST')
print('Diode Status: ', diode_ready)
time.sleep(20)
print('\n')
#Turn on pulsing
self.serial_write('PC=1')
else:
print('LASER NOT READY - run start_up step')
sys.exit()
self.update_internal_states()
#Actually projecting the laser beam - safety checks here too
def start_lasing(self):
self.update_internal_states()
if self.diode_ready == True and self.laser_ready == True:
#manual check:
lasercheck2 = input('Confirm Start Lasing [y/n] ')
if lasercheck2 != 'y':
sys.exit()
else:
#Run the Laser:
#Open the shutters
self.serial_write('S=1')
else:
print('LASER NOT READY')
sys.exit()
self.update_internal_states()
#this is broken since adding set funtion...
def set_parameters(self, power = None, pulse_freq = None, RRD = None, pulse_width = None, Bursts = None):
#update internal parameter values
if power == None:
power = self.power
else:
self.power = power
if pulse_freq == None:
pulse_freq = self.pulse_freq
else:
self.pulse_freq = pulse_freq
if pulse_width == None:
pulse_width = self.pulse_width
else:
self.pulse_width = pulse_width
if RRD == None:
RRD = self.RepRateDivisor
else:
self.RepRateDivisor = RRD
# if Bursts = None:
# Bursts = self.PulsesPerMicroburst
# else:
# self.PulsesPerMicroburst = Bursts
#set power
power_command = 'RL=' + str(self.power)
print('power ok')
self.serial_write(power_command)
#set pulse_freq (in kHz) (amplifier rep rate)
#NOTE: this must be a value selected from the drop down menu with compatible no. of microbursts
#SET can also be used to change other parameters
freq_command = 'SET=' + str(self.pulse_freq) + ',' + str(self.pulse_width) + ',' + str(self.RepRateDivisor) + ',' + str(self.MRR_dictionary[self.pulse_freq])
print('SET: ', freq_command)
print(self.serial_write(freq_command))
#wait until diode is ready
self.update_internal_states()
while self.diode_ready != True:
time.sleep(2)
self.update_internal_states()
self.status_report()
self.update_internal_states()
#essentially just closing the shutters
def stop_lasing(self):
print('Closing Shutters')
self.serial_write('S=0')
#should wait for crriage return here instead of using sleep
#(should really do that for all write functions - implement in serial commander)
time.sleep(2)
self.update_internal_states()
#fully shuts down the laser working?
def deactivate_laser(self):
#close the shutters
self.serial_write('S=0')
#turn off the diodes_on
self.serial_write('L=0')
#turn off pulsing
self.serial_write('PC=0')
#check if lasers are cool - make method for continuously testing this
laser_cool = self.query('?ST')
print(laser_cool)
self.diodes_on = False
self.closePort()
# def power_off(self):
# #protocol for turning off the laser
# #probably will need safety protocols here too
#
# #lasers off
# self.write()
#
# #Chillers off
# self.write()
#
# #close port
# self.closePort()