Skip to content

Commit a41879c

Browse files
Code Review
1 parent c8e1043 commit a41879c

File tree

6 files changed

+262
-243
lines changed

6 files changed

+262
-243
lines changed

pytest.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[pytest]
2-
adopts = --strict-markers
2+
addopts = --strict-markers
33
markers =
44
hardware: mark tests as run on physical hardware
55
log_cli = true

src/navigate/model/devices/stages/stage_tl_kcube_steppermotor.py

+53-33
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,16 @@
5151
import time
5252
from multiprocessing.managers import ListProxy
5353
from numpy import round
54+
55+
# Third Party Library imports
56+
5457
# Local Imports
5558
from navigate.model.devices.stages.stage_base import StageBase
5659

5760

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)
6164

6265

6366
def build_TLKSTStage_connection(serialnum):
@@ -96,7 +99,6 @@ def build_TLKSTStage_connection(serialnum):
9699
class TLKSTStage(StageBase):
97100
"""Thorlabs KST Stage"""
98101

99-
100102
def __init__(self, microscope_name, device_connection, configuration, device_id=0):
101103
"""Initialize the stage.
102104
@@ -111,18 +113,22 @@ def __init__(self, microscope_name, device_connection, configuration, device_id=
111113
device_id : int
112114
Device ID for the device.
113115
"""
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.
117119
self.axes_mapping = {"f": 1}
118-
120+
119121
#: list: List of KST axes available.
120122
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"]
123127
if type(device_config) == ListProxy:
124128
#: str: Serial number of the stage.
125129
self.serial_number = str(device_config[device_id]["serial_number"])
130+
131+
#: float: Device units per mm.
126132
self.device_unit_scale = device_config[device_id]["device_units_per_mm"]
127133
else:
128134
self.serial_number = device_config["serial_number"]
@@ -134,7 +140,11 @@ def __init__(self, microscope_name, device_connection, configuration, device_id=
134140
else:
135141
self.kst_controller = build_TLKSTStage_connection(self.serial_number)
136142

137-
143+
logger.debug(
144+
f"Connected to Thorlabs KST Stage with serial number "
145+
f"{self.serial_number}"
146+
)
147+
138148
def __del__(self):
139149
"""Delete the KST Connection"""
140150
try:
@@ -143,7 +153,6 @@ def __del__(self):
143153
except AttributeError:
144154
pass
145155

146-
147156
def report_position(self):
148157
"""
149158
Report the position of the stage.
@@ -156,10 +165,13 @@ def report_position(self):
156165
position_dict : dict
157166
Dictionary containing the current position of the stage.
158167
"""
159-
168+
160169
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)
163175
except (
164176
self.kst_controller.TLFTDICommunicationError,
165177
self.kst_controller.TLDLLError,
@@ -169,14 +181,13 @@ def report_position(self):
169181

170182
return self.get_position_dict()
171183

172-
173184
def move_axis_absolute(self, axes, abs_pos, wait_until_done=False):
174185
"""
175186
Implement movement.
176187
177188
Parameters
178189
----------
179-
axis : str
190+
axes : str
180191
An axis. For example, 'x', 'y', 'z', 'f', 'theta'.
181192
abs_pos : float
182193
Absolute position value
@@ -192,21 +203,25 @@ def move_axis_absolute(self, axes, abs_pos, wait_until_done=False):
192203
if axis_abs == -1e50:
193204
return False
194205

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)
197210

198211
if wait_until_done:
199212
stage_pos, n_tries, i = -1e50, 1000, 0
200213
target_pos = axis_abs
201214
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+
)
203219
i += 1
204220
time.sleep(0.01)
205221
if stage_pos != target_pos:
206222
return False
207223
return True
208224

209-
210225
def move_absolute(self, move_dictionary, wait_until_done=False):
211226
"""Move stage along a single axis.
212227
@@ -226,47 +241,52 @@ def move_absolute(self, move_dictionary, wait_until_done=False):
226241
"""
227242

228243
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+
)
230248

231249
return result
232250

233-
234251
def move_to_position(self, position, wait_until_done=False):
235252
"""Perform a move to position
236-
253+
237254
Parameters
238255
----------
239256
position : float
240257
Stage position in mm.
241258
wait_until_done : bool
242259
Block until stage has moved to its new spot.
243-
260+
244261
Returns
245262
-------
246263
success : bool
247264
Was the move successful?
248265
"""
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+
251270
if wait_until_done:
252271
stage_pos, n_tries, i = -1e50, 1000, 0
253272
target_pos = position
254273
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+
)
256278
i += 1
257279
time.sleep(0.01)
258280
if stage_pos != target_pos:
259281
return False
260282
else:
261283
return True
262-
263-
284+
264285
def run_homing(self):
286+
"""Run homing sequence."""
265287
self.kst_controller.KST_HomeDevice(self.serial_number)
266288
self.move_to_position(12.5, wait_until_done=True)
267-
268-
269-
289+
270290
def stop(self):
271291
"""
272292
Stop all stage channels move

src/navigate/model/devices/test_thorlabs_controller.py

-113
This file was deleted.

0 commit comments

Comments
 (0)