Page 121 - Hacking Roomba
P. 121
102 Part I — Interfacing
Listing 5-3 Continued
pause( (int)(pausetime*1000) );
stop();
}
public void spinLeft( int angle ) {
if( angle < 0 ) return;
float pausetime = Math.abs(millimetersPerDegree *
angle/speed);
spinLeftAt( Math.abs(speed) );
pause( (int)(pausetime*1000) );
stop();
}
Pivoting around a particular angle looks like this:
roombacomm.spinLeft(90); // turn anti-clockwise 90 degrees
roombacomm.spinRight(360); // spin totally around
Moving in Curves
The straight motion and pivot turns are sufficient to move around, but arc turns are more effi-
cient when dealing with obstacles. Watch the Roomba while it operates and you’ll notice it
performs three basic types of non-pivot turns (see Figure 5-7):
Small circle: The Roomba moves in a circle with a radius a little bigger than itself. This
is performed when the Roomba bumps against something (usually a table leg) and tries
to drive around it.
Waggle: The Roomba moves forward by moving in alternating arcs with radii larger
than the Roomba. This is performed when the Roomba is searching for something (dirt,
home base, and so on).
Expanding spiral: The Roomba moves in a circle that gets bigger and bigger, accom-
plished by gradually increasing the radius over time. This is performed when the
Roomba thinks it is in a large open area of floor.
The small circle is pretty evident now. You can implement it in RoombaComm with some-
thing like:
roombacomm.drive(200,300); // 250 mm/s, turn left on 300 mm radius
You can test that out with the roombacomm.Drive program.
The waggle is just the same, but with a larger radius, approximately 600, and it switches every
quarter second or so. To emulate it, you could do something in a loop for however long you
want, like Listing 5-4.