Skip to content

Add relative HFR calculation to Linear focus algorithm. Improve plotting. Tweak algorithm.

Hy Murveit requested to merge murveit/kstars:focusstars into master

This MR contains a number of changes to the Linear focus algorithm.

RelativeHFR The main algorithmic change is the introduction of a relative HFR. This applies to Linear when used with full-field HFRs (and only one image capture per position). Previously full-field computed its HFR based on all the stars in the image, for each position. The issue with that is that different position may (do) have different sets of stars detected. Thus a position that happens to include a brighter/larger star that a different position doesn't will be at a disadvantage when computing the HFR. RelativeHFR uses common sets of stars when comparing HFRs for different focus positions. This image shows an improvement: https://photos.app.goo.gl/hn7qimgb9Dzt5Bq76 Samples 1-8 are the 1st pass in the Linear focus algorithm, it goes back to the 2nd pass in sample 9-16. Note that samples 11 & 12 are much worse in the original HFR calculation, as compared to the 1st pass' best sample #5 (closed), than with the relative algorithm.

Improved Linear focus graphics The focus plot is improved with linear. Is shows what it's doing (pass1, pass2, solution pending, solved) as a title on the focus plot. Also several things are cleaned up on the plot (easier to read the best hfr values, polynomial only reflects the first pass).

Improved constants There were a few constants in the algorithm that could have used better default values, e.g. would have been ill advised for focusers whose position values can get > 100000. This has been fixed.

More persistant In the 2nd pass, the Linear algorithm scans, moving the focuser "in" looking for a position whose measured HFR is within a tolerance of the best 1st pass HFR. Once it finds such a good position, it might stop, but instead it continues to search as long as the HFR continues to decrease. Currently once the HFR stops decreasing, it finishes. This can be sensitive to noisy HFR values. Instead, now, when it notices the HFR getting worse, it retries a few times to make sure the HFR has stopped improving. This can be seen in the same plot linked above: https://photos.app.goo.gl/hn7qimgb9Dzt5Bq76 Sample 11 was within tolerance of best 1st pass sample 5. It could have stopped there, but continued with sample 12, which improved. Sample 13, though, was worse. Instead of stopping there, it retried the position of sample 13 three times for samples 14-16 (not sure whether that number 3 should be reduced). Since none were better than Sample 12, it finally stopped.

Further, previously this optimization was previously not allowed to cross the position where the HFR was minimized in the first pass. It now can cross that value, though the step size reduces when it does.

Note that the above search logic is due to the fact that the algorithm assumes the reported position is not necessarily accurate (e.g. that there is backlash in the focuser positioning). If the position were perfectly known and the focuser was able to move there without error, then the Linear algorithm would be unnecessary and the Polynomial algorithm would be the way to go. For example, when I said above that it "crosses the first pass' minimum", keep in mind that it really doesn't know the location of the 1st pass' minimum in the second pass, as the movement, along with its associate backlash has obfuscated that position.

This MR has been tested for a week on both a 560mm FL refractor with a moonlight focuser, and a 2000mm FL RC reflector with a secondary mirror focuser, as well as simulator testing, and seems to perform well.

Unit tests have been introduced for the relative HFR (testfocusstars.cpp) and the changes to the Linear focuser (testfocus.cpp).

Edited by Hy Murveit

Merge request reports