Lens movement/focus control - page 3 - General Help and Assistance on using CHDK stable releases - CHDK Forum supplierdeeply

Lens movement/focus control

  • 34 Replies
  • 3676 Views
*

Offline reyalp

  • ******
  • 14086
Re: Lens movement/focus control
« Reply #20 on: 25 / January / 2023, 14:53:08 »
Advertisements
What is strange, after reading your post, is when I use pos=call_event_proc('GetFocusLensMoveMinPosition') or pos=call_event_proc('GetFocusLensMoveMaxPosition'), I get -3200 or 3200 returned and the lens doesn't move. I'm in MF mode.

I was expecting to see the lens move.
I would not expect those functions to move the lens, and in my testing they did not. In general, functions in the firmware that start with "Get" return something rather than doing something (though of course side effects are possible), and from my testing they return fixed (i.e. unchanging for a given camera) (edit: incorrect see next post) values for the minimum and maximum "move position".

MoveFocusLensWithPosition is the one that moves lens, and again, in general, Canon functions that do something generally start with a verb like Move or Set.

@reyalp

Thanks to your help I've made progress and believe I'm ready to code up a new script for focus and exposure bracketing.
First, I'd like to make sure you are clear that in my judgement there is a significant chance that using MoveFocusLensWithPosition will result in lens error that is unrecoverable without disassembly of the lens mechanism. If you are comfortable bricking a $500+ camera, that's you're choice, and any knowledge gained in the process will be appreciated, but I don't want to hear any crying about it.

Again, this isn't just general paranoia, this because I encountered a lens error playing with this exact function. Just because my camera was eventually recovered by multiple reboots and gently whacking the lens doesn't mean yours will be!

Quote
Strangely in this demo script I can't seem to get the get_dofinfo giving me the focus position. It always seems to return 0.
That is odd. It may be a bug in the port. What do get_focus() and get_prop(require'propcase'.SUBJECT_DIST1) return?

Which camera are you testing this on, and what Canon firmware version is it?


From lines like
Code: [Select]
   test = call_event_proc('GetFocusLensCurrentPosition')
   qq=call_event_proc('MoveFocusLensWithPosition',100,0,0)
It seems you expect MoveFocusLensWithPosition to do a relative move, i.e. + or - form the current position. This is not how it works. It does an absolute move. To get a relative move, you should add or subtract from the value returned by GetFocusLensCurrentPosition. You should make sure that the resulting value is within the limits provided by GetFocusLensMoveMinPosition and GetFocusLensMoveMaxPosition, as Move is reported to crash with values outside those limits.

As a general comment, I'd highly recommend starting with a simple test case to understand the actual behavior of the functions rather than trying to implement a full bracketing script from the get go.

I personally find chdkptp invaluable for this kind of thing, because it allows me to interactively test functions and see the results, but YMMV.
« Last Edit: 25 / January / 2023, 15:05:09 by reyalp »
Don't forget what the H stands for.

*

Offline reyalp

  • ******
  • 14086
Re: Lens movement/focus control
« Reply #21 on: 25 / January / 2023, 15:04:30 »
Additional observation:
On G7 X, the range returned by GetFocusLensMove*Position does seem to vary with zoom:

Code: [Select]
con 5> =return call_event_proc('GetFocusLensMoveMinPosition'), call_event_proc('GetFocusLensMoveMaxPosition')
6:return:13
6:return:1651
con 6> =set_zoom(100)
con 7> =return call_event_proc('GetFocusLensMoveMinPosition'), call_event_proc('GetFocusLensMoveMaxPosition')
8:return:13
8:return:3467
Don't forget what the H stands for.

Re: Lens movement/focus control
« Reply #22 on: 25 / January / 2023, 15:05:09 »
Quote
It seems you expect MoveFocusLensWithPosition to do a relative move, i.e. + or - form the current position. This is not how it works. It does an absolute move. To get a relative move, you should add or subtract from the value returned by GetFocusLensCurrentPosition.

I can confirm that the move is relative.

That is, I tested multiple calls and tested the position after the move call. It all matched.

I really appreciate your warnings. I must say, so far all looks good.

If I don’t use MoveFocusLensWithPosition, is there any other route to getting a P&S cam to  move the lens in steps?

Cheers
« Last Edit: 25 / January / 2023, 15:18:58 by pigeonhill »

Re: Lens movement/focus control
« Reply #23 on: 25 / January / 2023, 15:06:31 »
Additional observation:
On G7 X, the range returned by GetFocusLensMove*Position does seem to vary with zoom:

Code: [Select]
con 5> =return call_event_proc('GetFocusLensMoveMinPosition'), call_event_proc('GetFocusLensMoveMaxPosition')
6:return:13
6:return:1651
con 6> =set_zoom(100)
con 7> =return call_event_proc('GetFocusLensMoveMinPosition'), call_event_proc('GetFocusLensMoveMaxPosition')
8:return:13
8:return:3467


This is why I calibrate at start up, and will recalibrate after focal length change, as I do on my M3 s ript.


Re: Lens movement/focus control
« Reply #24 on: 25 / January / 2023, 15:46:29 »
Quote
It seems you expect MoveFocusLensWithPosition to do a relative move, i.e. + or - form the current position. This is not how it works. It does an absolute move. To get a relative move, you should add or subtract from the value returned by GetFocusLensCurrentPosition.

I can confirm that the move is relative.

That is, I tested multiple calls and tested the position after the move call. It all matched.

I really appreciate your warnings. I must say, so far all looks good.

If I don’t use MoveFocusLensWithPosition, is there any other route to getting a P&S cam to  move the lens in steps?

Cheers
Put what I said above on hold, ie regarding relative move. Just spotted a silly mistake. More later ;-)

*

Offline reyalp

  • ******
  • 14086
Re: Lens movement/focus control
« Reply #25 on: 25 / January / 2023, 15:47:22 »
I can confirm that the move is relative.
If this is correct, it's completely different from the behavior I observed. In my testing, MoveFocusLensWithPosition clearly did an aboslute move to the specified position. That is, after MoveFocusLensWithPosition(X,0,0)  GetFocusLensCurrentPosition returns X.
Code: [Select]
connected: Canon PowerShot ELPH 180, max packet size 512
con 7> =return call_event_proc('Mecha.Create')
1:return:0
con 1> rec
con 2> =return call_event_proc('GetFocusLensMoveMinPosition'), call_event_proc('GetFocusLensMoveMaxPosition')
3:return:40
3:return:1840
con 3> =set_mf(true)
con 4> =return call_event_proc('GetFocusLensCurrentPosition')
5:return:770
con 5> =return call_event_proc('MoveFocusLensWithPosition',600,0,0)
6:return:0
con 6> =return call_event_proc('GetFocusLensCurrentPosition')
7:return:600
con 7> =return call_event_proc('MoveFocusLensWithPosition',770,0,0)
8:return:0
con 8> =return call_event_proc('GetFocusLensCurrentPosition')
9:return:770

I would be extremely surprised if it's relative on some cams and absolute on others.

Quote
If I don’t use MoveFocusLensWithPosition, is there any other route to getting a P&S cam to  move the lens in steps?
Well, other functions with suggestive names exist. Analysis would be require to understand how to use them, and there's no particular reason to think they would be safer.

From further testing on Elph180, it seems like there might be a crash related to MF after using these functions. After the above test, the camera crashed on set_mf(false). The next power on retracted the lens as normal. So it's possible the previous lens error was related to crashing with the lens in an unusual position.

edit:
In fact, just set_mf(true), set_mf(false) crashes that cam :blink:
« Last Edit: 25 / January / 2023, 15:49:53 by reyalp »
Don't forget what the H stands for.

Re: Lens movement/focus control
« Reply #26 on: 25 / January / 2023, 16:14:11 »
@reyalp

You are, of course, 100% correct.

My silly mistake, that gave me false hope, was that I tested the script on my M3  >:( :( :o ??? :-[ :-[ :-[ :-[

Reading your sagely advice, and doing a quick test on my G5X, has reluncantly led me to stop this development :-(

If you and others do find a safe way to move the lens in steps. ie not mm, on the P&S cams, then I'll restart my development.

Focus bracketing on the image side (steps) is the way to go ;-)

Cheers

Garry


*

Offline Mlapse

  • *****
  • 583
  • S95 S110
Re: Lens movement/focus control
« Reply #27 on: 25 / January / 2023, 16:31:31 »
as far as i could determine, the p&s don't have an actual stepper motor. this results in the step not being at the same focus point between (re)boots or when zooming.
frustration is a key ingredient in progress


Re: Lens movement/focus control
« Reply #28 on: 25 / January / 2023, 16:33:35 »
as far as i could determine, the p&s don't have an actual stepper motor. this results in the step not being at the same focus point between (re)boots or when zooming.

@Mlapse

Yes I had spotted that, which is why I calibrate on start up and when focal length changes. I do this on my Quasi DoF script and it works a charm.





*

Offline Mlapse

  • *****
  • 583
  • S95 S110
Re: Lens movement/focus control
« Reply #29 on: 25 / January / 2023, 16:47:11 »
with your script you can actually set the focus to a repeatable position between (re)boots or only when zooming within that session?
frustration is a key ingredient in progress

 

Related Topics


SimplePortal 2.3.6 © 2008-2014, SimplePortal