Skip to content

Commit 94b820d

Browse files
committed
microscope: fix backlash compensation to minimize moves
1 parent 6e22b51 commit 94b820d

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

software/control/microscope.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -382,15 +382,23 @@ def get_z(self):
382382
return self.stage.get_pos().z_mm
383383

384384
def move_z_to(self, z_mm, blocking=True):
385-
self.stage.move_z_to(z_mm, blocking=blocking)
386-
clear_backlash = z_mm >= self.stage.get_pos().z_mm
387-
# clear backlash if moving backward in open loop mode
388-
if blocking and clear_backlash:
385+
# We want the z axis to rest on the "down" (wrt gravity) direction of gravity. So if we
386+
# are moving in the positive (up) z direction, we need to move past our mark a bit then
387+
# back. If we are already moving in the "down" position, we can move straight there.
388+
need_clear_backlash = z_mm >= self.stage.get_pos().z_mm
389+
390+
# NOTE(imo): It seems really tricky to only clear backlash if via the blocking call?
391+
if blocking and need_clear_backlash:
389392
distance_to_clear_backlash = self.stage.get_config().Z_AXIS.convert_to_real_units(
390393
max(160, 20 * self.stage.get_config().Z_AXIS.MICROSTEPS_PER_STEP)
391394
)
392-
self.stage.move_z(-distance_to_clear_backlash)
393-
self.stage.move_z(distance_to_clear_backlash)
395+
396+
# Move past our final position, so we can move down to the final position and
397+
# rest on the downside of the drive mechanism.
398+
clamped_z_backlash_pos = min(z_mm + distance_to_clear_backlash, self.stage.get_config().Z_AXIS.MAX_POSITION)
399+
self.stage.move_z_to(clamped_z_backlash_pos, blocking=blocking)
400+
401+
self.stage.move_z_to(z_mm)
394402

395403
def start_live(self):
396404
self.camera.start_streaming()

0 commit comments

Comments
 (0)