focus distance (was Re: fixedint.lua: Astrophotography oriented script for long exposure + timelapse - General Discussion and Assistance - CHDK Forum  

focus distance (was Re: fixedint.lua: Astrophotography oriented script for long exposure + timelapse

  • 3 Replies
  • 1648 Views
*

Offline reyalp

  • ******
  • 14080
Advertisements
Thanks Reyalp,
  I will try the glue script as you suggest.  This seems like a neat way to do it.  I like the options in your script.
If I had a camera outside connected to USB, I think I'd be tempted to use the rs/shoot commands, but you should use whatever you're most comfortable with :)
Quote
  This is diverging off-topic, but one of the reasons I want to use the CHDKptp is so that I can set the focus, take a picture, then set the focus at a slightly different point, and take another picture... and see where the focus is sharpest.   But I am getting confused by all the different units. 

   Is there a way to interrogate the camera to determine what the focus point is set to?  Then I can focus at infinity or set it to scene mode, and see what value it reports.  I'd use that as a starting value and bracket around it.
Yes, you can use
Code: [Select]
=return get_focus()
to get the current focus distance in millimeters. You'll probably want the camera in manual focus or AF lock mode first. You can set the camera to manual focus with
Code: [Select]
=set_mf(1)
You can then change the focus with
Code: [Select]
=set_focus(number)
Where number is the distance in mm. In MF or AF lock, you should see the focus update immediately in the live view, and the value will persist until you change it. Note support for focus overrides in CHDK varies, but G16 should work in MF.

(edit: I should note that while get_focus/set_focus use millimeters, the chdkptp rs and shoot commands default to meters)
Quote
   I've found that 'luar set_focus(-1)' does not result in consistently focused images.  But I am not sure how the camera knows to translate '-1' to "infinity".   It seems to me to be more robust to set_focus(xxxx), but first I need to determine what value of xxxx corresponds to true focus at infinity. 
Yes, on some cameras, -1 is close enough but on others it's definitely not.
Quote
(I'm also making another assumption here, that the lens is generally capable of going beyond infinity.  It must be able to for optical focus of a distant subject to be able to work.   So I am not sure what "set the focus to infinity" means, unless the camera is somehow taught at what point the lens should be set.)
Yep. There's some additional complication. set_focus is nominally in millimeters, but it is mapped to physical positions of optics in some way that is neither very precise nor repeatable. For example, setting 170000 on my g7x sometimes results in values of 130310, 162798 or 195245. The actual focus also varies.

Also, the focus distances available to the camera cover a broader range than accessible through set_focus and get_focus. On my G7X, if I adjust focus in the MF UI, get_focus starts returning -1 about when bar is full, but there many additional steps of focus beyond that point. get_focus continues returning -1, but the focus goes progressively further past infinity.

« Last Edit: 19 / November / 2019, 22:32:10 by reyalp »
Don't forget what the H stands for.

Yes yes yes!  That business with the camera reporting erratic values was exactly what I was seeing.  That is why I asked about interrogating the camera.  I had tried set_focus() followed by get_focus() and the numbers were so erratic, that I thought I was doing something wrong, or that wasn't the right command.   

But upon some more thought overnight, it makes sense.  The lens equation is 1/i + 1/o = 1/f where i, o and f are the image distance, object distance and focal length respectively.   If you write it as o = 1/(1/f - 1/i) you can take the derivative do/dx to see how the "object position" (i.e. the value returned by get_focus()) varies with change in image position (i.e. the actual position of the lens above the sensor), and it blows up when i=f.   So that makes sense.  When you are focusing the lens at "infinity",  any very small change in the lens position results in a huge change in calculated "object" position.   So I am not sure there is anything useful to be learned from the returned object position.  It would be better to extract the lens position (i) in mm.

The last time I took one of these cameras apart, there was a small DC motor moving the lens in and out.  That means there must be an optical interrupter sensor of some sort, or another form of feedback measuring the *actual* lens position, i.  So a focus command moves the motor some amount and the camera firmware reads back the position the mechanism arrived at.  That will likely vary by position, vibration, temperature, and I am thinking the motion is hysteretic.  The object distance if calculated from the measured image distance, and that is why the values are so erratic. 

  To solve the hysteresis,  I'm hoping it might be possible to command the lens to (object) position 1mm, then out to 100 mm to rack up all the lens gearing one way, then finally out to 10,000 mm for an effective "infinity" position.  But the catch it then we can only go in one direction.  We can't go past infinity and bring the focus in.

  Is there a way to set the lens in a more raw fashion - i.e. native camera "clicks" or whatever it is?  Then we could possibly command the lens to go out *past* infinity focus and come *in* to the desired point.  Not sure that would work any better, but it would be nice to be able to try it.

  I guess it's possible having pinpoint stars is pushing the limits of these cameras beyond what they were intended to do.  I'm also curious how much of a lens position error (in micro meters) corresponds to a blur of one pixel at the image plane, but I am not sure how to think about that yet.  But my one photo is encouraging, so I am going to keep plugging at it till I need a new camera.

  Thanks,
  Dan

P.s. and yes, also same thing on the G16.   The Manual Focus bar goes to full at infinity focus, but there is a little arrow at the top of it.  I can click the focus position 11 times more and then the arrow goes away.   But is the focus really "beyond infinity" when clicking beyond the full bar?  I need to try that.

We really need a set_lens_position() command rather than a set_focus() command.

  Dan

*

Offline reyalp

  • ******
  • 14080

But upon some more thought overnight, it makes sense.  The lens equation is 1/i + 1/o = 1/f where i, o and f are the image distance, object distance and focal length respectively.   If you write it as o = 1/(1/f - 1/i) you can take the derivative do/dx to see how the "object position" (i.e. the value returned by get_focus()) varies with change in image position (i.e. the actual position of the lens above the sensor), and it blows up when i=f.   So that makes sense.  When you are focusing the lens at "infinity",  any very small change in the lens position results in a huge change in calculated "object" position.   So I am not sure there is anything useful to be learned from the returned object position.
It tells you *something* about the position, I would expect different reported "subject distance" reflect different lens positions. E.g. on my g7x, ~130000 is different from 195000. So you could step set_focus values from say, 100k to 200k, note when the get_focus() changes, and check each distinct get_focus() step (including where it goes to -1) for focus quality.  However, if best focus isn't at one of the points set_focus lands on, you're SOL.

I've actually been meaning to add something like this to fixedint, since trying to focus using the LCD screen is one of the major pain points. My idea is to evaluate contrast on the raw image using rawop, perhaps restricted to point sources. This would be similar to camera AF, except done on full resolution raw data and restricted to limited range.

Quote
  Is there a way to set the lens in a more raw fashion - i.e. native camera "clicks" or whatever it is?  Then we could possibly command the lens to go out *past* infinity focus and come *in* to the desired point.  Not sure that would work any better, but it would be nice to be able to try it.
There has been some experimentation:
https://chdk.setepontos.com/index.php?topic=11078.msg130083#msg130083

Also some related work on EOS M cameras https://chdk.setepontos.com/index.php?topic=12542.msg140739#msg140739 (not directly relevant to P&S, they use different functions)

P.s. and yes, also same thing on the G16.   The Manual Focus bar goes to full at infinity focus, but there is a little arrow at the top of it.  I can click the focus position 11 times more and then the arrow goes away.   But is the focus really "beyond infinity" when clicking beyond the full bar?  I need to try that.
On my G7 X, it definitely is, focus gets progressively worse at steps beyond infinity. There are actually a few steps beyond where the arrow disappears.

Quote
We really need a set_lens_position() command rather than a set_focus() command.
That would certainly be desirable, but it needs some R&D to figure how to support it across > 100 models. Focus override has already been a problem area.

The set functions are like MoveFocusLensToPosition*, MoveFocusLensWithPosition* and MoveFocusPosition. Usage, limits, safety need to be determined by reverse engineering and experiment. There is also MoveFocusActuator

Other possibly interesting functions
GetFocusLensPositionRatio
ChangeFocusDistanceToPosition
GetFocusLensMoveMaxPosition /  GetFocusLensMoveMinPosition
Don't forget what the H stands for.