Skip to content

Commit 3132dfc

Browse files
committed
Added some homing and limit finidng code to ludl stage control.
1 parent 8454f33 commit 3132dfc

File tree

1 file changed

+54
-3
lines changed

1 file changed

+54
-3
lines changed

microscope/stages/ludl.py

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,30 @@ def move_to_absolute_position(self, axis: bytes, pos: float) -> None:
246246
axisname=AXIS_MAPPER[axis]
247247
self.move_command(bytes('MOVE {0}={1}'.format(axisname,
248248
str(pos)),'ascii'))
249+
def move_to_limit(self,axis: bytes,speed: int):
250+
axisname=AXIS_MAPPER[axis]
251+
self.get_command(bytes('SPIN {0}={1}'.format(axisname,speed),'ascii'))
252+
253+
def motor_moving(self,axis: bytes) -> int:
254+
axisname=AXIS_MAPPER[axis]
255+
reply=self.get_command(bytes('RDSTAT {0}'.format(axisname),'ascii'))
256+
flags=int(reply.strip()[3:])
257+
return (flags&1)
258+
259+
def set_speed(self, axis: bytes, speed: int) -> None:
260+
axisname=AXIS_MAPPER[axis]
261+
self.get_command(bytes('SPEED {0}={1}'.format(axisname,speed),'ascii'))
262+
249263

264+
def wait_for_motor_stop(self,axis: bytes):
265+
while(self.motor_moving(axis)):
266+
time.sleep(0.1)
267+
268+
269+
def reset_position(self, axis: bytes):
270+
axisname=AXIS_MAPPER[axis]
271+
self.get_command(bytes('HERE {0}=0'.format(axisname),'ascii'))
272+
250273
def get_absolute_position(self, axis: bytes) -> float:
251274
axisname=AXIS_MAPPER[axis]
252275
position=self.get_command(bytes('WHERE {0}'.format(axisname),'ascii'))
@@ -284,6 +307,11 @@ def __init__(self, dev_conn: _LudlController, axis: str) -> None:
284307
super().__init__()
285308
self._dev_conn = dev_conn
286309
self._axis = axis
310+
# not a good solution as min/max are used to build the stage map in
311+
# mosaic etc... Maybe we just need to know it!
312+
self.min_limit = 0.0
313+
self.max_limit = 0.0
314+
self.set_speed(100000)
287315

288316
def move_by(self, delta: float) -> None:
289317
self._dev_conn.move_by_relative_position(self._axis, int(delta))
@@ -300,10 +328,33 @@ def position(self) -> float:
300328

301329
@property
302330
def limits(self) -> microscope.AxisLimits:
303-
min_limit = -1000000 #self._dev_conn.get_limit_min(self._axis)
304-
max_limit = 1000000 #self._dev_conn.get_limit_max(self._axis)
305-
return microscope.AxisLimits(lower=min_limit, upper=max_limit)
331+
return microscope.AxisLimits(lower=self.min_limit, upper=self.max_limit)
332+
333+
def home(self) -> None:
334+
self.find_limits()
335+
self.move_to(self.max_limit/2)
336+
337+
def set_speed(self, speed: int) -> None:
338+
self._dev_conn.set_speed(self._axis, speed)
339+
340+
def find_limits(self,speed = 100000):
341+
#drive axis to minimum pos, zero and then drive to max position
342+
self._dev_conn.move_to_limit(self._axis,-speed)
343+
# spin moves dont set the status info need to query the motor
344+
# status byte
345+
self._dev_conn.wait_for_motor_stop(self._axis)
346+
# reset positon to zero.
347+
print(self.position)
348+
self._dev_conn.reset_position(self._axis)
349+
self.min_limit=0.0
350+
# move to positive limit
351+
self._dev_conn.move_to_limit(self._axis,speed)
352+
self._dev_conn.wait_for_motor_stop(self._axis)
353+
self.max_limit=self.position
354+
return self.limits
355+
306356

357+
307358
class _LudlStage(microscope.abc.Stage):
308359
def __init__(
309360
self, conn: _LudlController, **kwargs

0 commit comments

Comments
 (0)