Skip to content

Commit

Permalink
[fix] In binary autofocus move to best position even when minimum ste…
Browse files Browse the repository at this point in the history
…psize is reached (#2840)

Break the loop after moving to the best position: Otherwise the focus will not be at the best position
when clipping left and right have caused left and right to be equal, but them not being equal to the center / best position.
  • Loading branch information
tepals authored Nov 20, 2024
1 parent 9cd5e9a commit 2bad431
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/odemis/acq/align/autofocus.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,6 @@ def _DoBinaryFocus(future, detector, emt, focus, dfbkg, good_focus, rng_focus):
if future._autofocus_state == CANCELLED:
raise CancelledError()

if left == right:
logging.info("Seems to have reached minimum step size (at %g m)", 2 * step_factor * min_step)
break

# if best focus was found at the center
if i_max == 1:
step_factor /= 2
Expand All @@ -335,6 +331,13 @@ def _DoBinaryFocus(future, detector, emt, focus, dfbkg, good_focus, rng_focus):
# Clip best_pos in case the hardware reports a position outside of the range.
best_pos = max(rng[0], min(best_pos, rng[1]))
focus.moveAbsSync({"z": best_pos})

if left == right:
# Do this after moving to the best position, because clipping left and right can cause
# left and right to be equal, even when both are unequal to the best position.
logging.info("Seems to have reached minimum step size (at %g m)", 2 * step_factor * min_step)
break

step_cntr += 1

worst_fm = min(focus_levels.values())
Expand Down

0 comments on commit 2bad431

Please sign in to comment.