indigo-astronomy / indigo

INDIGO is a system of standards and frameworks for multiplatform and distributed astronomy software development designed to scale with your needs.
http://www.indigo-astronomy.org
Other
139 stars 64 forks source link

ccd_ptp: Implement focusing for Sony cameras via NearFar #484

Closed jimtjames closed 11 months ago

jimtjames commented 12 months ago

This pull request aims to implement a focuser for Sony cameras, similar to the existing one for Canon. This is done through the use of the property NearFar, which is also added to the property list.

The focusing routine is modified from the Canon one. I have done some simple testing with a Sony A7R III and Sony 200-600 lens in AIN by sending relative focus commands, and can confirm via the images and the back screen of the camera that it does shift focus. That said, I have not tested this with the full focusing routine as I don't have the ability to try this under the stars yet.

polakovic commented 11 months ago

I made couple of changes (cceb107732700cc157cf63b037ebed7a258c3f1a):

1) on Sony manual focus doesn't need active LiveView so I removed superfluous code,

2) it looks that 0xD2D2 is not supported on other cameras than A7III so I removed the code which depends on it. Instead you have to set DSLR_FOCUS_MODE to MF, what is probably true for astrophoto anyway. With this change it works with A7RIV.

Pls. can you check it with your camera if it works as well?

Some more related info is here: https://github.com/gphoto/libgphoto2/issues/434

jimtjames commented 11 months ago

First off, thanks for merging this PR and further cleaning up the code. I think this will go a long way in making INDIGO the preferred platform for Sony users; in my experience the PTP driver is more stable than the INDI driver, and focusing support seems to be exclusive to here.

With respect to your comments:

1) Understood, thank you! I didn't know whether liveview was needed or not, but I just put it in there since it was included in the Canon driver.

2) That's my understanding as well (I got it from that same gphoto issue). It doesn't seem to do anything on my A7R III, but I don't have an A7 III to test with so I left it in there. I bet that setting the focus mode to MF or DMF is sufficient.

I have tested my A7R III with the updated driver and it appears to shift focus, so seems to work okay!

One thing I will note though is that making the steps adjust NearFar by 7 each iteration is likely too large for achieving sharp focus. I don't yet have access to my setup to test the updated driver under the stars, but previously I've found that modifying NearFar by 3 or fewer was necessary to land within the critical focus zone, which is why I originally set it to 2. I know that the code switches to smaller steps when the number of steps is less than 7, but I also noticed that the NearFar settings are seemingly nonlinear - seven 1 steps won't move the same amount as one 7 step. Thus for focusing algorithms to work correctly, I think all NearFar updates need to be the same size. Alternatively, we could determine the relationship between NearFar values and relative focus shift compared to a setting of 1 (though I don't know that this would be consistent between different cameras).

polakovic commented 11 months ago

One thing I will note though is that making the steps adjust NearFar by 7 each iteration is likely too large for achieving sharp focus. I don't yet have access to my setup to test the updated driver under the stars, but previously I've found that modifying NearFar by 3 or fewer was necessary to land within the critical focus zone, which is why I originally set it to 2. I know that the code switches to smaller steps when the number of steps is less than 7, but I also noticed that the NearFar settings are seemingly nonlinear - seven 1 steps won't move the same amount as one 7 step. Thus for focusing algorithms to work correctly, I think all NearFar updates need to be the same size. Alternatively, we could determine the relationship between NearFar values and relative focus shift compared to a setting of 1 (though I don't know that this would be consistent between different cameras).

Oh thank you! Good to know, I'll try to make some test next weekend to make sure the position is reproducible with different step sizes.

jimtjames commented 11 months ago

I ran some tests by sending the relevant PTP command and observing the final position from the rear screen after NearFar updates when starting with my lens focused at infinity. To reach a distance of 30m from infinity, we need either:

These numbers aren't exact, but I think this indicates that focus position likely won't be exactly reproducible with the current update size strategy. The ratios are weird enough that I think it'd be hard to implement accurate focusing by trying to compensate for multiple sized updates. I think the best thing to do right now would be to only use a single update size (i.e. 2), which will likely work fine if a user is already close to focus.

Alternatively, I'm curious if we can readout the focus distance via PTP. According to the PTP document on page 109/97, there's a property called FocusDistance with code 0x5009 that's supposed to be the focus distance in millimeters (though the maximum makes it sound more like centimeters). Perhaps if we can read it out, then we can implement an absolute focuser with some additional logic?

polakovic commented 11 months ago

Thank you for sharing your observations! I'll change the code to use 1 step increments only, it will be safer.

I doubt FocusDistance property is used by any real PTP implementation and specifically Sony is really far from the standard :(

polakovic commented 11 months ago

Is this OK? 08c16f7447901605a64733944d18f18a1512f95c

jimtjames commented 10 months ago

Sorry for the delay! That looks good and seems to work on my camera. I'll try testing it under the stars and update accordingly if I find any issues.

polakovic commented 10 months ago

Great! Thank you for your help!