Roomba Program 1

From GICLWiki
Revision as of 13:36, 1 February 2007 by Pwt23 (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // 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*) :::::::::::::
           ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
           
           // **WALL FINDING** 
           // - Simple loop that reiterates until it sees a wall
           // - Roomba "waggles" forward
           // - When it hits left bump sensor, it turn 45 degrees right, and vice versa 
           // - When it finds a wall, it exits loop, and code can be implemented afterwards for another behavior   
           while( ! roombacomm.wall())       
               {          
                  
                   roombacomm.goForward();
                   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();
Personal tools