Updated move() to try a few times for the last 2um of motion.
This commit is contained in:
36
attocube.py
36
attocube.py
@ -1,3 +1,4 @@
|
||||
from distutils.command.install_egg_info import to_filename
|
||||
from re import S
|
||||
import time
|
||||
import subprocess
|
||||
@ -246,7 +247,7 @@ class AttocubeAxis(Adjustable):
|
||||
# 2. Soft epics limits
|
||||
|
||||
|
||||
def move(self, val, relative=False, wait=True, ignore_limits=False, confirm_move=True, timeout=300.0, pos_check_delay=0.15, target_gnd=None):
|
||||
def move(self, val, relative=False, wait=True, ignore_limits=True, confirm_move=True, timeout=300.0, pos_check_delay=0.15, target_gnd=None, move_attempts = 5, verbose = False, tolerance=0.3):
|
||||
"""
|
||||
moves Attocube drive to position (emulating pyepics Motor class)
|
||||
|
||||
@ -255,10 +256,12 @@ class AttocubeAxis(Adjustable):
|
||||
val value to move to (float) [Must be provided]
|
||||
relative move relative to current position (T/F) [F]
|
||||
wait whether to wait for move to complete (T/F) [F]
|
||||
ignore_limits try move without regard to limits (T/F) [F]
|
||||
ignore_limits try move without regard to limits (no epics limits implemented yet) (T/F) [T]
|
||||
confirm_move try to confirm that move has begun (T/F) [F]
|
||||
timeout max time for move to complete (in seconds) [300]
|
||||
pos_check_delay delay before checkig motor in position (in seconds) [0.1]
|
||||
move_attempts how many times should the move be attempted if not in limits (attocube often needs to be poked a few times for the last 1um) [5]
|
||||
tolerance when to consider target destination reached (in microns) [0.3]
|
||||
|
||||
return values:
|
||||
==============
|
||||
@ -335,15 +338,28 @@ class AttocubeAxis(Adjustable):
|
||||
if time.time() > tout:
|
||||
return TIMEOUT
|
||||
|
||||
time.sleep(pos_check_delay) # Wait before checking if target value reached. It's necessary as sometimes this PV takes a while to set for the new target value.
|
||||
while self.is_at_target() == False and time.time() <= tout:
|
||||
ca.poll(evt=1.0e-2)
|
||||
|
||||
if self.is_at_target():
|
||||
return SUCCESS
|
||||
|
||||
# Wait before checking if target value reached. It's necessary as sometimes this PV takes a while to set for the new target value.
|
||||
time.sleep(pos_check_delay)
|
||||
|
||||
while self.is_at_target(tolerance=tolerance) == False and time.time() <= tout:
|
||||
# If the value is near the last 2um. Move the cube to setpoint a few more times to get to the right position.
|
||||
if self.is_at_target( tolerance = 2):
|
||||
for attempt in range(move_attempts):
|
||||
if verbose:
|
||||
print(f'move attempt: {attempt+1}')
|
||||
self.pvs.move.put(1, wait=True)
|
||||
time.sleep(2)
|
||||
if self.is_at_target(tolerance=tolerance):
|
||||
if verbose:
|
||||
print(f'Move finished. Had to poke the cube {attempt+1} times to get there though.')
|
||||
return SUCCESS
|
||||
|
||||
print('Position reached within 2um, but not better.')
|
||||
return TIMEOUT
|
||||
|
||||
if self.is_at_target(tolerance=tolerance):
|
||||
return SUCCESS
|
||||
|
||||
|
||||
return UNKNOWN_ERROR
|
||||
|
||||
def gui(self):
|
||||
|
Reference in New Issue
Block a user