I finally got this sorted and have reasonable focus results. There may still be a bit of seeing issues, but, in general, the v-curve looks better than before backlash compensation.
I forked TallFurryMan's firmware and removed the dustcap control as well as implementing backlash compensation. The firmware can be found at github.com/beckrd/Moonlite_Focuser
.
This graph is a cool source of information! Assuming the order in which you focused with filters is L, R, G then B, it seems the position reported to Ekos is wrong as moves become smaller. The problem seems located for moves lesser than 10. I know that my original attempt at managing backlash is wrong when the movement request is smaller than the backlash amount, and I measured a backlash of ~10 ticks on the 28BYJ-48. It might be a similar problem?
I'm still biased that the backlash isn't fully compensated. My goal of having enough engagement for the focuser to not slip outwards seems to have been met. I ran the R, G & B frames through PixInsight's SubframeSelector script and had the most consistent results I've had since the focuser was installed.
For the next night out, I think I'll change the backlash to 100 to improve the meshing of the gears both directions. If the issue on HFR vs focus position the other night is because backlash is non-symmetric, I can't think of how to correct it.
This is a good idea, now that you actually removed the backlash value from your equation. As you say, that will work only if the backlash is identical if both directions, but there's no physical reason it should be different.
I think the auto-focus procedure goes far for the L filter because it is the first filter, and only refines with smaller values for other filters, expecting the focus point to be close. It might be a problem, it seems you have a very low number of iterations when focusing subsequent filters. To me the number of samples that we see on the curve for G and B can't be used effectively to provide a minimum, and is certainly used jointly with the previous results. That is probably not what you want.
Perhaps you could use the filter offset panel to force a large outward offset before starting the procedure and see how it behaves? One thing you could try is change the order of filters to check if the weird curve slopes follow the filter type or the filter order.
In all cases it's good that you could achieve your primary objective indeed, congratulations
Beginning of this week, I implemented your solution in my own firmware (I pushed the change to github if you are interested).
I tested it yesterday night, and it works pretty well, certainly better than the method I was using before with a backlash in two directions.
Unfortunately, I still suffer from relatively bad seeing in my backyard, causing HFR calculations to vary widely so it's difficult to conclude.
While testing, I got more consistent results by switching the star detection method from "SEP" to "Centroid".
It may be less precise, but HFR values suffer less variation from seeing, and this accelerates the focus procedure with no apparent loss of focus quality.
Before that, I was using full-field HFR calculation to prevent the algorithm from selecting a hot pixel, a stellar core or even a double star (aargh!) while I'm sleeping. But full-field HFR calculation is deadly slow on my system. I'll check how this behaves.
First off, thanks for sharing the code and leading me to understanding state machines through our direct messages. This exercise has been valuable to me for more than just the focus controller.
To ensure I eliminated backlash, I increased the backlash value to 96(!). However, I still saw similar results which may be seeing related, although I use 5 second exposures to minimize seeing effects.
I have been using full-field HFR and it works at a reasonable speed on the laptop I have been using. I suppose I may need modify that if I start using a Raspberry Pi at the scope.