×

INDI Library v2.0.6 is Released (02 Feb 2024)

Bi-monthly release with minor bug fixes and improvements

Autofocus 'single pass' linear algorithm

  • Posts: 37
  • Thank you received: 4
For me, the linear algorithm for autofocusing was a great addition in Ekos (thanks for that!), making it way more reliable with the focuser I have. In my case, the main problem with polynomial (or iterative) is that it tends to take few samples, so the computed solution can be quite biased. Also, though my focuser implements backlash compensation, the back and forth movements won't help either. The linear algorithm does a more comprehensive sampling (almost without going back and forth) so its computed solution after the first pass is quite spot on. 

The current implementation added a more persistant behaviour that in my case means that the complete routine takes a lot more (full field work best for me to better estimate the HFR in my noisy CCD, but downloads are slow, even with bin2x2). 

Would you (@ Hy Murveit) consider to add a "single pass" option to the linear algorithm? -- meaning "jump to the computed solution after first pass" (with compensation) if curve fitting is good enough. 

Another question, regarding the initial movement (outward+inward): it seems to implement a backlash compensation of 5*initial_step_size, is that so? Could this also be configurable?

Thanks in advance, 
Sergio
2 years 1 month ago #80448

Please Log in or Create an account to join the conversation.

  • Posts: 1208
  • Thank you received: 559
Sergio,

Re your 2nd question:

I think the awkwardly named "out step multiple" in the Mechanics subtab is what you're asking for.
Please feel free to suggest a better name.

 

Re your first request:

- Are you saying that you have no issues with backlash (backlash is the reason for the 2nd pass), but still prefer Linear over Polynomial? Please explain.

- When you say:  "jump to the computed solution after first pass" (with compensation) if curve fitting is good enough. 
I don't really understand:  "if curve fitting is good enough" and "with compensation".

BTW, how long do your focus sessions take? In my experience (ASI1600 on RPi4) I was usually completing the autofocus in under 2 minutes. It's true that that's time one could be capturing, but the flip side is if you rush things, then you might wind up with an hour of wasted images.  In any case, I'm open to suggestions/discussion. 

Thanks,
Hy
The following user(s) said Thank You: Sergio
2 years 1 month ago #80454
Attachments:

Please Log in or Create an account to join the conversation.

  • Posts: 37
  • Thank you received: 4
> Re your 2nd question:
> I think the awkwardly named "out step multiple" in the Mechanics subtab is what you're asking for.
> Please feel free to suggest a better name.

I observed (not sure if I got it right) that the first outward movement seems to be equal to (out_step_multiple+5)*initial_step_size steps, then followed by a inward movement of 5*initial_step_size steps, so the complete outward+inward movement has a net outward shift of out_step_multiple*initial_step_size steps.

So I understand that this initial outward "overshoot" of 5*initial_step_size is a backlash compensation, is that so? In that case, the '5' value is configurable anywhere?

> Re your first request:

> - Are you saying that you have no issues with backlash (backlash is the reason for the 2nd pass),
> but still prefer Linear over Polynomial? Please explain.

Backlash is an issue but somewhat alleviated by my focuser internal backlash compensation. So if I do many changes in direction, the position error due to backlash may increase; but if there is no much back and forth, positioning seems to be quite acceptable. In my case the polynomial algorithm takes a few samples and then quickly finds a solution, but it's not very reliable, in part for the back and forth movements, but I think that mostly for the lack of proper sampling.

Linear does a very good sampling even in the first pass (also I can control the sampling with initial_step_size).

> When you say:  "jump to the computed solution after first pass" (with compensation) if curve fitting is good enough. 
> I don't really understand:  "if curve fitting is good enough" and "with compensation".

Sorry for not being specific. By "compensation" I meant "backlash compensation" (like the first movement of the linear algorithm). So this final "jump" would be in the outward direction past the computed solution, then inward, to fall exactly on the computed solution.

"If curve fitting is good enough": I was guessing that the computed solution is derived from a quadratic regression over the samples. If that is the case, a goodness-of-fit metric, such as R-squared, may indicate our degree of confidence on the computed solution after the first pass. To be fair this involves an arbitrary threshold to specify what is "good enough" (R-squared should be greater than some arbitrary value). If the metric doesn't reach the threshold, maybe just flag the autofocus as failed (for the user to tune parameters in "interactive" sessions / rely on the scheduler error handling in automated sessions).

> BTW, how long do your focus sessions take? In my experience (ASI1600 on RPi4) I was usually completing
> the autofocus in under 2 minutes. It's true that that's time one could be capturing, but the flip side is if you rush
> things, then you might wind up with an hour of wasted images. 

In my case, focusing is about 4 minutes in average. I image from an urban location with narroband filters and a USB2.0 CCD. Each focus exposure has to be somewhat long, at least 3-4 seconds to get enough signal to work with, and download time (bin2x2) is around 8 seconds. Currently (v3.5.6 and 3.5.7), the linear algorithm takes about 20 iterations in average.

> In any case, I'm open to suggestions/discussion. 

And many thanks for that!
Sergio
Last edit: 2 years 1 month ago by Sergio. Reason: Quoted text didn't show up
2 years 1 month ago #80505

Please Log in or Create an account to join the conversation.

  • Posts: 593
  • Thank you received: 274
I too have been doing some experiments with the 3 focus algorithms to try to optimise things for my setup. Like @Sergio for my setup (ASI EAF) I find that the extra datapoints that the Linear algorithm takes produces the most accurate curve. The other algorithms seem to produce a far less accurate curve. I'm not really sure why this is and probably need to test more. My guess would be its a combination of less points and with all the switching of direction I probably need a longer settle time vs linear which just drives in 1 direction.

I have adjusted the backlash in my EAF a few times and get different results. I also suspect that my backlash compensation will be temperature dependent across a session. So whilst I believe I have most of the backlash compensated for I suspect it will never be very accurate.

So for my setup, I think Linear has the highest chance of being most accurate. My observation is that on pass 1, it reliably plots the curve and pinpoints the minimum very well. What then happens on pass 2 is that it steps back along the curve with decreasing HFR, and goes to the point just past the minimum, where HFR has started to increase and then takes the 1/4 stepsize step and stops there. For me this usually gives an HFR that is 10-15% above the HFR minimum.

What would work better for my setup would be... do pass 1 and calculate the curve and minimum. Then take a big step out and then, rather than stepping back in pass 2, go straight to the minimum so approach the minimum from an inwards direction so any uncompensated backlash is neutralised by the step out and step in. I can do this manually but obviously not when the setup is running unattended.

I understand from @Hy's comments on other threads that the idea of Linear is for use where moving from pass 1 to pass 2 cannot rely on the equipment going to the same position - hence the necessity to step back in on pass 2. However, the alternative of using Polynomial or Iterative just don't work as well on my setup.

Maybe there is a need for 2 Linear algos: 1 as is now for less reliable equipment and a new one for equipment that is a bit more reliable but with some uncompensated backlash where Polynomial and Iterative aren't so effective. Folks with high end equipment can continue with Polynomial and Iterative which I'm sure works great for them.

Its tricky for me to comment on whether the changes to use the same stars are making an improvement. Logically, of course, this should but I think it gets offset by an ever dwindling set of stars to compare. I sometimes go from around 100 stars down to <5 so I suspect the benefit of using the same stars to compare is getting offset by averaging over a small number of stars. I think I need to experiment a bit more to see if I can get a better set of stars.

I'm going to continue to play around with the algos to see if I can improve my setup.
2 years 1 month ago #80525

Please Log in or Create an account to join the conversation.

  • Posts: 225
  • Thank you received: 16
I agree John. I rarely get a better result on pass 2. I really like linear, but hate having to wait for a second pass... particularly when it usually stops on a less optimal setting.

Ron
2 years 1 month ago #80550

Please Log in or Create an account to join the conversation.

  • Posts: 219
  • Thank you received: 41
I've also observed that on 2nd pass the solution found it's usually worst that the minimum found on 1st pass. I'm also using a ZWO EAF, but without backlash compensation.
2 years 1 month ago #80653

Please Log in or Create an account to join the conversation.

  • Posts: 25
  • Thank you received: 1
Same for me. Admittedly, I have a DIY solution for motor focus, so backlash is an issue. Therefore, linear is the way to go for me.
The first pass usually yields a great curve with a clear minimum, but the second pass quite often either stops to early or misses the minimum because of momentarily bad or changed seeing. Sometimes, there is also an unreasonably good focus point during the first pass, that does not really affect the polynomial, but makes it impossible for the second pass to reach the % Limit.
So - in short, a single pass with a jump to the calclated solution (moving in from the same direction as the first pass was moving) would be my preferred choice as well. I do this quite often manually by aborting the autofocus after pass one, but of course this is not the desired solution.
 
Last edit: 2 years 3 weeks ago by Stephan.
2 years 3 weeks ago #81053

Please Log in or Create an account to join the conversation.

  • Posts: 219
  • Thank you received: 41
I've been thinking a lot about this problem, because with an f4 focus precision is critical. The problem with "go straight to the 1st pass minimum" is that it will only works if you don't have backlash. With backlash you will be unable to reverse direction and the go to the first place... you don't have an absolute position to help you in this last "jump"
2 years 3 weeks ago #81054

Please Log in or Create an account to join the conversation.

  • Posts: 219
  • Thank you received: 41
What about the following proposal:

* We start with a linear pass as we do currently. But instead of interpolate a parabola and use it to find the minimum we use the classic "V" curve and we use the intersection of the two lines to estimate the best focus position
* We go back to the starting point and a little more and start again to get datapoints. As soon as we have a good line interpolated from this points, we can compute the distance (the backlash) between the current descending slope and the one on the 1st pass.
* As we know the final destination and we have absorbed the backlash we can jump straight to the desired position.

The use of straight lines (the "V" curve approximation) will help on step 2, identifying how far the second run si from the firs one (it's a backslash measurement)

What do you think? Will this be an improvement over the current algorithm?
The following user(s) said Thank You: Stephan, Francisco Bitto
2 years 3 weeks ago #81055

Please Log in or Create an account to join the conversation.

  • Posts: 25
  • Thank you received: 1
I guess it is the question if backlash is symmetrical. Assuming it is, once you complete your first pass, if you move back to your starting point by overshooting it significantly, and then driving back to the starting point, you eliminate backlash already.
Therefore, I think that after the first pass, you can drive back beyond the starting point (more than there is backlash in the system) and then go forward directly to the target (e.g. minimum of parabola or line crossing like you suggested) . This should work as long as backlash is symmetrical for in- and outward movement.
2 years 3 weeks ago #81085

Please Log in or Create an account to join the conversation.

  • Posts: 207
  • Thank you received: 14
I found the linear method worked fine but slow on my 150PDS - Crayford focuser. This uses DIY myfocuserpro2 with modified 28BYJ-48 (converted to bipolar) with belt pulley.
My 80 f5 sw refractor has rp focuser so use geared nemo stepper with belt pulley. This does not work at all well. 1st pass locates minimum most of the time, but sometimes
carries on into outer space and have to stop and go manual. 2nd pass doesn't do great job. More powerful motor . I think the ASI system adopt polynomial 1st pass then linear
2nd pass. I guess problem is DIY systems too variable. Is there hope for improvements in future I wonder ? 
 
2 years 3 weeks ago #81121

Please Log in or Create an account to join the conversation.

Time to create page: 0.891 seconds