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

Setting focus from scripts or menus

  • 601 Replies
  • 214741 Views
Re: Setting focus from scripts or menus
« Reply #380 on: 16 / March / 2014, 18:56:37 »
Advertisements
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.
Tested on A1200 using mf6.lua script from above.  This camera does not have MF but does have a set_mf() method  (PT_MFon).  Focuses correctly with no crashes but the second image is only captured if get_shooting or delay time is enabled.  As expected.

Might the patch to do SET_NOW need to be different with cameras that use:

Code: [Select]
PostLogicalEventForNotPowerType(levent_id_for_name("PressSw1AndMF"),0); as their MF method ?

(Note:  as discussed on IRC, I still need to go back through the individual camera spreadsheets and make sure that method actually sets the MF propcase to 1 and did not work simply because the camera could already set_focus() without an MF mode)
Ported :   A1200    SD940   G10    Powershot N    G16

*

Offline reyalp

  • ******
  • 14126
Re: Setting focus from scripts or menus
« Reply #381 on: 16 / March / 2014, 19:04:40 »
Might the patch to do SET_NOW need to be different with cameras that use:

Code: [Select]
PostLogicalEventForNotPowerType(levent_id_for_name("PressSw1AndMF"),0); as their MF method ?
If they set the propcase, the method used to get into MF shouldn't matter. On A540, the levent method basically just switches to MF mode, so it would be fine there.

One thing that needs to be checked on the cameras where PressSw1AndMF works is whether the propcase changes immediately or after some delay.

edit:
On a540
Code: [Select]
con 1> =p=require'propcase' t0=get_tick_count() post_levent_for_npt('PressSw1AndMF',0) repeat sleep(10) until get_prop(p.FOCUS_MODE) == 1 return get_tick_count() - t0
2:return:20
« Last Edit: 17 / March / 2014, 01:32:49 by reyalp »
Don't forget what the H stands for.

Re: Setting focus from scripts or menus
« Reply #382 on: 19 / March / 2014, 15:57:09 »
I've been "blowing my brains out" chasing an SD override problem for a couple days now.  I've reduced the issue to the attached script.   I'm sort of hoping somebody can spot something stupid I've done rather than this being a problem with the A1200 port or the core CHDK code.

What I'm seeing is my A1200 occasionally get stuck in a mode where it won't take a set_focus() command correctly.  The value passed by the command is basically ignored and a smaller value used instead.

This happens when using either the set_mf() or set_aflock() functions.  As with all annoying software things,  it only happens sometimes.   After hundreds of downloads, stop/start cycles, power cycles, script aborts via shutter button, etc I can't find a pattern to what makes this stop and start.  Sometimes it will do it the first time the script runs from a cold powerup, other times it starts happening after multiple runs of the script.  Most times it does not happen at all but once it gets in the error mode, it tends to stay there.

So far, the only thing I have been able to reproduce consistently (using the attached script) is that set_focus() will always work after a shoot_half but not always before a shoot_half.  I've set the script up to let an @param setting change where the set_focus() is used.  Once the camera gets into "funky focus mode",  then running the script with the set_focus() before the shoot_half always fails and running it with set_focus() after the shoot_half always succeeds.    And if you restart the script enough,  they both start working again after a while.

 ???
Ported :   A1200    SD940   G10    Powershot N    G16

Re: Setting focus from scripts or menus
« Reply #383 on: 21 / March / 2014, 08:12:37 »
Further to my previous post, another tl;dr (dropped here now more to keep a record than out of any expectation of an easy answer) :
  • the mf10test.lua script posted above almost always works correctly but
  • it will occasional start up and put the camera into "funky aflock mode"
  • once in this mode,  I can restart the script with different @params and it will stay in "funky aflock mode"
  • in "funky aflock mode" the focus is locked at a value smaller than specified in the first set_focus() command and does not respond to any further set_focus() commands executed prior to a shoot_half.
  • I can start a different test script and it also stays in "funky aflock mode"
  • after a random number of restarts, the script will begin to always rerun correctly
  • shown below are two screen shots from two sequential script runs of my mf11test.lua script (attached) running while in "funky aflock mode"
  • the text in the red boxes shows that the first set_focus(1000) after the set_aflock() fails to set the correct focus value.  It's always a lower value when this happens.
  • the text in the blue boxes shows the next attempt to set focus for the two different test conditions - one works and the other doesn't.
  • the difference between the two shots is where set_focus(1000) is executed in the script. In the first shot, it's before the shoot_half (and processed internally as a SET_NOW).  In the second shot, its after the shoot_half (again a SET_NOW but the underlying MoveFocusLensToDistance() happens after the shoot-half has set its focus position).





Like I said before, it's random but when it starts happening, it keeps happening for a while.  And fustrating.  But as least I have pix to prove it happens.
« Last Edit: 21 / March / 2014, 08:32:33 by waterwingz »
Ported :   A1200    SD940   G10    Powershot N    G16

*

Offline reyalp

  • ******
  • 14126
Re: Setting focus from scripts or menus
« Reply #384 on: 29 / March / 2014, 17:05:07 »
Regarding ubasic http://chdk.setepontos.com/index.php?topic=650.msg111718#msg111718

It seems to me a relatively simple way to deal with this would be to expose shooting_can_focus and some way to query the CAM_SD_OVER_IN* values. Although you don't strictly need these in Lua, I think it might be nice to have them there too, because it could result in clearer code.

something like
can_set_focus() -- returns the value of shooting_can_focus()

get_set_focus_modes() -- returns (bitmask?) telling you which of the CAM_SD_OVER_IN are set.

The second one could also be something like
can_set_focus_in(x) where x is something like 'mf', 'aflock' 'af' or numbers representing these

Not sure about the names...

I haven't looked at what it would take to make ubasic support discarding return values, I imagine it wouldn't be terribly hard but I'm not really enthusiastic about because
1) I don't feel like messing with ubasic
2) I'd rather not change the syntax of the language
Don't forget what the H stands for.

Re: Setting focus from scripts or menus
« Reply #385 on: 30 / March / 2014, 10:32:39 »
tl;dr > scripted SD override using the set_focus() command is still not 100% reliable.

My A1200's continues to have difficulties using AFL & MF modes under the new 1.3.0 SD override code.   The camera occasionally seems to get into a focus lock mode where set_focus() commands have no effect.  It also seems to stay locked regardless of whether it's in AFL or MF modes.  And when it starts doing this it eventually reverts to using the passed set_focus() value.

Unfortunately, when this happens appears to be random - after 100's of tests & test scripts & repeated combinations I cannot detect a pattern of what makes this happen. But approximately 20% of the time,  set_focus() fails and that's clearly a problem for this and potentially other cameras. 

Unreliable operation in scripts is probably worse than not having the function at all.

There was a recent SVN patch (3383) that causes set_focus() to use SET_NOW rather than SET_LATER that might explain why the set_mf() command is affected.  But looking at the code tells me that when the camera was in AFL mode, it previously was doing a SET_NOW.   (Also note that all the testing in this thread was done prior to this patch).

The only progress I've made is that if I modify set_focus() to always use SET_LATER, I have yet to see the bug after hundreds of test runs (usually more than enough to trigger it when it uses SET_NOW).

The original reason for using SET_NOW rather than SET_LATER when AFL was engaged is probably lost in history and it's not clear if it worked properly for all cameras given the messy state that the whole SD override code was in.  The current logic for using SET_NOW is to avoid a crash in AFL mode for some cameras. The theory is that allowing set_focus() to move the lens mechanism after a HALF_PRESS can cause timing issues and crashes.   

What to do about this then ?  Options :

  • Nothing.  Its just another broken bit of SD overrides for one camera model.
  • Continue testing for an answer.  Not sure I have much more time for this one.
  • Switch the set_focus() code back to pre-3383 state.  This will change things for set_mf() mode in cameras without Canon MF but likely won't help AFL mode.
  • Add a #define that configures set_focus() as a SET_NOW or SET_LATER command on a per camera basis. Default to SET_NOW.
  • Add a #define that configures set_focus() as a SET_NOW or SET_LATER command on a per camera basis. Default to SET_LATER

It would help to have more eyes / cameras on this.  The new meteor2.lua script I've been testing seems to be particulary vunerable to the bug and has enough print statements to show when it's happening.  For testing, turn off dark frames, set the Tv to 1 second and the shot count to 2.  If it does not fail on the first shot then it never fails during any give script run.

« Last Edit: 30 / March / 2014, 11:09:29 by waterwingz »
Ported :   A1200    SD940   G10    Powershot N    G16

*

Offline srsa_4c

  • ******
  • 4451
Re: Setting focus from scripts or menus
« Reply #386 on: 30 / March / 2014, 11:13:51 »
My same generation a3200 doesn't seem to fail when using your test script (mf11test, ~half dozen test runs).
tl;dr > scripted SD override using the set_focus() command is still not 100% reliable.
You could try calling MoveFocusLensToDistance directly (in AF lock), and see whether that succeeds setting the focus. Shooting, half-shooting may not be necessary in this experiment.
http://chdk.setepontos.com/index.php?topic=9443.msg102557#msg102557
Doing this test may make no sense, but I don't have a clear view on the CHDK SD override code to be sure.

Re: Setting focus from scripts or menus
« Reply #387 on: 30 / March / 2014, 11:25:53 »
My same generation a3200 doesn't seem to fail when using your test script (mf11test, ~half dozen test runs).
Thanks for trying that.  The randomness of this is very frustrating.  Can you try the meteor2.lua script linked above?

Quote
You could try calling MoveFocusLensToDistance directly (in AF lock), and see whether that succeeds setting the focus. Shooting, half-shooting may not be necessary in this experiment.
http://chdk.setepontos.com/index.php?topic=9443.msg102557#msg102557
Doing this test may make no sense, but I don't have a clear view on the CHDK SD override code to be sure.
That's basically what set_focus() ends up using after it gets through all the various check.  I looked at that post before and I think it was just basically allowing the user to get around the various messed up #defines in the original SD override code.
Ported :   A1200    SD940   G10    Powershot N    G16

*

Offline srsa_4c

  • ******
  • 4451
Re: Setting focus from scripts or menus
« Reply #388 on: 30 / March / 2014, 13:27:07 »
meteor2 always succeeds (setting focus to inf.) on the a3200 and ixus115...

*

Offline reyalp

  • ******
  • 14126
Re: Setting focus from scripts or menus
« Reply #389 on: 30 / March / 2014, 14:25:13 »
There was a recent SVN patch (3383) that causes set_focus() to use SET_NOW rather than SET_LATER that might explain why the set_mf() command is affected.
It was inconsistent before. In MF mode, cameras with native MF would do SET_NOW, while others would do SET_LATER.
Quote
  But looking at the code tells me that when the camera was in AFL mode, it previously was doing a SET_NOW.   (Also note that all the testing in this thread was done prior to this patch).
I think you mean MF here? AFL was not treated specially in the old code.

Quote
The only progress I've made is that if I modify set_focus() to always use SET_LATER, I have yet to see the bug after hundreds of test runs (usually more than enough to trigger it when it uses SET_NOW).

The original reason for using SET_NOW rather than SET_LATER when AFL was engaged is probably lost in history and it's not clear if it worked properly for all cameras given the messy state that the whole SD override code was in.
The using SET_NOW for AFL is recent, to avoid crashing.  The reason using it for MF is lost in history (to me at least), but it has the obvious advantage that you can see the change take effect, and if the camera is really in MF mode, it should be just like normal operation. But now we are putting cameras that don't actually have MF into some kind of MF mode...
Quote
Switch the set_focus() code back to pre-3383 state.  This will change things for set_mf() mode in cameras without Canon MF but likely won't help AFL mode.
As above, the pre-3383 state was quite inconsistent. Also, SET_LATER in AFL (and MF I think, but I'm not sure) crashes quite a few cameras, so this would break some that are currently (mostly) working.

Another alternative would be let the script decide to do SET_NOW or SET_LATER. This would not be good for script portability.

There are also some different lens control functions in the the firmware, so maybe there is something else we can call on these cameras.

For your tests, I assume you have servo and continuous AF off?
Don't forget what the H stands for.

 

Related Topics


SimplePortal © 2008-2014, SimplePortal