Time-Lapse Photography with your Inexpensive Canon Camera (CHDK p. 3) - page 2
Aerial Mapping With Your Canon Point-and-Shoot
Writing UBASIC scripts
If you thought chdk-timer looked a bit like BASIC, you weren't mistaken: it's a language called UBASIC.
Each script starts with a header section:
rem Author - Keoeeit rem USE WITH CAUTION rem do not run for many hours or days @title Interval Shooting Non-stop @param a Interval (Minutes) @default a 0 @param b Interval (Seconds) @default b 10 @param c Interval (10th Seconds) @default c 0
rem, short for remark, begins a comment line.
The @title of the script defines an on-screen title.
The @param and @default lines set up parameters the user can customize through the Scripting parameters menu (Figure 2).
You're only allowed single character variable names -- a through j on earlier builds, a through z in recent versions. Even if you don't define any parameters, CHDK will display at least three in the menu, named a through c, so you might as well use them.
The script sets up a few variables:
t=a*60000+b*1000+c*100 if t<100 then let t=5000 n=1then updates the screen to let the user knows what's happening:
print "Interval shooting." print "Until you interrupt it." print "Use with caution." sleep 1000
sleep sleeps for that many milliseconds.
The heart of the script
Now we get to the good part:
:shot print "Shot number", n shoot n=n+1 sleep t goto "shot"
If you're used to more modern languages, this UBASIC loop might look a bit strange: define a label, then loop using goto. But it's typical BASIC structure.
If you want to loop a finite number of times -- suppose you know you'll never take more than 999 shots -- you can use FOR/NEXT:
for n=1 to 999 shoot sleep t next n
UBASIC also allows simple subroutines:
for n=1 to 10 gosub "shootprint" sleep t next n :shootprint shoot print n return
Of course, the most important part of this loop is the line that takes the picture: shoot. What else can you do?
You can simulate button presses for any button on the camera:
click "button-name"or wait for the user to click a button:
wait_click "button-name"The most common button names are up, down, left, right, set, zoom_in, zoom_out menu, display, print, and erase. You can also use shoot_full and shoot_half to specify full or half presses of the shutter button -- so shoot is just shorthand for click "shoot_full". Some cameras have additional buttons.
In theory, you can control your camera's aperture and shutter speed with commands like set_tv value, get_av variablename or set_av_rel value. But in practice I've found they're all very flaky on my camera -- usually the camera won't shoot after setting them, and trying to read the current settings freezes the camera.
CHDK also offers commands to get and set zoom, zoom_rel, focus, and iso. And when your script is finished, call end so it stops running.
This article barely scratches the surface -- refer to the UBASIC Tutorial page for much more detail on these and other commands. You can also get debugging hints there, and information on special CHDK builds that include other features such as motion detection.
If you find yourself frustrated with the limitations of UBASIC, there's another language available for CHDK: lua.
If you write a useful script, be sure to share it on the User-written scripts page. Don't be shy!
Akkana Peck is a freelance programmer and writer, amateur photographer and the author of the book Beginning GIMP: From Novice to Professional. She's also a control freak who loves fiddling with devices and making them do things they aren't supposed to be able to do.
- Skip Ahead
- 1. Aerial Mapping With Your Canon Point-and-Shoot
- 2. Aerial Mapping With Your Canon Point-and-Shoot
Solid state disks (SSDs) made a splash in consumer technology, and now the technology has its eyes on the enterprise storage market. Download this eBook to see what SSDs can do for your infrastructure and review the pros and cons of this potentially game-changing storage technology.
- 1Linux Top 3: GNOME 3.12 and New Betas for Ubuntu 14.04 and OpenMandriva Lx 2014.0
- 2Linux Top 3: Linus Lashes out, Linux 3.14 Gets PIE and Ubuntu One is Done.
- 3Linux Top 3: Ubuntu 14.04, Debian Gives Squeeze More Life and Red Hat Goes Atomic
- 4Linux Top 3: Linux 3.11, Kubuntu Goes Commercial
- 5Linux Top 3: RHEL 6.5, Debian 7.2 and EOL for Linux 3.0.x