Page 160 - Hacking Roomba
P. 160
Chapter 7 — Making RoombaView 141
Wheeldrop and drive motor over-current state
Dirt sensor state
Battery charge, voltage, and current consumption
ROI mode
To remotely command Roomba, it should have:
Buttons and/or keyboard control to drive the Roomba and various speeds
Buttons to reset the ROI and Roomba to a known state
Buttons to toggle between passive, safe, and full ROI modes
Additionally, RoombaView should know if it’s connected and talking to Roomba or not and
show that state.
Driving Roomba in Real-Time
Processing will call the keyPressed() method in your sketch whenever a user presses a key.
The variables key and keyCode hold the key character pressed and the raw keycode, respec-
tively. If you wanted the arrow keys to move the robot, the spacebar to stop it, and the Return
key to reset it, the keyPressed() method might look like this:
void keyPressed() {
if( key == CODED ) {
if( keyCode == UP )
roombacomm.goForward();
else if( keyCode == DOWN )
roombacomm.goBackward();
else if( keyCode == LEFT )
roombacomm.spinLeft();
else if( keyCode == RIGHT )
roombacomm.spinRight();
}
else if( keyCode == RETURN || keyCode == ENTER ) {
println(“resetting”);
roombacomm.reset();
}
else if( key == ‘ ‘ ) {
roombacomm.stop();
}
Add any other keys to command the Roomba to do whatever you want. Any RoombaComm
command or combination of commands can be added, but be aware of the pause()-related
issues mentioned earlier.
To test for key presses from keys without a character representation like the arrow keys, shift,
enter, and so on, first check for key==CODED and then examine the keyCode.