Auto Focusing Aid

The Auto Focusing Aid is accessible from Tools tab
Related videos:
The automated focusing requires some initial preparation and measurements in order to provide best results. Please read this section before you start using it.
The new Auto Focusing Aid that comes with APT 3.88 and later is combined effort of Stephen King, Benjamin Schulz, Jim Hunt, Ivaylo and Maria Stoynovs. Stephen suggested the method of hyperbola fit for finding the exact focus point by exploring a range of data points and made the "prove of concept" tests. Benjamin wrote a computation library that takes care for the mathematics of the hyperbola fit. The exact algorithms for gathering the data points backlash calculation, filter offsets calculation are made and cleared after great amount of brain-storming, simulations and tests made by this team, but also with many other APT friends. Great thanks to everyone involved for investing so much time and efforts into this project!
The Benjamin's computation library is with open source and is available at https://github.com/bschulz81/hyperbolicfitdll. The sources are also available in the "Sources" subfolder of the folder where APT is installed.
How it works in short - the auto-focsing takes a number of shots, changing the focuser position between them. For each shot is measured the HFD - Half Flux Diameter or FWHM - Full Width Half Maximum or InvPower. Computed is the hyperbola curve that fits best the Position vs HFD / FWHM / InvPower pairs. The minimum of this hyperbola is point with good focus - part of the Critical Focus Zone. This method named U-curve is considered to be more effective than the classical V-curve.
Hardware requirements - Focuser with stepper motor and ASCOM / INDIGO / INDI driver (or enable emulation of position focuser, see Scope & Focuser settings tab)
1. Critical Focus Zone
Everyone of us has seen diagrams of optical systems where the light beams are crossing in the focus point which is critical for good astrophotography or visual observation. However in reality it is not one point, but zone where the light is still focused. This zone is named Critical Focus Zone or CFZ. How big this zone depends on how "fast" the telescope is. Slower scopes (those with bigger F ratio -  the Focal Length divided by Diameter) have bigger CFZ, the faster scopes (these with small F ratio) have smaller CFZ. The scope focuser moves in steps and usually there are several positions where sensor is in the CFZ. This means stars will be equally focused on several positions which makes the focusing much easier task than searching for one exact position.
Here comes a very important thing in the focusing procedure. If we move the focuser by with step much bigger than CFZ we will skip the focus zone and will not be sure where exactly its. In other hand if we move with step much smaller than the CFZ we will get very small changes in the HFD / FWHM / InvPower readings and usually these changes will be affected by the atmosphere turbulence. So it is important to move with a step big enough to give noticeable/measurable difference in the HFD / FWHM / InvPower and in same time not too big so be able to find where HFD / FWHM / InvPower stops to get smaller and starts to get bigger again. Various sources suggest that the optimal step size is 1.5-2 times the CFZ.
APT gives way to calculate the CFZ measured in microns. Just enter your focal length and scope diameter in Tools Tab, click on Recalc button and the Log Panel will see the CFZ size.
This value is in measured in microns, so we have to convert it to focuser steps by determining how many microns the focuser is moved per one step of the motor. If your scope has external focuser you can measure it easily. Here is description how to measure the microns per step. If you have internal focuser like Schmidt-Cassegrain you will have to experiment a bit. According to the empirical data we have collected during the tests we have found the value of 4 microns per step if good value or at least is good starting point. Once we have the "microns per step" we are ready to use the Auto Focus Aid - click on the Auto button in the settings and enter the value when asked. APT will determine the Focuser Move Step that should work fine (see the notes below).
If you want to calculate manually the Focuser Move Step, convert the CFZ from microns to steps by dividing by "microns per step". For the scope used for our example we have 86 microns and 3.1 microns per step, so we have 86 / 3.1 = 27.7 or our CFZ is ~28 focuser steps. The Focuser Move Step which is good to use is 42 to 56.
The "rule of thumb": During the years we have polished a simple empirical way to find a good Focuser Move Step. Start with the default step calculated by Auto button. Run auto focus with good initial focus by visual estimation. If you see jumping dots increase the step. If you see something like W shape lower the step. Repeat the process starting again with good focus till you get good U shape.
2. Backlash
Every mechanical device is not perfect. When you move the focuser in one direction and then get back with same step it will not be in the staring point because there is some play in the parts - this the backlash. You have to make a bit bigger second move in order to compensate the backlash.
There are three approaches to handle the backlash
Here are some ideas how to Measure the Backlash. Once you have the backlash value you can enter in the focuser driver properties or in Scope & Focuser settings tab. To use the overshoot enable the Final Inward Move in Scope & Focuser settings tab. Many are using the combination of backlash and overshoot, however only overshoot can gives good results too.
3. Setup
Use the button Settings to open the dialog box and tune the options related to auto-focusing (see the description below). Usually the only setting that has to be changed is the Focuser Move Step. It is important to set short exposure when InvPower is used!
4. Focus
The Auto Focus Aid needs a source of HFD / FWHM / InvPower values. You can use FocusCraft and Focusing Aid. If you are using Focusing Aid switch to 1:1 Preview mode (double click on the star you want to use). Focus by eye as good as you can or go to know focuser position which is close to the best focus point and click on the button Run.
Auto Focusing Aid

Focusing Method

1. Focusing Method
Defines which metrics to use for Auto-Focusing - HFD (Half Flux Diameter) or FWHM (Full Width Half Maximum) or InvPower (Fourier method). HFD tends to give better results when the stars are detected. When focusing is made via InvPower there is no star detection.
Note: InvPower is sensible to saturated stars in the focusing images. Usually the focusing exposures of 1s or even less give better results than long exposures. If you see small bump in the lowest part of the U curve this means that there are saturated stars.
This setting is also used by the EOS Lens auto-focusing.

Focusing Algorithm

2. Focusing Algorithm
Defines what algorithm to use for automatic focusing:
    - One Pass tries to find the best focus taking defined number of exposures. If there is need it will take additional data points.
    - Flexible (default) is based on One Pass. If additional data points were used Auto-Focus Aid will make second pass starting from the focus point found in the first pass. It can give a bit better result than One Pass, but can take double time.
    - Middle Of Two is based on One Pass. It makes one pass and calculates the focus position. After that makes second pass starting from the focus point found in the first pass. As result will use the focuser position which is the average of the positions found in the two passes.
    - Better Of Two is based on One Pass. It makes one pass and calculates the focus position. After that makes second pass starting from the focus point found in the first pass. The result will be the focuser position which has lower HFD/FWHM.


3. Loop
When enabled the Auto-focusing will make continuing focusing till it is manually stopped. Use this option if you want to collect data and study how the focus changes with the temperature changes.


4. Record
When enabled, will store the results of all successful focusing runs in log file. Later it can be exported via the Analyzer button and to be inspected and analyzed in MS Excel or other application.

Calc Backlash

5. Calc Backlash
When enabled, on Run will try to measure the focuser backlash. Before you start measuring the focuser's backlash make sure that you have disabled all features that can cause unwanted motor movements. Disable the backlash compensation, temperature compensation, final inward move in Scope & Focuser settings tab. Also the backlash compensation in the ASCOM / INDIGO / INDI driver settings.
Make sure that the scope is well tempered. Use night with stable atmosphere and star or area well above the horizon.

Calc Filter Offsets

6. Calc Filter Offsets
When enabled will auto focus with all filters and will calculate focuser position offset per every filter. The offsets can be used to adjust the focuser position on filter change without need to refocus. Before starting move the filter wheel to the filter which you want to use as base. It is better to use Ha, SII or R filter as base. At the end the calculated offset will be reported and you can apply the values in the Filter Wheel settings tab automatically
Calculate the offsets when the system is well cooled, on sky area close to zenith and in a night with stable atmosphere!

Run / Stop

7. Run / Stop
Starts/Stops the auto focusing process.
Shift+Click will make new hyperbola fit calculation using the data from the last pass. It is useful to see the effect changing the Min points for curve fit, Rejection or Tolerance settings without taking new set of images. After the calculation will be given  an option to move to the new focus position and take new confirmation image to see if the HFD / FWHM / InvPower is getting better.


8. Status
Shows the current status of Auto-Focusing Aid.


9. Settings
Opens the settings dialog box.


10. Analyzer
Exports the logged focusing results file that to be opened with MS Excel or similar application.
Shift+Click copies detailed data for last focusing into the clipboard. It can be sent to APT team for inspection.
Ctrl+Click imports from the clipboard focusing data that can be used for calculation of focus point. Useful if you want to try the shared from other users or your old data from the main APT log file (the lines with "AF (FPHF) Positions:" and " AF (FPHF) Values:")

Data Graph

11. Data Graph
Shows the gathered focus points. The horizontal is the focuser position, the vertical is the measured HFD/FWHM. Moving the mouse pointer over the dots you can see the position and the HFD/FWHM values.
Several colors forms are used to display various data:
- dots are used to display the data from the first pass
- small rings used to display data from the second pass
- small squares are used to display data ignored via backlash detection
- purple dots / rings are the data used for hyperbola fit
- red dots / rings are the ignored post ions not for hyperbola fit
- green line is the position of the hyperbola minimum
- green dot is the HFD / FWHM / InvPower value measured in the hyperbola minimum.
- blue curve is the hyperbola from the first pass
- yellow curve is the hyperbola from the first pass
Note: If you see dots jumping almost randomly this could mean that the Focuser Move Step is too small. If you see flat bottom in several points it could mean that the Focuser Move Step is too big.

Ringy Thingy

12. Ringy Thingy
Ringy Thingy is an innovative way to edit numeric values using only mouse or touch pad. See details and animation how to use it in the Application Interface notes.

Number of test points

13. Number of test points
Defines the number of the positions where to measure the HFD/FWHM. Before each measurement the position is changed with number of steps defined by Focuser Move Step. If you change this paramter, make sure to click on "Auto" button to re-calculate the Focuser Move Step.
Default value: 12, min: 7.

Min Points for curve fit

14. Min Points for curve fit
The focusing algorithm could reject some points which differ from nearby points and from the expectations in order get better result. If Min points for curve fit is equal to Number of test points the rejection is disabled and all points will be used, no matter what. Usually Min points for curve fit is Number of test points minus 2 to 4.
If there are rejected points they will be marked with red in the graph.
Default value: 8, min: 6.

Focuser Move Step

15. Focuser Move Step
Defines how many focuser steps to make between the HFD / FWHM / InvPower measurements. This is very important value and depends on the Number of test points and on CFZ - Critical Focus Zone. Use the button Auto to get suggestion for the step size.
Default value: 35. It should work for well with 12  Number of test points for most f/5.5 scopes.
The button Auto calculates the Focuser Move Step based on Number of test points, the CFZ - Critical Focus Zone of the telescope and the microns moved by one step of the focuser motor.
Note: If you see dots jumping almost randomly this could mean that the Focuser Move Step is too small. If you see flat bottom in several points it could mean that the Focuser Move Step is too big.

Max moves

16. Max moves
Defines the upper limit of the focuser moves that to make in trying to find the focus. When reached the aid will report and error and stop.

Pause after move

17. Pause after move
Defines how many second to wait after focuser move is finished before taking another image. The default value is 1.

Default Exposure

18. Default Exposure
Defines the default exposure for auto-focusing. When set to 0s or empty will use the exposure set in the Camera tab. Also is possible to define exposure per filer in Filter Wheel tab of Settings. The priority from top to lower is:

Default ISO

19. Default ISO
 Defines the default ISO for auto-focusing. When is empty will use the value set in the Camera tab.

Default Bin

20. Default Bin
 Defines the default Bin for auto-focusing. When is empty will use the value set in the Camera tab.

Default Gain

21. Default Gain
Defines the default Gain for auto-focusing. When is empty will use the gain set per filter or the value set in the Camera tab.

Region of Interest

22. Region of Interest
 Allows speeding-up the image download by reading part of the sensor pixels. For example selecting 1/4 will read one quarter of the sensor around its center.


23. Rejection
Defines what rejection method to use if Min points for curve fit is smaller then Number of test points and allows points rejection. The empirical tests shows that S Estimation gives best results.


24. Tolerance
The Rejection methods could be configured how tolerant to be to the data points when are tested if they belong to the hyperbola curve or not. The different rejection methods has different default values which will be set on method selection.
Default tolerance for S Estimation is 3.0

Search Method

25. Search Method
Defines how to search the hyperbola fit by Linear or Median regression. The empirical tests shows that Linear is faster and is giving almost identical results as Median.

Limit FocusCraft

26. Limit FocusCraft
If you see that test points jump too much in the graph you can try to limit FocusCraft to work only with the brightest star.

Pause Guiding

27. Pause Guiding
When enabled, the guiding will be stopped on focusing start and will be resumed after that. This is useful option when Off-Axis Guider is used.

Keep focusing images

28. Keep focusing images
When enabled APT will keep the focusing images from the last re-focusing in the TemporaryStorage sub-folder located in the Images Path.