Script that will fire on focus change? - Script Writing - CHDK Forum
supplierdeeply

Script that will fire on focus change?

  • 23 Replies
  • 15275 Views
Script that will fire on focus change?
« on: 29 / May / 2008, 10:40:14 »
Advertisements
I have a very specific photographic function that I would like to perform and I was wondering if any of you scripting gurus would like to help me out. I take pictures of RC airplanes for a website (rcgroups.com). This involves trying to follow a very fast airplane through the sky and taking a snap when it's in the center of the frame and focused. (Infinity doesn't work.)  This works about 1 in 100 times if I try to do it manually. It's very frustrating.

What I would like for my S2 is a script that would fire whenever the focus changed from infinity to anything closer to infinity. Then I could pan through the sky and any time the airplane was locked in the center of the frame and focus locked, it would fire as fast as it possibly could while re-focusing in between shots (the airplane is moving remember). Then when I'm back pointing at the sky, it would wait. (I guess I would have to remember to stop the script or I'd end up taking hundreds of pictures of my feet or the inside of my camera bag...)

Any ideas? (I'm not a programmer myself.) TIA

Re: Script that will fire on focus change?
« Reply #1 on: 29 / May / 2008, 13:25:56 »
Interesting idea for a script. Here is a preliminary (untested) version. Parameters are:

Distance x 5 Inches: The target focal distance. If you put in 20, it will be 100 inches

Include=1 Exclude=2: When include is selected, the camera will shoot when focus falls in the selected range. When exclude is selected, it will shoot when focus falls outside the range

Range x 5 Inches: The amount of variance from target distance you want to allow. If distance is set to 20 and this value is set to 2, the effective target distance will be the range 90 inches to 110 inches

I haven't tested this script, so there may be some errors. I am not sure what value "get_focus" returns when the focus is set to infinity. If someone could let me know, I'll work that into the script. I wrote this for a Digic III camera. Digic II camera users will need to change "206" to "205" in the 2 get_prop commands.

Edit: updated code is below
« Last Edit: 30 / May / 2008, 14:45:22 by A_Str8 »

Re: Script that will fire on focus change?
« Reply #2 on: 29 / May / 2008, 13:36:32 »
After doing some searching around here, it seems infinity =-1. The script has been modified. I also fixed some logic errors in the "exclude" section
« Last Edit: 29 / May / 2008, 13:50:09 by A_Str8 »

*

Offline fudgey

  • *****
  • 1705
  • a570is
Re: Script that will fire on focus change?
« Reply #3 on: 29 / May / 2008, 14:06:54 »
I see A_Str8 beat me to it but this is what I cooked up...
It's not compatible with Ae lock because of the get_prop 205/206's. It's a really good wear out test for the focus mechanics, I'm afraid... :D

A_Str8: AFAIK, different cameras may have different values coming out of get_focus... my a570is gives 65535 for infinity, not -1 like yours. But it doesn't matter with my script anyway, you can either specify the reference distance as a parameter or let the script measure it for you automagically.

edit: hmm... actually it does matter since if infinity is negative in your camera, you'll have to be creative and use the "further" mode if you select infinity as reference or the camera will never shoot. Didn't think of that since for my camera infinity is positive :)

Burst mode would probably be a desirable addition, but let's see how this one works first...

Digic III:
Code: [Select]
rem CHDK uBASIC script. Shoot when the camera finds focus closer/further
rem to a reference distance. At startup, camera must be pointed at
rem the reference distance or reference can be given as a parameter.
rem
rem To find a value for the reference parameter, use the auto mode
rem and read what the script reports you. It may or may not be
rem in millimeters, this depends on your camera model.
rem
rem Works on Digic III, developed on A570IS.
rem Change get_prop 206->205 for Digic II.
rem Author: Fudgey on 20080529

@title Focus Shoot
@param a Reference (0=Auto)
@default a 0
@param b Closer=0, Further=1
@default 0

if a=0 then gosub "getreference" else R=a

cls
print "Ref is", R
print "READY, SEARCHING FOCUS."

if b=1 then goto "further" else goto "closer"

:closer
  press "shoot_half"
  do
    get_prop 206 P
  until P=1
  get_focus F
  if F<R then click "shoot_full" else release "shoot_full"
  do
    get_prop 206 P
  until P<>1
goto "closer"

:further
  press "shoot_half"
  do
    get_prop 206 P
  until P=1
  get_focus F
  if F>R then click "shoot_full" else release "shoot_full"
  do
    get_prop 206 P
  until P<>1
goto "further"

:getreference
  cls
  print "Point at reference object,"
  print "press MENU to get reference"
  do
    wait_click
    is_key K "menu"
  until K=1
  press "shoot_half"
  do
    get_prop 206 P
  until P=1
  get_focus R
  release "shoot_half"
return

Digic II:
Code: [Select]
rem CHDK uBASIC script. Shoot when the camera finds focus closer/further
rem to a reference distance. At startup, camera must be pointed at
rem the reference distance or reference can be given as a parameter.
rem
rem To find a value for the reference parameter, use the auto mode
rem and read what the script reports you. It may or may not be
rem in millimeters, this depends on your camera model.
rem
rem Developed on A570IS, modified for Digic II, hopefully works.
rem Change get_prop 205->206 for Digic III.
rem Author: Fudgey on 20080529

@title Focus Shoot
@param a Reference (0=Auto)
@default a 0
@param b Closer=0, Further=1
@default 0

if a=0 then gosub "getreference" else R=a

cls
print "Ref is", R
print "READY, SEARCHING FOCUS."

if b=1 then goto "further" else goto "closer"

:closer
  press "shoot_half"
  do
    get_prop 205 P
  until P=1
  get_focus F
  if F<R then click "shoot_full" else release "shoot_full"
  do
    get_prop 205 P
  until P<>1
goto "closer"

:further
  press "shoot_half"
  do
    get_prop 205 P
  until P=1
  get_focus F
  if F>R then click "shoot_full" else release "shoot_full"
  do
    get_prop 205 P
  until P<>1
goto "further"

:getreference
  cls
  print "Point at reference object,"
  print "press MENU to get reference"
  do
    wait_click
    is_key K "menu"
  until K=1
  press "shoot_half"
  do
    get_prop 205 P
  until P=1
  get_focus R
  release "shoot_half"
return
« Last Edit: 29 / May / 2008, 14:22:10 by fudgey »


Re: Script that will fire on focus change?
« Reply #4 on: 29 / May / 2008, 14:22:03 »
A_Str8: AFAIK, different cameras may have different values coming out of get_focus... my a570is gives 65535 for infinity, not -1 like yours. But it doesn't matter with my script anyway, you can either specify the reference distance as a parameter or let the script measure it for you automagically.
I don't know that my camera returns -1 for infinity. I found that in a thread. I haven't actually tested my script, so -1 may or may not be right and the script may or may not work.

The auto reference is definitely a nice touch.
 
I converted mm to inchesx5 because it would be a pain to input further distances in mm.

*

Offline fudgey

  • *****
  • 1705
  • a570is
Re: Script that will fire on focus change?
« Reply #5 on: 29 / May / 2008, 14:25:32 »
I converted mm to inchesx5 because it would be a pain to input further distances in mm.

But only slightly... you do know you can zoom in the script menu to select a 1/10/100/1000/10000 multiplier for parameter setting?

Re: Script that will fire on focus change?
« Reply #6 on: 29 / May / 2008, 15:27:42 »
No, I didn't know that. Thanks

Re: Script that will fire on focus change?
« Reply #7 on: 29 / May / 2008, 16:00:39 »
This is great - thanks guys. I tried A_Str8's script and when I hit the shutter I get vBasic:1 unk stmt.

I haven't time right now to try fudgey's but will a bit later (perhaps tonight). I have to get back to work.


Re: Script that will fire on focus change?
« Reply #8 on: 29 / May / 2008, 23:18:21 »
Just tried fudgey's script and all I get is ***STARTED*** after I push the shutter. I put it into <alt> mode, press and release the shutter while pointed at infinity, and get ***STARTED***. Then I move until I'm pointed at something closer and it never focuses. I've tried in P and AUTO, I've tried pressing and releasing the shutter, and just pressing and holding. I think I'm missing something, or the script doesn't work.

Keep trying guys it looks like we're getting close!!

Re: Script that will fire on focus change?
« Reply #9 on: 30 / May / 2008, 07:04:22 »
I take pictures of RC airplanes for a website (rcgroups.com). This involves trying to follow a very fast airplane through the sky and taking a snap when it's in the center of the frame and focused. (Infinity doesn't work.)  This works about 1 in 100 times if I try to do it manually. It's very frustrating.

Strikes me that the solution may lie with a change of photographic method rather than CHDK cleverness. My approach would be: Zoom out somewhat, use Aperture Priority (Av) mode; select the smallest aperture possible (make the F number as high as possible - this gives the greatest depth of field) and raise the ISO setting until you get a fast enough shutter speed. Then adjust manual focus to roughly the expected distance to the aircraft. Finally, crop the photo to isolate the aircraft. It may feel like you're throwing megapixels away by cropping, but a sharp 2MP image looks a lot better than a blurry 5MP image - especially if the target market is a website.

 

Related Topics