Skip to content

gphoto: manual focusing is non-linear on Sony cameras #1341

Description

@MmAaXx500

Describe the bug
KStars' autofocusing feature expects that 10 times 10 steps taken in one direction can be undone by taking 100 steps in the opposite direction. This breaks down with Sony as the steps/ticks are mapped in a non-linear way.

MoveRelFocuser decomposes the number of ticks to large, medium, and low steps and uses (-)3, (-)2, (-)1 speeds respectively for the focus movement. This mechanism assumes some kind of relationship between these speed levels that is different on Sony a6400 and causes unpredictable focus movement. If you move 1x100 ticks you end up on a different position when you move 10x10 ticks.

Relevant code for the large/medium/low calculation:

// Ratio from far 3 to far 2
static constexpr double FOCUS_HIGH_MED_RATIO = 7.33;
// Ratio from far 2 to far 1
static constexpr double FOCUS_MED_LOW_RATIO = 6.36;

// Reduce by a factor of 10
double adaptiveTicks = ticks / 10.0;
double largeStep = adaptiveTicks / (FOCUS_HIGH_MED_RATIO * FOCUS_MED_LOW_RATIO);
double medStep = (largeStep - rint(largeStep)) * FOCUS_HIGH_MED_RATIO;
double lowStep = (medStep - rint(medStep)) * FOCUS_MED_LOW_RATIO;
m_TargetLargeStep = rint(fabs(largeStep));
m_TargetMedStep = rint(fabs(medStep));
m_TargetLowStep = rint(fabs(lowStep));

On my Sony a6400, focus speeds can be approximated using this table, with speed 1 as the baseline unit (1 SonyStep). The table shows how many SonySteps are covered by a single use of each speed, for example, 1 use of speed 3 moves the same distance as 8 uses of speed 1.

Speed 1 2 3 4 5 6 7
Steps (SonyStep) 1 2-3 8 20 55 146 ~389*

* speed 7 is approximated, because I'm lazy to count it

Based on the table it can be seen that the speeds are moving exponentially longer than the previous speed by approx a factor of 2.666.

For example if KStars asks for 10 ticks focus movement in one direction 10 times that will move the focus 10 SonySteps in total. If KStars decides to move back to the starting point and asks for -100 ticks of focus movement then that'll result in -9 SonySteps (0 large, -2 medium, -3 low). It can be seen that the focus movement is not equal, so what KStars think where the focuser is will drift from the real focusing position.

At the moment I don't have a perfect solution for this as I expect that the factor between the speeds are changing from manufacturer to manufacturer, possibly even between models, so the universal solution would be to only use speed 1 on all cameras, but it also has its own cons.

Current way of focusing

  • Pro
    • fast
  • Con
    • not universal, maybe only works on a specific camera

Using only speed 1

  • Pro
    • precise
    • universal
  • Con
    • slow on larger movements

To Reproduce

  1. Use a large step size in KStars and use the manual focus in/out buttons
  2. See on camera how much the focus is moved
  3. Switch to a small step size, roughly 1/10th the size, and attempt to undo the movement
  4. See the difference between the original large movement and the many small movements

Expected behavior
Focus movement should be linear 1x1000 should be same distance as 10x100 and 100x10.

Screenshots
N/A

Desktop (please complete the following information):

Log Files
N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions