Roomba Program 1
From GICLWiki
(Difference between revisions)
| Line 1: | Line 1: | ||
This program is a basic autonomous behavior for Roomba and can be used as a starting place. Where you should be looking in this sample code is the "ROOMBA PORT" | This program is a basic autonomous behavior for Roomba and can be used as a starting place. Where you should be looking in this sample code is the "ROOMBA PORT" | ||
| + | |||
| + | The source file can be found here: http://gicl.cs.drexel.edu/wiki-data/images/0/03/ROOMBA_PROGRAM_1.zip | ||
| + | |||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
Revision as of 10:58, 5 February 2007
This program is a basic autonomous behavior for Roomba and can be used as a starting place. Where you should be looking in this sample code is the "ROOMBA PORT"
The source file can be found here: http://gicl.cs.drexel.edu/wiki-data/images/0/03/ROOMBA_PROGRAM_1.zip
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Program: ROOMBA_TEMPLATE
// Description: - This a template for any Roomba program. In order to use this, simple place code in the 'while' loop in place of "// ((>>>>]]}- PLACE CODE HERE -{[[<<<<))"
// - As a Disclaimer, this loops much more complicated than it is...
//
// Drexelized By: Peter Thai - [pwt23@drexel.edu]
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// This imports the libraries necessary for communicating with Roomba (namely RoomabComm)
import roombacomm.*;
import roombacomm.net.*;
//This stops Roomba and disconnects it from your computer.
String roombacommPort = "COM3"; // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<::::::::::::: ENTER YOUR ROOMBA PORT :::::::::::::
//String roombacommPort = "/dev/cu.RooTooth-COM0-1";
boolean hwhandshake = false;
RoombaCommSerial roombacomm = new RoombaCommSerial();
roombacomm.waitForDSR = hwhandshake;
// If Roomba fails to connect, it will print out an error and terminate the program
if ( ! roombacomm.connect(roombacommPort) )
{
println("Couldn't connect to "+roombacommPort);
System.exit(1);
}
// Once Roomba is connected, it will perform the following actions to indicate it has connected
println("Roomba startup on port"+roombacommPort); // Prints out the Port on which Roomba is connected
roombacomm.startup();
roombacomm.control(); // Puts Roomba in "Safe Mode"
roombacomm.playNote(72,50); // Plays a note
roombacomm.pause(100); // Pauses Roomba while note is being played
roombacomm.updateSensors(); // Updates the state of all sensors
// This is the main loop. It is executed continuously until the variable 'done' is set to true
boolean done = false; // This instantiates the variable 'done' and sets it to false
while (!done)
{
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// ::::::::::::: START CODE (Code goes between this thing and.... *look down*) :::::::::::::
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
roombacomm.goForward();
roombacomm.pause(200);
roombacomm.updateSensors();
if (roombacomm.bumpLeft())
{
roombacomm.spinRight(45);
}
else if (roombacomm.bumpRight())
{
roombacomm.spinLeft(45);
}
roombacomm.updateSensors();
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// ::::::::::::: END CODE (Code goes between this thing and... *look up*) :::::::::::::
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
}
//This stops Roomba and disconnects it from your computer.
roombacomm.stop();
roombacomm.disconnect();