Skip to content

Commit 31c6f82

Browse files
author
Luis Carlos Garcia-Peraza Herrera
committed
Homing working :)
1 parent 03db3dc commit 31c6f82

File tree

2 files changed

+48
-49
lines changed

2 files changed

+48
-49
lines changed

configfile.yml

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
# Serial Number of each stage
2-
X_AXIS_SN = '83853044'
3-
Y_AXIS_SN = '83854474'
4-
Z_AXIS_SN = '83853018'
2+
X_AXIS_SN: '83853044'
3+
Y_AXIS_SN: '83854474'
4+
Z_AXIS_SN: '83853018'
55

66
# Scanning Distance Parameters
7-
MAX_DIST = 50 # microns
8-
ENCODER_SCALE = 24576
9-
10-
# Moving 3D Stage Flags
11-
RIGHT = 0
12-
LEFT = 1
13-
DOWN = 0
14-
UP = 1
7+
MAX_DIST: 50 # mm
8+
ENCODER_SCALE: 24576

linearstage.py

Lines changed: 43 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -26,32 +26,38 @@
2626
import pyAPT
2727
import threading
2828
import time
29+
import yaml
2930
from runner import runner_serial
3031

3132
class LinearStage(object):
3233

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-
4534
'''
46-
@brief TODO
35+
@brief Loading configuration from config file.
4736
'''
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
5155

5256
def getInfoAxis(self, axis):
5357
con = pyAPT.MTS50(serial_number = axis)
54-
return con.info()
58+
ret = con.info()
59+
con.close()
60+
return ret
5561

5662
'''
5763
@brief Prints the serial number, model, type, firmware version and servo of all the connected stages.
@@ -82,7 +88,9 @@ def getInfo(self):
8288
'''
8389
def getStatusAxis(self, axis):
8490
con = pyAPT.MTS50(serial_number = axis)
85-
return con.status()
91+
ret = con.status()
92+
con.close()
93+
return ret
8694

8795
'''
8896
@brief Prints the axis, position and velocity of the connected stages.
@@ -127,13 +135,25 @@ def getPos(self, axis = None):
127135
@brief Sends the 3D linear stage to the position (0, 0, 0).
128136
'''
129137
def goHome(self):
138+
# Move to home position of the stage
130139
self.moveAbsolute(self.MAX_DIST, 0, self.MAX_DIST)
140+
141+
# Verify X axis home position
131142
con = pyAPT.MTS50(serial_number = self.X_AXIS_SN)
132143
con.home()
144+
con.close()
145+
146+
# Verify Y axis home position
133147
con = pyAPT.MTS50(serial_number = self.Y_AXIS_SN)
134148
con.home()
149+
con.close()
150+
151+
# Verify Z axis home position
135152
con = pyAPT.MTS50(serial_number = self.Z_AXIS_SN)
136153
con.home()
154+
con.close()
155+
156+
# Move to our reference frame home position
137157
self.moveAbsolute(0, 0, 0)
138158

139159
'''
@@ -143,9 +163,9 @@ def goHome(self):
143163
'''
144164
def rasterScan(self, step, delayMs):
145165
# Going home to reset the encoders
146-
print('Homing... ')
166+
print('Homing... ', end = '', flush = True)
147167
self.goHome()
148-
print("OK\n")
168+
print('OK')
149169

150170
# Setting the initial direction of the X (k) and Y(j) axes
151171
kDir = self.RIGHT
@@ -203,14 +223,9 @@ def moveAbsoluteX(self, x):
203223
con.goto(x, wait = False)
204224
stat = con.status()
205225
while stat.moving:
206-
# out = ' pos %3.2fmm vel %3.2fmm/s'%(stat.position, stat.velocity)
207-
# sys.stdout.write(out)
208226
time.sleep(0.01)
209227
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()
214229

215230
'''
216231
TODO
@@ -220,14 +235,9 @@ def moveAbsoluteY(self, y):
220235
con.goto(y, wait = False)
221236
stat = con.status()
222237
while stat.moving:
223-
# out = ' pos %3.2fmm vel %3.2fmm/s'%(stat.position, stat.velocity)
224-
# sys.stdout.write(out)
225238
time.sleep(0.01)
226239
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()
231241

232242
'''
233243
TODO
@@ -238,14 +248,9 @@ def moveAbsoluteZ(self, z):
238248
con.goto(z, wait = False)
239249
stat = con.status()
240250
while stat.moving:
241-
# out = ' pos %3.2fmm vel %3.2fmm/s'%(stat.position, stat.velocity)
242-
# sys.stdout.write(out)
243251
time.sleep(0.01)
244252
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()
249254

250255
'''
251256
@brief TODO

0 commit comments

Comments
 (0)