Page 173 - Hacking Roomba
P. 173
154 Part II — Fun Things to Do
Drive Motors
When driving the motors at normal speeds, a subtle digital mewling (for lack of a better term;
it’s a very indescribable sound) can be heard from them. When the motors are driven at very
slow speeds, this mewling is much more pronounced and creepier. It’s a great sound to have as
another percussive noise for any compositions.
ROI SONG and PLAY Commands
To play musical tones on the beeper, you first define a song and then play it. Roomba has no
mechanism to play a single note. Several songs can be defined and stored in the Roomba’s
memory. Once a song is stored, it can be played on demand.
SONG Command
The SONG command defines a song of up to 16 notes. It is the most complex command in
the ROI. The number of notes in the song determines the length of the command. After the
command header, notes are specified as a list of (note number,duration) pairs. The dura-
tion is in units of 1/64th of a second. Sixteen songs may be stored in Roomba.
The note number is the same as MIDI note numbers. In MIDI, a 12-note octave starts at C
and continues up to B. There are ten octaves, and notes are given names to designate which
note and octave they are. Thus, the note name A4 means the A musical note in octave four, and
C7 means the C note in octave seven. Figure 8-3 shows this arrangement for three common
octaves.To convert a note name to a note number requires a little math.The note letter becomes
a number offset with an octave, numbered between 0 and 11 (C = 0, C# = 1, D = 2, and so on).
The octave number indicates how many octaves’ worth of notes to add to the note offset. In
MIDI, notes start at C-1, an octave below the lowest in a piano (-1 is a negative 1). In general,
to convert a note name to MIDI note number, the equation is:
note number = note offset + ((octave+1) × 12)
To convert the standard note name A4 to a MIDI note number, you use 9 + ((4+1) × 12) = 69.
The lowest note that the Roomba can produce is G1 with a note number of 31 (7 + ((1+1) ×
12). The highest note Roomba can produce is G9 with a note number of 127 (7 + (9+1) × 12).
To Roomba, numbers below 31 are treated as rests (pauses) where no sound is made for the
duration of the note.
MIDI will be covered more in the “RoombaMidi: Roomba as Roomba MIDI” section later in
this chapter. MIDI is a standard that’s been around for over 20 years. It was created by a
bunch of nerdy musicians looking for a way to hook their synthesizers together. You can find
a lot information about MIDI online, including the Harmony Central tutorial at www
.harmony-central.com/MIDI/Doc/tutorial.html. Ricci Adams’ Musictheory.net
(www.musictheory.net/) has a wonderful set of step-by-step interactive notation and
music theory lessons that are fun and quick.