51
51
import time
52
52
from multiprocessing .managers import ListProxy
53
53
from numpy import round
54
+
55
+ # Third Party Library imports
56
+
54
57
# Local Imports
55
58
from navigate .model .devices .stages .stage_base import StageBase
56
59
57
60
58
- # # Logger Setup
59
- # p = __name__.split(".")[1]
60
- # logger = logging.getLogger(p)
61
+ # Logger Setup
62
+ p = __name__ .split ("." )[1 ]
63
+ logger = logging .getLogger (p )
61
64
62
65
63
66
def build_TLKSTStage_connection (serialnum ):
@@ -96,7 +99,6 @@ def build_TLKSTStage_connection(serialnum):
96
99
class TLKSTStage (StageBase ):
97
100
"""Thorlabs KST Stage"""
98
101
99
-
100
102
def __init__ (self , microscope_name , device_connection , configuration , device_id = 0 ):
101
103
"""Initialize the stage.
102
104
@@ -111,18 +113,22 @@ def __init__(self, microscope_name, device_connection, configuration, device_id=
111
113
device_id : int
112
114
Device ID for the device.
113
115
"""
114
- super ().__init__ (microscope_name , device_connection , configuration , device_id )
115
-
116
- # only initialize the focus axis
116
+ super ().__init__ (microscope_name , device_connection , configuration , device_id )
117
+
118
+ #: dict: Mapping of axes to KST axes. Only initialize focus.
117
119
self .axes_mapping = {"f" : 1 }
118
-
120
+
119
121
#: list: List of KST axes available.
120
122
self .KST_axes = list (self .axes_mapping .values ())
121
-
122
- device_config = configuration ["configuration" ]["microscopes" ][microscope_name ]["stage" ]["hardware" ]
123
+
124
+ device_config = configuration ["configuration" ]["microscopes" ][microscope_name ][
125
+ "stage"
126
+ ]["hardware" ]
123
127
if type (device_config ) == ListProxy :
124
128
#: str: Serial number of the stage.
125
129
self .serial_number = str (device_config [device_id ]["serial_number" ])
130
+
131
+ #: float: Device units per mm.
126
132
self .device_unit_scale = device_config [device_id ]["device_units_per_mm" ]
127
133
else :
128
134
self .serial_number = device_config ["serial_number" ]
@@ -134,7 +140,11 @@ def __init__(self, microscope_name, device_connection, configuration, device_id=
134
140
else :
135
141
self .kst_controller = build_TLKSTStage_connection (self .serial_number )
136
142
137
-
143
+ logger .debug (
144
+ f"Connected to Thorlabs KST Stage with serial number "
145
+ f"{ self .serial_number } "
146
+ )
147
+
138
148
def __del__ (self ):
139
149
"""Delete the KST Connection"""
140
150
try :
@@ -143,7 +153,6 @@ def __del__(self):
143
153
except AttributeError :
144
154
pass
145
155
146
-
147
156
def report_position (self ):
148
157
"""
149
158
Report the position of the stage.
@@ -156,10 +165,13 @@ def report_position(self):
156
165
position_dict : dict
157
166
Dictionary containing the current position of the stage.
158
167
"""
159
-
168
+
160
169
try :
161
- pos = self .kst_controller .KST_GetCurrentPosition (self .serial_number )/ self .device_unit_scale
162
- setattr (self , f"f_pos" , pos )
170
+ pos = (
171
+ self .kst_controller .KST_GetCurrentPosition (self .serial_number )
172
+ / self .device_unit_scale
173
+ )
174
+ setattr (self , "f_pos" , pos )
163
175
except (
164
176
self .kst_controller .TLFTDICommunicationError ,
165
177
self .kst_controller .TLDLLError ,
@@ -169,14 +181,13 @@ def report_position(self):
169
181
170
182
return self .get_position_dict ()
171
183
172
-
173
184
def move_axis_absolute (self , axes , abs_pos , wait_until_done = False ):
174
185
"""
175
186
Implement movement.
176
187
177
188
Parameters
178
189
----------
179
- axis : str
190
+ axes : str
180
191
An axis. For example, 'x', 'y', 'z', 'f', 'theta'.
181
192
abs_pos : float
182
193
Absolute position value
@@ -192,21 +203,25 @@ def move_axis_absolute(self, axes, abs_pos, wait_until_done=False):
192
203
if axis_abs == - 1e50 :
193
204
return False
194
205
195
- self .kst_controller .KST_SetAbsolutePosition (self .serial_number , int (axis_abs * self .device_unit_scale ))
196
- self .kst_controller .KST_MoveAbsolute (self .serial_number )
206
+ self .kst_controller .KST_SetAbsolutePosition (
207
+ self .serial_number , int (axis_abs * self .device_unit_scale )
208
+ )
209
+ self .kst_controller .KST_MoveAbsolute (self .serial_number )
197
210
198
211
if wait_until_done :
199
212
stage_pos , n_tries , i = - 1e50 , 1000 , 0
200
213
target_pos = axis_abs
201
214
while (round (stage_pos , 6 ) != round (target_pos , 6 )) and (i < n_tries ):
202
- stage_pos = self .kst_controller .KST_GetCurrentPosition (self .serial_number )/ self .device_unit_scale
215
+ stage_pos = (
216
+ self .kst_controller .KST_GetCurrentPosition (self .serial_number )
217
+ / self .device_unit_scale
218
+ )
203
219
i += 1
204
220
time .sleep (0.01 )
205
221
if stage_pos != target_pos :
206
222
return False
207
223
return True
208
224
209
-
210
225
def move_absolute (self , move_dictionary , wait_until_done = False ):
211
226
"""Move stage along a single axis.
212
227
@@ -226,47 +241,52 @@ def move_absolute(self, move_dictionary, wait_until_done=False):
226
241
"""
227
242
228
243
result = True
229
- result = (self .move_axis_absolute ("f" , move_dictionary ["f_abs" ], wait_until_done ), result )
244
+ result = (
245
+ self .move_axis_absolute ("f" , move_dictionary ["f_abs" ], wait_until_done ),
246
+ result ,
247
+ )
230
248
231
249
return result
232
250
233
-
234
251
def move_to_position (self , position , wait_until_done = False ):
235
252
"""Perform a move to position
236
-
253
+
237
254
Parameters
238
255
----------
239
256
position : float
240
257
Stage position in mm.
241
258
wait_until_done : bool
242
259
Block until stage has moved to its new spot.
243
-
260
+
244
261
Returns
245
262
-------
246
263
success : bool
247
264
Was the move successful?
248
265
"""
249
- self .kst_controller .KST_MoveToPosition (self .serial_number , position * self .device_unit_scale )
250
-
266
+ self .kst_controller .KST_MoveToPosition (
267
+ self .serial_number , position * self .device_unit_scale
268
+ )
269
+
251
270
if wait_until_done :
252
271
stage_pos , n_tries , i = - 1e50 , 1000 , 0
253
272
target_pos = position
254
273
while (round (stage_pos , 4 ) != round (target_pos , 4 )) and (i < n_tries ):
255
- stage_pos = self .kst_controller .KST_GetCurrentPosition (self .serial_number )/ self .device_unit_scale
274
+ stage_pos = (
275
+ self .kst_controller .KST_GetCurrentPosition (self .serial_number )
276
+ / self .device_unit_scale
277
+ )
256
278
i += 1
257
279
time .sleep (0.01 )
258
280
if stage_pos != target_pos :
259
281
return False
260
282
else :
261
283
return True
262
-
263
-
284
+
264
285
def run_homing (self ):
286
+ """Run homing sequence."""
265
287
self .kst_controller .KST_HomeDevice (self .serial_number )
266
288
self .move_to_position (12.5 , wait_until_done = True )
267
-
268
-
269
-
289
+
270
290
def stop (self ):
271
291
"""
272
292
Stop all stage channels move
0 commit comments