Contents

One of the very useful features of CHDK is its ability to focus the camera manually, either as part of a script or through the CHDK menus. While some Canon cameras have a built-in manual focus options, many do not. And for all cameras, the ability to set a focus point in a script can be important, either for "focus stacking" shots or to force the camera to focus at infinity (or the hyper-focal point) when shooting with intervalomters.

However, determining how to use CHDK to reliably manually focus a camera's lens can be difficult as many cameras need to be configured a little differently. This applies to both the "set_focus()" command in CHDK scripts, or the "Override Subject Distance" menu item in the CHDK's Enhanced Photo Operations menu. This problem is caused by there being no standard method that works for every camera that allows you to enable manual focus using CHDK.

Others will only focus when the camera's built-in autofocus is locked (AFL) prior to a set_focus() or SD override via menu.

And still others need the camera to be in Canon manual focus (MF) mode before you can focus via CHDK set_focus() or SD override via menu.

Listed below are some notes collected from various CHDK forum posts and wiki pages that should help you determine how to enable manual focus via CHDK for your camera. A Lua script is also given to simply determine what works for a particular camera.

set_aflock(1) causes the Canon firmware to stop focusing when shooting

does an initial focus measurement and sets focus at that value when called

set_aflock(0) restores camera automatic focusing.

seems to works on almost all cameras

using set_aflock() may be necessary on some camera for set_focus() to work (elph310). On other cameras, it has no effect on whether set_focus() works.

on some cameras, the set_aflock() command must be issued after a "half-press" focus completes and before the half press is released

if you call set_aflock() and then set_focus() (in a mode on your camera where that works) then the focus for all subsequent shots will stay at the value specified in set_focus(). If set_aflock() has not been called then set_focus() will only apply to the next shot - after that the camera will revery to auto focus.

When in Canon MF mode, focus will be set immediately when a set_focus() command is issued. Otherwise the focus will not take effect until after the "half-press" part of the shooting sequence.

If all of the above fail to work, you may be able to set focus to infinity on any camera by using click() commands to select the "landscape" focus mode. The needed button is usually indicated by the tulip flower icon on one of the camera buttons but check your camera manual to be sure.

The script copied below lets you try out the various options for using set_focus(). Save it to an ASCII plain text file with the name mf-test.lua.

The script provides six choices of camera setup - pick one from the user parameter at run time to see if that mode will work for your camera.

The script will attempt to focus at 100, 200, and 300 mm and take a two test shots at each distance. The first shot is preceeded by a set_focus() command but the second shot is not. The purpose of the second shot is to see if the focus distance set for the first shot is preserved for the second shot.