-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpi_stage_marcus.py
113 lines (91 loc) · 3.41 KB
/
pi_stage_marcus.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
import serial
import time
from math import floor, ceil
import numpy as np
class PI_stage:
def __init__(self, port):
self.ser = serial.Serial(
port=port,
baudrate=57600,
bytesize=serial.EIGHTBITS,
stopbits=serial.STOPBITS_ONE,
parity=serial.PARITY_NONE,
timeout=0.1)
def round_to(self,num):
return floor(num*100)/100
def move_absolute_um(self, pos):
self.sendcmd('MOV 1 ' + str(self.round_to(pos)))
return 0
def get_position_um(self):
self.sendcmd('POS?')
return self.get_response()
def sendcmd(self, command):
command = command + '\n'
self.ser.write(command.encode('utf-8'))
def get_response(self):
res = self.ser.read(100).decode("utf-8")[2:]
print(res)
return res
def setTrigWidth(self):
self.sendcmd('TWC')
for i in np.arange(0, 5):
#if (i%2)==1:
self.sendcmd('TWS 2 ' + str(i) + ' 1')
#else:
# self.sendcmd('TWS 2 ' + str(i) + ' 0')
print('TWS 2 ' + str(i) + ' 1')
self.sendcmd('TWS 2 ' + str(i) + ' 1')
#self.sendcmd('TWS 2 ' + str(80) + ' 0')
#self.sendcmd('TWS 2 ' + str(81) + ' 0')
self.sendcmd('CTO 2 3 4')
def setSweepTime(self, t=100):
#self.sendcmd('WTR 1 '+ str(ceil(t/1.6)) + ' 0')#adjust the period of the sweep, time = num * 0.0001 * 16000 second.
#0.0001s is the time of every servo cycle, 16000 is the number of the point in wave table.
self.sendcmd('WTR 1 '+ str(ceil(t/1.6)) + ' 0')
def setCycleNum(self, n=1):
self.sendcmd('WGC 1 '+ str(n)) # set the cycle number after initiate the wave generator
def setWaveTable(self):
self.sendcmd('WAV 1 X LIN 16000 100 0 16000 0 0') #create the wave table.
def setWaveTableOpenLoop(self):
self.sendcmd('WAV 1 X LIN 4000 150 0 4000 0 0') #create the wave table.
def conWaveTable(self,n=1):
self.sendcmd('WSL 1 '+ str(n)) # connect the wave generator to the wave table No.n
def initWaveGen(self):
#self.sendcmd('WSL 1 1')#Set Connection Of Wave Table To Wave Generator
self.sendcmd('WGO 1 1')#start the wave generator
def stopWaveGen(self):
self.sendcmd('WGO 1 0')
def setClosedLoop(self):
self.sendcmd('SVO 1 1')
def setOpenLoop(self):
self.sendcmd('SVO 1 0')
def stop(self):
self.sendcmd('WGO 1 0')#stop the wave generator
self.sendcmd('STP')
def autoZero(self):
self.sendcmd('ATZ')#stop the wave generator
def close(self):
self.ser.close()
if __name__ == '__main__':
import matplotlib.pyplot as plt
import time
# import numpy as np
stage = PI_stage('COM23')
#stage.move_absolute_um(50)
#stage.sendcmd('GWD? 1 16000 1')
#time.sleep(3)
#scan = stage.get_response()
#scanline = np.fromstring(scan, sep='\n')
#plt.plot(scanline)
#plt.show()
#************************************triger width setting
################stage.setTrigWidth() #!!!Danger!!!
#************************************triger width setting
#stage.move_absolute_um(50)
#stage.setWaveTable()
#stage.conWaveTable()
#time.sleep(11)
#stage.sendcmd('DRR?')
#recordTable = stage.get_response()
#print(recordTable)
#stage.close()