Skip to content

Autofocus Restart Bug

John Evans requested to merge johnevans/kstars:autofocusrestartbug into master

This fixes a bug in Focus whereby under the following conditions the Autofocus restart is not performed correctly:

  1. Autofocus fails.
  2. Current focuser position is within 1 tick of initial focuser position at the start of Autofocus. I think this limits the situation to an R2 failure and a more generic failure part way though an Autofocus where the current position matches the start position (unlikely). In practice this bug is quite unlikely to occur IMHO. I think its been present for a while and isn't new.

The bug is that the function changePosition detects that the focuser has <= 1 to reset its position and does not attempt to move the focuser (as some focusers can stall on 0/1 tick moves). The restart logic is triggered off the completion of the reset position movement, so in this case it's not triggered.

The code then (incorrectly) takes another focus frame and tries to process the result (which is the same data as before + the 1 new frame), i.e. Autofocus is not rerun.

This breaks Analyze because Analyze relies on matching pairs of startingAutofocus() and either autofocusComplete() or autofocusAborted() messages. With the bug, Analyze receives startingAutofocus() followed by autofocusAborted() followed by autofocusComplete(). The start time in Analyze is set by startingAutofocus() and reset to -1 after autofocusComplete() and autofocusAborted().

Coded and tested on the Sim. I would rather not rush this release because:

  1. I think this is not a new bug and won't occur very often.
  2. The change is to the core focuser movement function that all focus moves go through so is at high risk of breaking something else (that I can't think of at the moment).

Merge request reports