Setting focus from scripts or menus - page 38 - General Discussion and Assistance - CHDK Forum

Setting focus from scripts or menus

  • 557 Replies
  • 141912 Views
*

Offline reyalp

  • ******
  • 13502
Re: Setting focus from scripts or menus
« Reply #370 on: 15 / March / 2014, 22:33:04 »
Advertisements
Another "fun" thing. Lua set_focus
Code: [Select]
...
        if (camera_info.cam_has_manual_focus)
        {
...
        }
        else
        {
            if (shooting_get_common_focus_mode() || camera_info.state.mode_video) shooting_set_focus(to, SET_NOW);
            else shooting_set_focus(to, SET_LATER);   
        }
...
Ubasic
Code: [Select]
          if (camera_info.cam_has_manual_focus)
          {
...
          }
          else
          {
              if (camera_info.state.mode_video) shooting_set_focus(sd, SET_NOW);
              else shooting_set_focus(sd, SET_LATER);   
          }

Note the lack of the shooting_get_common_focus_mode() check.
Don't forget what the H stands for.

Re: Setting focus from scripts or menus
« Reply #371 on: 15 / March / 2014, 22:53:53 »
We listed PressSw1AndMF as "working" for D10 in waterwingz spreadsheet, but it actually has no effect. Since the camera is able to override in AF, overrides continue to work after calling it. Elph130 is similar: override crashes in AF and also crashes with PressSw1AndMF.
I guess that's limitation of the existing MF_test.lua script.   It makes the calls to setup AFL or MF modes, does a couple of set_focus() commands and uses a half-press (or shoot) to see if the focus reads back correctly.   

But if the camera can focus without AFL or MF then its hard to say if setting those made any difference.  One of the limitation of trying to move from "doesn't work" and/or "crashes"  to  "this works even if its redundant".

And now I realize that the script does not check the return status of post_levent_for_npt("PressSw1AndMF").

Ouch.

With 20:20 hindsight I should have reported what PressSw1AndMF does to prop.FOCUS_MODE.  That's the bad news - I missed that.  The good news is that I still have the data - its in the original spreadsheets!!  For the D10 example,  the spreadsheet shows prop.FOCUS_MODE not being changed by PressSw1AndMF. And because of how the script missed checking return status, its not even clear that's a valid levent.

So where do we go from here?



Ported :   A1200    SD940   G10    Powershot N    G16

*

Offline reyalp

  • ******
  • 13502
Re: Setting focus from scripts or menus
« Reply #372 on: 15 / March / 2014, 23:02:24 »
But if the camera can focus without AFL or MF then its hard to say if setting those made any difference.  One of the limitation of trying to move from "doesn't work" and/or "crashes"  to  "this works even if its redundant".
Right, wasn't complaining, it was a very good start.
Quote
For the D10 example,  the spreadsheet shows prop.FOCUS_MODE not being changed by PressSw1AndMF. And because of how the script missed checking return status, its not even clear that's a valid levent.
If you call with a non-existent name, there will be a lua error and the script will terminate. (edit: from lua, from C code you are on your own if you don't check...)
Don't forget what the H stands for.

*

Offline reyalp

  • ******
  • 13502
Re: Setting focus from scripts or menus
« Reply #373 on: 15 / March / 2014, 23:14:44 »
First test:
Code: [Select]
___> connect(0)
connected: Canon PowerShot S110, max packet size 512
con> =set_record(1)
con 1> =return get_focus()
2:return:155
con 2> =set_focus(1000)
con 3> =return get_focus()
4:return:155
con 4> =press 'shoot_half'
con 5> =return get_focus()
6:return:155
There is another issue at play in this case. If you use SD override while not in MF mode (or aflock in recent CHDK 1.3 version), the actual override is only applied when you have shoot. The same logic applies to things like shutter override, and any keys pressed are released when the script ends.

Script overrides that haven't be applied yet are reset for each new script.  Each = command is a new script.
So if you do
=set_focus(1000)
=return get_focus()

the override has never been applied, and get_focus() just returns the actual focus value.

something like

=set_focus(1000) press('shoot_half') sleep(1000) return get_focus()

should return the modified focus value, if your camera can sd override in AF mode.
« Last Edit: 15 / March / 2014, 23:16:19 by reyalp »
Don't forget what the H stands for.


*

Offline reyalp

  • ******
  • 13502
Re: Setting focus from scripts or menus
« Reply #374 on: 16 / March / 2014, 01:06:40 »
Looking at the shooting_get_common_focus_mode stuff in Lua set_focus, I've concluded that it's just wrong.

In an auto mode, SET_NOW will never have the desired effect, so it's irrelevant whether conf.subj_dist_override_koef is set or net (it could theoretically update the non script override values at the same time to cooperate with CHDK shortcut MF, but it doesn't)

Based on that, I've made the following patch that cleans up script set_focus.

It now uses SET_NOW if in MF (whether or not the camera has native MF, as determined by PROPCASE_FOCUS_MODE), AF lock, or movie mode. It uses SET_LATER otherwise.

Additionally, I made set_focus in lua return a boolean rather than a number, and both Lua and ubasic not call any set_focus functions if shooting_can_focus is false.

I tested this on my cameras with mftest.lua and mf6.lua. Unless there are objections, I will check it in. It doesn't address the crash, but I think it reduces some of the other confusion.

The movie mode logic is a carry-over from the old code, and is probably wrong. It may be appropriate to use SET_NOW if a movie is recording. On many cameras, I expect that you can set MF or AF lock before starting recording, and then set the focus as you please.
Don't forget what the H stands for.

Re: Setting focus from scripts or menus
« Reply #375 on: 16 / March / 2014, 01:26:21 »
It doesn't address the crash, but I think it reduces some of the other confusion.
Sorry .. which crash?
Ported :   A1200    SD940   G10    Powershot N    G16

*

Offline reyalp

  • ******
  • 13502
Re: Setting focus from scripts or menus
« Reply #376 on: 16 / March / 2014, 01:41:47 »
Don't forget what the H stands for.

Re: Setting focus from scripts or menus
« Reply #377 on: 16 / March / 2014, 09:33:35 »
Sorry .. which crash?
The aflock ASSERT!! FocusLensController.c Line 829 crash
http://chdk.setepontos.com/index.php?topic=11078.msg111171#msg111171
http://chdk.setepontos.com/index.php?topic=11078.msg111140#msg111140
I was thinking more about which shooting circumstance that triggers that crash. But I guess it should not matter if the patch works correctly.
Ported :   A1200    SD940   G10    Powershot N    G16


*

Offline reyalp

  • ******
  • 13502
Re: Setting focus from scripts or menus
« Reply #378 on: 16 / March / 2014, 15:26:25 »
I was thinking more about which shooting circumstance that triggers that crash. But I guess it should not matter if the patch works correctly.
Yeah, that's why I mentioned the crash. Changing the logic of where the override is applied may make the crash testing a bit of a moving target, but I think it's worth it because the old code could introduce quite a bit of confusion (like the results I got for elph130, which made it look like set_focus in MF wasn't working...)
Don't forget what the H stands for.

*

Offline reyalp

  • ******
  • 13502
Re: Setting focus from scripts or menus
« Reply #379 on: 16 / March / 2014, 17:32:51 »
Unless there are objections, I will check it in.
I checked this in, trunk changeset 3383.

The main impact is cameras that do NOT have MF, but do have a set_mf() method will use set_now when in MF mode.

Regarding the crash, from IRC:
< nafraf> a810, SD Mode[set_afl], Refocus[yes], delay[No], get_shooting[Yes], bypass Interlocks[Yes] => no crash
< reyalp> interesting, a810 worked without aflock according to the spreadsheet
< reyalp> so as long as scripts know what to do, this isn't a big deal

< nafraf> same results for sx240.
< nafraf> sx240: SD Mode[set_mf], delay[Yes|No], get_shooting[No] => Crash
< nafraf> sx240: SD Mode[set_mf], delay[Yes|No], get_shooting[Yes] => No crash

Don't forget what the H stands for.

 

Related Topics