-
Notifications
You must be signed in to change notification settings - Fork 0
/
10kHz_Pulsing.py
67 lines (54 loc) · 1.84 KB
/
10kHz_Pulsing.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
from ArduinoGate import ArduinoGate
from Monaco import Monaco
import numpy as np
import time
import sys
#set to 10kHz
laser = Monaco(Port_id = 'com1', power = 50.5, pulse_freq = 1000)
gate = ArduinoGate(port ='com4', baudrate = 9600, timeout = 5)
#Laser Set-up
laser.set_parameters(power = 5, RRD = 100)
#set to 40 pulses
laser.serial_write('BP=40')
def solve_for_y(poly_coeffs, y):
#stackoverflow: https://stackoverflow.com/questions/16827053/solving-for-x-values-of-polynomial-with-known-y-in-scipy-numpy
pc = poly_coeffs.copy()
pc[-1] -= y
return np.roots(pc)
def Watt2RL(desired_power):
#desired power must be in range
polynom = [-3.89619018e-18, 1.43681797e-15, -1.71273526e-13, 8.88299244e-13, 1.54934881e-09, -1.41594079e-07, 4.87160468e-06, -4.11977712e-05, 2.31567217e-04, 2.70908813e-03, -1.08571654e-02]
roots = solve_for_y(polynom, desired_power)
#limit roots between 0 and 100, limit no complex values
rootsReal = [root.real for root in roots if root.imag == 0]
rootsLimited = [root for root in rootsReal if root >= 0 and root <=100]
return rootsLimited[0] #round value???
def powerPercent(percentValue):
maxpower = 5.24
power = (5.24/100)*percentValue
return power
def powerfinder(percentValue):
power = powerPercent(percentValue)
RL = Watt2RL(power)
return RL
#start experiment script
startPower = 5
endPower = 100+1
Step = 5
laserPowers = list(range(startPower,endPower,Step))
laser.stop_lasing()
laser.start_lasing()
for power in laserPowers:
power = powerfinder(power)
laser.set_parameters(power = power)
#Confirmation
testpower = laser.query('?RL')
print('Power: ', testpower)
confirm = input('Fire Laser? (y/n)')
if confirm == 'y':
gate.quick_open(500)
time.sleep(1)
else:
laser.stop_lasing()
sys.exit()
laser.stop_lasing()