New CHDK script for KAP - UAV for fast shutter speeds

edited November 2013 in Control Systems
A new KAP script for CHDK has been published by waterwingz on the CHDK site:

The main purpose of the script is to manage all of the exposure settings so that a fast target shutter speed is maintained, thereby maximizing picture sharpness. The variables are managed independently for each picture, which provides flexibility for variable lighting conditions not available from a simple Tv mode setting. The script also provides the usual intervalometer parameters, as well as parameters for exposure compensation, zoom, fixed focus at infinity, and USB run/pause control. The hope is that you can set all these parameters in advance, and just start the script running when you launch rather than having to change camera settings manually.

The script works for cameras with any combination of adjustable iris and/or ND filter. It will run under CHDK versions 1.2 and 1.3, but in either case build 3149 or later is required.

This project grew out of previous discussions on CHDK's Custom Auto ISO function, which works in a manner similar to the new script, except that it does not manage the aperture setting.

I've been working with waterwingz for a couple weeks on this script, and I think it's pretty good, but any input on needed changes or fixes would be appreciated, either here or in the CHDK forum.

I hope the script will be useful.


  • In case you missed it, you may be interested in the following comments that I have posted previously :-

    Michael Layefsky and others have long used the following SDM methods that give correctly exposed images at 8x normal shutter speed :-

    The second method allows you to set maximum ISO.
    This has been used on stratospheric balloon flights.
    It does what you want the CHDK script to do.

    My own tests suggest that with these small sensor cameras and with a subject essentially at infinity (which optically can be less than two metres at wide-angle !) stopping-down the aperture is undesirable.

    It reduces sharpness and forces a lower shutter speed.

    Bear in mind that f4 on these cameras is typically equivalent to f22 on a 35mm camera as far as depth-of-field (that you do not need) is concerned.

    The SDM strategy is to force the ND filter out and set aperture to maximum.
  • Thanks so much, David, for your encouragement and support.
  • Thanks wayback! I'll test this script as soon as possible! Unfortunately I have no idea when that is, the weather seems quite sucky this week and sunlight very limited. I hope for next weekend. But the script looks nice, good work.
  • edited October 2013
    It may be useful to provide hard evidence as to why I say shutter speed and iso alone can deal with all practical shooting conditions.

    Consider the following settings from a user in Las Vegas in very bright conditions :-

    Bv96 = 900 (brightness)
    Sv96 = 465 (100 ISO real)
    Tv96 = 1148 (1/4000 sec)
    Av96 = 363 (f3.7 real)

    In other words, aperture fully open in very bright light.
    Most shooting conditions will be in dimmer light where shutter speed needs to be reduced and/or ISO increased.

    There is no reason to change the aperture (that is, make it physically smaller).

    For cameras with an ND filter that is obviously ALWAYS forced out.
  • In my experience with my A590is, mid-range apertures seem to be a bit sharper than either wide open or completely stopped down. So I would prefer to shoot at something like f/3.5 or f/4.0 since that produces better pictures for me. But that's a preference, and for KAP in particular I would be willing to go wide open if it means I don't have to slow down the shutter speed, which is the most important determinant of getting sharp pictures. The script manages those decisions automatically based on the user's parameter settings and the algorithms described in detail in the wiki linked to above.

    The new script has the advantage of letting me set value preferences and ranges for all exposure components - shutter speed, ISO, and aperture or ND filter. Someone who believes the aperture setting has no effect on sharpness can set his aperture preference to wide open and shoot on that basis, and he may still benefit from other features found in the script. Or if he doesn't want to use the script, he can lock his aperture to wide open and just use the Custom Auto ISO function found in the CHDK menu, which works much as the script does, but without any aperture control.

    So the script offers the user a good bit of flexibility to set the exposure preferences the way *he* wants to, without locking them in stone, and it provides within the script a few settings that normally require manual camera settings, such as going into manual focus, then setting focus to infinity, or zooming to a particular point. In fact, if you use auto-run, everything would be automatic - you would only have to hit the power button to turn on the camera.

    By the way, I should mention that for my A590is, and presumably the A570is, the Focus setting "MF2" in the parameters is the one that works to go to manual focus at infinity. Or if you want to use autofocus, just set that preference to "Off".
  • OK, updated CHDK version and installed the script. Looks good. Now just waiting for airtime. :D
  • I hope you get some good wind, Henrik. Let me know how the script works for you.
  • Alrighty, I had a test drive today! :)

    The wind was scary, but I had set my mind to test this, so I did.

    It was bumpy ride, so I decided to target 1/1000.

    Relevant settings that I used:

    Av Mode: Iris
    Target Tv: 1/1000
    Tv Max: 1/2000
    Lowest Av: 2.8
    Target Av: 4.0
    Highest Av: 8.0
    ISO Min: 80
    ISO Max1: 100
    ISO Max2: 200

    I deliberately kept the ISOs low.

    I'm very happy with the results. Even though the light was already so low, that every pic was with f/2.8, I think the readings are consistent. And the exposure is as good as it gets with this camera (A640). Clouds over exposed mostly, but that's a metering issue, I think I have to set exposure compensation down a bit, and that'll do the trick. There was couple pics with 1/1000 and ISO 120, so quite close already to switch to f/3.5 or so, but not enough light. Exposure range in the captured pics was from 1/320 to 1/1000.

    All in all, I'm very happy with this. It's clear, easy and it works. Thanks Wayback! :)

    All saved pics from the trip:


  • I'm glad it worked for you. The pictures look sharp, which was the primary goal.

  • Anxious to try it also with my A810, which has only ND filter, no iris. :)
  • Thank you for a very nice script!
    I used it today with a powershot 230HS to shoot theese images:
    I only changed the frequency and used the ND filter setting. The images were much better than last attempt.
  • Does the script allow the focus to be set by hyperfocal distance (based on f /stop and zoom focal-length)?

    Photos taken with an A590 using the hyperfocal distance are sharper than using infinity.
  • edited October 2013
    The current script does not have a hyperfocal focus option but it would be easy to add to the next release if you think that would be valuable?

    Edit : I should probably also point out that the ability of CHDK to successfully set a manual focus varies somewhat with camera model. The script allows you to select from all the methods discovered so far (trial & error) to see which one might work for your camera. If one of the methods works then hyperfocal distance selection is possible.
  • bisenberger, do you use CHDK to set the focus to the hyperfocal distance? I've never played with that on my A590, but testing the various focus distances you can get manually on the camera, I haven't found that the next step closer from infinity, which I think is 20 ft, is any better than infinity for sharpness.

    If you're not using any zoom, and the aperture is f2.6, what is the hyperfocal distance?

  • Hi waterwingz,
    I just upgraded my CHDK in my PS A590is to Ver 1.2.0-3192 an loaded the script, but when I start the script I get the following error: bad argument #1 to ´set_prop´ (number expected, got nil) and the script gets terminated.

    What I'm missing?
    Any help is really appreciated.
  • Ramiro

    when you did the upgrade to CHDK did you update the CHDK folder? There should be a LUALIB subfolder with a file called 'propcase.lua' and a subfolder in that called GEN with various propset files (propset1.lua etc). The set_prop command needs to access that stuff.
  • edited October 2013
    Just managed to upgrade CHDK to 1.2 on one of my A2300's and loaded the KAP UAV script. Seems to work except the MF4 setting causes CHDK to stall.
  • Getting manual focus to work properly with CHDK is a bit "hit or miss". The method needed varies a lot from camera to camera unfortunately so the script includes all the methods most commonly used. Not all will work - you have to do a little "trial & error" to see what works for your camera.
  • As Dave said, if you're updating to a new major version of CHDK, such as 1.1 or earlier to 1.2, or 1.2 to 1.3, you want to download from the "Complete" column on the downloads page, not the "Small" column. Delete all the old CHDK stuff on the card, in both the root directory and the CHDK folder, then replace it with the Complete stuff, plus of course the new KAP script, which goes in the Scripts subfolder.
  • Thank you very much Dave and wayback!!
    I just did what you said and the script worked without any problem!
  • edited November 2013
    waterwingz, yes hyperfocal distance would be a valuable option.

    wayback, yes I use CHDK to set the hyperfocal distance. On the version of CHDK I've been using if your A590 is in manual focus mode (with ALT on) pressing the down button sets MF distance to hyperfocal distance. The resulting image is sharper than when it's set to infinity. The A590 is still and excellent KAP camera.
  • edited November 2013
    The following is from the CHDK April 2009 user guide.

    More keys and shortcuts:
    In manual focus mode - (with ALT)
    Up – Set MF to infinity
    Down – to set MF distance to hyperfocal distance (based on f/stop and zoom focal-length).
    Left – Decrease Value Factor,
    Right – Increase Value Factor.
  • edited November 2013
    I've now tried this lua script on both my A640 and G7 and I am very impressed. I've yet to test it on my IR converted A640.

    The addition of hyperfocal distance to the script would for me be the icing on the cake. When taking full fish eye images and using the zoom to fill the view finder, it would hopefully ensure better definition in the images especially towards the edges of the image. I know the quality of the optics figures here too but it would help.

    To understand the problem this site has an online Depth of Field Calculator which not only gives numbers but graphics to complement your entered data. Using my data you can see by the graphics how setting the focal length/hyperfocal distance can affect the image outcome.

    Data: Canon A640, Focal Length 5.8mm (29.2x0.2=5.84 [0.2=fish eye value]), f-stop f/4
    approx vertical height 150 feet.


    The site also has an extensive list of Circles of Confusion for most cameras as well as a calculator.


    Further explanation in my case using fish-eye. The problem is I need to over-ride the camera doing its own thing while range-finding. The circumference of the lens impedes on the camera's sensors, giving erroneous readings. The manual setting is such a fiddle and therefore errors when setting up. The ability to dial it in once and for all is attractive.
  • edited November 2013
    Thanks for the links toadstone, very handy!

    Like wayback, I found the sweet spot on my A590 IS to be around f/4.0.
  • edited November 2013
    A590 IS:
    If the focus lock is set to off in the script, and you use CHDK to set the focus to hyperfocal distance before running the script the photos will be taken at the hyperfocal distance. You will want to make sure Iris is not enabled for AV Mode in the script, as different apertures will affect the hyperfocal distance.

    Really cool script!
  • edited November 2013
    I have been playing around sometime with hyperfocal distance with my A590is and my experience is that if you set the focus in the hyperfocal distance, although it is technically true that you get the maximum depth of field possible, the sharpness in "infinite" would be almost not acceptable.
    And usually focusing in the hyperfocal distance it is not needed while doing KAP since you don't have a lot of objects too close to the kite even, if you are taking pictures of other kites.
    Plase take a look to the table below.

    Canon A590is

    I hope this helps.

    PS: For some reason I can't include the picture of the table :-(
  • edited November 2013
    Here's a comparison between infinite and hyperfocal focus with safety MF both off and on. Safety MF makes a big difference on hypefocal.
    f/4.0 - 1/800 - ISO 80
  • As I see it, the infinite picture is sharper at the far end than the hyperfocal picture, which is what I would expect.

    You can't really tell anything from the safety MF pics because safety MF is actually autofocus, and since you have both near and far objects in the frame, you don't really know what it's focusing on each time.

    If the hyperfocal distance is, say, 10 feet, then focus is perfect only at 10 feet. Nearer or farther away, the subjects may still appear to be in focus, but really they are just not enough out of focus to be recognized as such. But still, focus is always best at the nominal subject distance, and deteriorates as you move away from that distance. That's why I think infinity is almost always the better choice for KAP.

    Waterwingz can do as he likes, but I just don't think building in a hyperfocal setting into the script would be useful for the great majority of KAPpers. Might be more useful for UAV though.
  • edited November 2013
    The above is not a valid test.

    "the subjects may still appear to be in focus, but really they are just not enough out of focus to be recognized as such."

    Which means they ARE in focus under those viewing conditions.
    The point is, the magnified views in the images above represent a different set of viewing conditions.
    For the magnified images viewed at the same distance, the 'circle-of-confusion' would be smaller and the hyperfocal distance would be different than that used.
    It would move closer to infinity.

    I agree there is no point having a hyperfocal option.
    If you are using a wide-angle setting with a UAV then it is not needed there either.
    Anything beyond one metre is at infinity anyway.

    As for aperture, that should not be variable but fixed at your determined optimum value.
    In the case of my S95 that is fully open.

    Just change shutter speed and ISO, that is all that is needed.

    Keep it simple ............
  • The photos were all taken from the same location on a tripod at f/4.0 - 1/800 - ISO 80. The only difference between the images were the focus set at hyperfocal and infinite and the Safety MF setting. The posted image is a screen capture from Adobe Bridge Review Mode. The Loupe tool is a feature of Review Mode that lets you compare areas of different images at 100% magnification (1:1). For more information on Adobe Bridge Review Mode and the Loupe tool see this link.

    I agree that it looks like hyperfocal distance is of little value for KAP.

    I've notice with my cameras that the sweet spot is around the middle of Aperture range. I prefer to use the AV setting for KAP with lower ISO to avoid noise in shadow areas.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion