26
26
import pyAPT
27
27
import threading
28
28
import time
29
+ import yaml
29
30
from runner import runner_serial
30
31
31
32
class LinearStage (object ):
32
33
33
- # Constants
34
- X_AXIS_SN = '83853044'
35
- Y_AXIS_SN = '83854474'
36
- Z_AXIS_SN = '83853018'
37
- MAX_DIST = 50 # microns
38
- ENCODER_SCALE = 24576
39
- MAX_DIST_ENCODER = MAX_DIST * ENCODER_SCALE
40
- RIGHT = 0
41
- LEFT = 1
42
- DOWN = 0
43
- UP = 1
44
-
45
34
'''
46
- @brief TODO
35
+ @brief Loading configuration from config file.
47
36
'''
48
- # def __init__(self):
49
- # self.running = True
50
- # self.threads = []
37
+ def __init__ (self ):
38
+ config = yaml .load (open ("configfile.yml" )) # $ pip install pyyaml
39
+
40
+ # Reading linear stage serial number from config file
41
+ self .X_AXIS_SN = config ["X_AXIS_SN" ]
42
+ self .Y_AXIS_SN = config ["Y_AXIS_SN" ]
43
+ self .Z_AXIS_SN = config ["Z_AXIS_SN" ]
44
+
45
+ # Reading distance range and scaling from config file
46
+ self .MAX_DIST = config ["MAX_DIST" ]
47
+ self .ENCODER_SCALE = config ["ENCODER_SCALE" ]
48
+ self .MAX_DIST_ENCODER = self .MAX_DIST * self .ENCODER_SCALE
49
+
50
+ # Moving 3D Stage Flags
51
+ self .RIGHT = 0
52
+ self .LEFT = 1
53
+ self .DOWN = 0
54
+ self .UP = 1
51
55
52
56
def getInfoAxis (self , axis ):
53
57
con = pyAPT .MTS50 (serial_number = axis )
54
- return con .info ()
58
+ ret = con .info ()
59
+ con .close ()
60
+ return ret
55
61
56
62
'''
57
63
@brief Prints the serial number, model, type, firmware version and servo of all the connected stages.
@@ -82,7 +88,9 @@ def getInfo(self):
82
88
'''
83
89
def getStatusAxis (self , axis ):
84
90
con = pyAPT .MTS50 (serial_number = axis )
85
- return con .status ()
91
+ ret = con .status ()
92
+ con .close ()
93
+ return ret
86
94
87
95
'''
88
96
@brief Prints the axis, position and velocity of the connected stages.
@@ -127,13 +135,25 @@ def getPos(self, axis = None):
127
135
@brief Sends the 3D linear stage to the position (0, 0, 0).
128
136
'''
129
137
def goHome (self ):
138
+ # Move to home position of the stage
130
139
self .moveAbsolute (self .MAX_DIST , 0 , self .MAX_DIST )
140
+
141
+ # Verify X axis home position
131
142
con = pyAPT .MTS50 (serial_number = self .X_AXIS_SN )
132
143
con .home ()
144
+ con .close ()
145
+
146
+ # Verify Y axis home position
133
147
con = pyAPT .MTS50 (serial_number = self .Y_AXIS_SN )
134
148
con .home ()
149
+ con .close ()
150
+
151
+ # Verify Z axis home position
135
152
con = pyAPT .MTS50 (serial_number = self .Z_AXIS_SN )
136
153
con .home ()
154
+ con .close ()
155
+
156
+ # Move to our reference frame home position
137
157
self .moveAbsolute (0 , 0 , 0 )
138
158
139
159
'''
@@ -143,9 +163,9 @@ def goHome(self):
143
163
'''
144
164
def rasterScan (self , step , delayMs ):
145
165
# Going home to reset the encoders
146
- print ('Homing... ' )
166
+ print ('Homing... ' , end = '' , flush = True )
147
167
self .goHome ()
148
- print ("OK \n " )
168
+ print ('OK' )
149
169
150
170
# Setting the initial direction of the X (k) and Y(j) axes
151
171
kDir = self .RIGHT
@@ -203,14 +223,9 @@ def moveAbsoluteX(self, x):
203
223
con .goto (x , wait = False )
204
224
stat = con .status ()
205
225
while stat .moving :
206
- # out = ' pos %3.2fmm vel %3.2fmm/s'%(stat.position, stat.velocity)
207
- # sys.stdout.write(out)
208
226
time .sleep (0.01 )
209
227
stat = con .status ()
210
- # l = len(out)
211
- # sys.stdout.write('\b'*l)
212
- # sys.stdout.write(' '*l)
213
- # sys.stdout.write('\b'*l)
228
+ con .close ()
214
229
215
230
'''
216
231
TODO
@@ -220,14 +235,9 @@ def moveAbsoluteY(self, y):
220
235
con .goto (y , wait = False )
221
236
stat = con .status ()
222
237
while stat .moving :
223
- # out = ' pos %3.2fmm vel %3.2fmm/s'%(stat.position, stat.velocity)
224
- # sys.stdout.write(out)
225
238
time .sleep (0.01 )
226
239
stat = con .status ()
227
- # l = len(out)
228
- # sys.stdout.write('\b'*l)
229
- # sys.stdout.write(' '*l)
230
- # sys.stdout.write('\b'*l)
240
+ con .close ()
231
241
232
242
'''
233
243
TODO
@@ -238,14 +248,9 @@ def moveAbsoluteZ(self, z):
238
248
con .goto (z , wait = False )
239
249
stat = con .status ()
240
250
while stat .moving :
241
- # out = ' pos %3.2fmm vel %3.2fmm/s'%(stat.position, stat.velocity)
242
- # sys.stdout.write(out)
243
251
time .sleep (0.01 )
244
252
stat = con .status ()
245
- # l = len(out)
246
- # sys.stdout.write('\b'*l)
247
- # sys.stdout.write(' '*l)
248
- # sys.stdout.write('\b'*l)
253
+ con .close ()
249
254
250
255
'''
251
256
@brief TODO
0 commit comments