Page 219 - Hacking Roomba
P. 219
200 Part II — Fun Things to Do
Turning Roomba into an Alarm Clock
Roomba is now so familiar that it’s almost like a pet. Why not have it sleep at your feet like a
faithful dog? Except unlike a dog, with Roomba you can set the exact time when it will wake
you up. And you can even make it turn on the radio for you.
Listing 10-4 shows the basics of the Processing sketch RoombAlarmClock, an alarm clock
implemented on Roomba. It has the following features:
Alarm: Beep and make noise at a particular wakeup time.
Snooze button: Must hit both the left and light bump sensors.
Turn off alarm: Pick up Roomba and press the Power button.
Turn on or off radio on iTunes: Press the Clean button to play or pause.
The alarm and snooze times are determined by using Java Date and DateFormat objects.
Alter the initial time for the alarm to go off (wakeupTime) and the length of the snooze
(snoozeSecs) and run the sketch to start the alarm. When the alarm goes off, the method
playAlarm() is called, which plays a tune and vibrates Roomba back-and-forth. Pressing
both bumpers snoozes the alarm, while picking up Roomba and pressing the Power button
turns off the alarm until the next day.
The radio is turned on and off with the runRadioCmd() method. This method uses
Runtime.exec() to execute a system command. The particular command shown uses
osascript, the Mac OS X command-line tool for running Applescript statements. The
Applescript statement tell app “iTunes” to playpause will tell iTunes to play if it’s
paused or pause if it’s playing. So before using RoombAlarmClock, set iTunes to the playlist
or Internet radio station you’d like to wake up with. Then, when it’s running, at any time press
the Clean button to turn on the radio.
For other operating systems, change the radioCmd variable to any command-line command
that you fancy. You could even add additional commands that are triggered for the other but-
tons or sensors. Perhaps the Max button runs a command that talks to an X-10 controller to
turn on the lights. If you encapsulate these various commands into a shell script (or batch file
on Windows), you can change it all you want without re-exporting the sketch in Processing.
In Chapter 13 you’ll learn how to make Roomba fully autonomous. When fully stand-alone,
having it be an alarm clock would be even more interesting. For example, it could run away
from you as you try to turn off the alarm.
If you use RoombAlarmClock to wake you up, don’t put Roomba on your nightstand table. It
may very well fall off. Roomba is quite sturdy, but why take the chance? Place Roomba on the
floor.

