SPACE
APPROACHING THE FINAL FRONTIER
NEAR
■ BY L. PAUL VERHAGE
THE CANON HACKER
DEVELOPMENT KIT - PART 2
Last time, this column introduced CHDK and how to load it on a camera’s
SD card. Locking the SD card makes it bootable on a Canon camera and that
allows you to write simple scripts that automate features of Canons that
aren’t otherwise available. This month’s column discusses the syntax of the
uBasic scripting language so you can begin writing your own scripts. The
next article will cover when I gave a NearSys BalloonSat flight computer
control of a Canon camera running a remote script.
There is no editor for uBasic per say, although it would make a great tool if it could syntax check scripts
before loading them into your Canon (hint, hint). So, if
there’s no uBasic editor, what program does one use to
create a script? Most people probably use Notepad
because uBASIC scripts are text files without formatting
commands.
SOME CHDK SYNTAX
One way to teach syntax is to explain with examples.
So, let’s look at the two scripts I’ve worked with so far. I
selected these scripts because they are appropriate for my
near space missions. The first example allows my
PowerShot A550 to take pictures when the flight
computer commands it to. I would use this script in
conjunction with a sun sensor. When the near spacecraft
rotates to the proper sun angle, the flight computer would
instruct the camera to take a picture. Controlling the
camera based on sun angle prevents some of the wasted
images that occur when the camera shoots an image
while it is pointed directly at or directly away from the
sun. A script like this would also allow the flight computer
to orient the camera with a servo before recording an
image. This script uses the camera’s USB port like a cable
release:
rem NearSys USB Remote
rem Enable Remote operation in camera’s menu
@title Remote Button
:loop
wait_click 1
is_key k “remote”
if k=1 then shoot
68 November 2010
goto “loop”
end
Here’s an explanation of the syntax in this short script.
REM
REM is short for remark. uBasic ignores remarks;
they’re placed in the script just for us humans.
@title Remote Button
@title indicates the title or name of the script. This is
the title that shows up on the camera’s LCD screen once
you start the script.
: loop (colon loop)
The colon signifies a label. Labels are locations you
can send programs to using goto and gosub.
wait_click n
wait_click is a command that tells the camera to wait
for any button to be pushed. It’s not required that a
number appear after the wait_click. However, if there is a
number, then the number is a timeout that the script waits
in milliseconds. Either after a button is pushed or when
the timeout occurs, uBASIC goes to the next line in the
script. Timeouts can be life savers if something is wrong
with the script or the camera hangs.
is_key k “remote”
The is_key k “remote” statement asks if the last
button pushed was the one called remote. If true, then the
variable k is set to 1 (true). If not true, then the variable k