Skip to content

DRAFT Fixed focus restart bug

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

There is a bug in the focus module whereby if a session clouds over focus keeps retrying and failing (which is fine) but wanders away from the last good focus position. The problem with this is that focus goes so far away that it will never recover if the clouds disappear.

The bug has been around for a while (at least several Kstars releases) and happens with Linear as well as the new Linear1Pass and I suspect the other focus mechanisms.

The reason it happens is:

  1. If focus fails, it resets the focuser back to the starting position (or last successful focus point) before retrying.
  2. Within the focus module it tries 3 times then stops if AutoFocus was run from the GUI or sends a signal to the Scheduler if it was run from there.
  3. In the focus module when it retries, it waits for the async event from the focuser saying its finished moving (back to the starting position) before triggering the start of the next run. This works fine.
  4. When a run starts, it queries the focuser to get the current position which it then saves as the starting position.
  5. For a Scheduler controlled autofocus run, when control goes back to the scheduler (after 3 internal focus fails), the scheduler just restarts focus (upto 5 times). This is where the problem is... during the start it queries the focuser, gets an "in flight" position and uses that as the start position.

So the fix is to not signal the Scheduler that focus has failed from the failure event, but use the failure event to start the focuser move back to its start position and only signal the scheduler when the focuser has finished moving.

I would like this to be code reviewed, as although conceptually the fix is quite straightforward the code to be changed is quite complex and the impact of the change is across all focus runs, all focus algorithms, all focusers, etc.

I briefly discussed this with Hy and he has kindly agreed to review it.

Edited by John Evans

Merge request reports