-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_stages.py
175 lines (139 loc) · 4.64 KB
/
test_stages.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
# OpenCV program to perform Edge detection in real time
# import libraries of python OpenCV
# where its functionality resides
import cv2
import ctypes
#from ctypes import *
from ctypes import windll, c_double
#from ctypes import windll, c_double, create_string_buffer
import sys, time
xComPort=5
yComPort=7
zComPort=4
xPS = 1
yPS = 2
zPS = 3
nAxis=1
nPosF=10000
##xDistance=103.0
##yDistance=94.0
xDistance=0.0
yDistance=0.0
zDistance=0.0
nExport=0
##7.8
z_value=3.8
# np is an alias pointing to numpy library
import numpy as np
# capture frames from a camera
import os.path
dll_name = "ps10.dll"
dllabspath = os.path.dirname(os.path.abspath(__file__)) + os.path.sep + dll_name
# load library
# give location of dll
mydll = windll.LoadLibrary(dllabspath)
xstage=mydll.PS10_Connect(xPS, 0, xComPort, 9600,0,0,0,0)
xstage=mydll.PS10_MotorInit(xPS, nAxis)
ystage=mydll.PS10_Connect(yPS, 0, yComPort, 9600,0,0,0,0)
ystage=mydll.PS10_MotorInit(yPS, nAxis)
zstage=mydll.PS10_Connect(zPS, 0, zComPort, 9600,0,0,0,0)
zstage=mydll.PS10_MotorInit(zPS, nAxis)
# loop runs if capturing has been initialized
# 0 is relative, i guess 1 would be absolute
xstage=mydll.PS10_SetTargetMode(xPS, nAxis, 0)
ystage=mydll.PS10_SetTargetMode(yPS, nAxis, 0)
zstage=mydll.PS10_SetTargetMode(zPS, nAxis, 1)
# set velocity
if nPosF > 0:
xstage=mydll.PS10_SetPosF(xPS, nAxis, nPosF)
ystage=mydll.PS10_SetPosF(yPS, nAxis, nPosF)
zstage=mydll.PS10_SetPosF(zPS, nAxis, nPosF)
PS10_GetPositionEx=mydll.PS10_GetPositionEx
PS10_GetPositionEx.restype = ctypes.c_double
xreadout=PS10_GetPositionEx(xPS, nAxis)
yreadout=PS10_GetPositionEx(yPS, nAxis)
zreadout=PS10_GetPositionEx(zPS, nAxis)
xstage=mydll.PS10_GoRef(xPS, nAxis, 4)
xstate = mydll.PS10_GetMoveState(xPS, nAxis)
while xstate > 0:
xstate = mydll.PS10_GetMoveState(xPS, nAxis)
print("Axis is in position.")
xreadout=PS10_GetPositionEx(xPS, nAxis)
print( "Position=%.3f" %(xreadout) )
time.sleep(5)
ystage=mydll.PS10_GoRef(yPS, nAxis, 4)
ystate = mydll.PS10_GetMoveState(yPS, nAxis)
while ystate > 0:
ystate = mydll.PS10_GetMoveState(yPS, nAxis)
print("Axis is in position.")
yreadout=PS10_GetPositionEx(yPS, nAxis)
print( "Position=%.3f" %(yreadout) )
time.sleep(5)
zstage=mydll.PS10_MoveEx(zPS, nAxis, c_double(z_value), 1)
zstate = mydll.PS10_GetMoveState(zPS, nAxis)
while zstate > 0:
zstate = mydll.PS10_GetMoveState(zPS, nAxis)
print("Axis is in position.")
zreadout=PS10_GetPositionEx(zPS, nAxis)
print( "Position=%.3f" %(zreadout) )
zstage=mydll.PS10_SetTargetMode(zPS, nAxis, 0)
time.sleep(5)
measurement = []
global_y_cord = 0
test = True
xstage=mydll.PS10_MoveEx(xPS, nAxis, c_double(xDistance), 1)
xstate = mydll.PS10_GetMoveState(xPS, nAxis)
while(xstate > 0):
#should be read by the stage
xreadout=PS10_GetPositionEx(xPS, nAxis)
print( "Position=%.3f" %(xreadout) )
# reads frames from a camera
xstate = mydll.PS10_GetMoveState(xPS, nAxis)
xreadout=PS10_GetPositionEx(xPS, nAxis)
print( "Position=%.3f" %(xreadout) )
while xstate > 0:
xstate = mydll.PS10_GetMoveState(xPS, nAxis)
time.sleep(5)
ystage=mydll.PS10_MoveEx(yPS, nAxis, c_double(yDistance), 1)
ystate = mydll.PS10_GetMoveState(yPS, nAxis)
while(ystate > 0):
#should be read by the stage
yreadout=PS10_GetPositionEx(yPS, nAxis)
print( "Position=%.3f" %(yreadout) )
# reads frames from a camera
ystate = mydll.PS10_GetMoveState(yPS, nAxis)
time.sleep(5)
xstage=mydll.PS10_MoveEx(xPS, nAxis, c_double(-xDistance), 1)
xstate = mydll.PS10_GetMoveState(xPS, nAxis)
while(xstate > 0):
#should be read by the stage
xreadout=PS10_GetPositionEx(xPS, nAxis)
print( "Position=%.3f" %(xreadout) )
# reads frames from a camera
xstate = mydll.PS10_GetMoveState(xPS, nAxis)
xreadout=PS10_GetPositionEx(xPS, nAxis)
print( "Position=%.3f" %(xreadout) )
while xstate > 0:
xstate = mydll.PS10_GetMoveState(xPS, nAxis)
time.sleep(5)
ystage=mydll.PS10_MoveEx(yPS, nAxis, c_double(-yDistance), 1)
ystate = mydll.PS10_GetMoveState(yPS, nAxis)
while(ystate > 0):
#should be read by the stage
yreadout=PS10_GetPositionEx(yPS, nAxis)
print( "Position=%.3f" %(yreadout) )
# reads frames from a camera
ystate = mydll.PS10_GetMoveState(yPS, nAxis)
time.sleep(5)
zstage=mydll.PS10_MoveEx(zPS, nAxis, c_double(zDistance), 1)
zstate = mydll.PS10_GetMoveState(zPS, nAxis)
while(zstate > 0):
#should be read by the stage
zreadout=PS10_GetPositionEx(zPS, nAxis)
print( "Position=%.3f" %(zreadout) )
# reads frames from a camera
zstate = mydll.PS10_GetMoveState(zPS, nAxis)
# close interface
closingx=mydll.PS10_Disconnect(xPS)
closingy=mydll.PS10_Disconnect(yPS)
closingz=mydll.PS10_Disconnect(zPS)