Roomba Program 1

From GICLWiki
(Difference between revisions)
Jump to: navigation, search
 
Line 1: Line 1:
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Program: ROOMBA_TEMPLATE
+
    // 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 -{[[<<<<))"
+
    // 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...
+
    //              - As a Disclaimer, this loops much more complicated than it is...
//
+
    //
// Drexelized By: Peter Thai - [pwt23@drexel.edu]
+
    // Drexelized By: Peter Thai - [pwt23@drexel.edu]
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
+
   
// This imports the libraries necessary for communicating with Roomba (namely RoomabComm)
+
    // This imports the libraries necessary for communicating with Roomba (namely RoomabComm)
 
     import roombacomm.*;
 
     import roombacomm.*;
 
     import roombacomm.net.*;
 
     import roombacomm.net.*;
 
+
   
 
+
   
//This stops Roomba and disconnects it from your computer.
+
    //This stops Roomba and disconnects it from your computer.
    String roombacommPort = "COM3"; // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<::::::::::::: ENTER YOUR ROOMBA PORT :::::::::::::
+
        String roombacommPort = "COM3"; // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<::::::::::::: ENTER YOUR ROOMBA PORT :::::::::::::
 
     //String roombacommPort = "/dev/cu.RooTooth-COM0-1";
 
     //String roombacommPort = "/dev/cu.RooTooth-COM0-1";
 
     boolean hwhandshake = false;  
 
     boolean hwhandshake = false;  
 
     RoombaCommSerial roombacomm = new RoombaCommSerial();
 
     RoombaCommSerial roombacomm = new RoombaCommSerial();
 
     roombacomm.waitForDSR = hwhandshake;
 
     roombacomm.waitForDSR = hwhandshake;
 
 
      
 
      
// If Roomba fails to connect, it will print out an error and terminate the program  
+
       
 +
    // If Roomba fails to connect, it will print out an error and terminate the program  
 
     if ( ! roombacomm.connect(roombacommPort) )
 
     if ( ! roombacomm.connect(roombacommPort) )
 
         {
 
         {
Line 26: Line 26:
 
             System.exit(1);   
 
             System.exit(1);   
 
         }
 
         }
 
+
   
 
+
   
// Once Roomba is connected, it will perform the following actions to indicate it has connected
+
    // 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
 
     println("Roomba startup on port"+roombacommPort); // Prints out the Port on which Roomba is connected
 
     roombacomm.startup();
 
     roombacomm.startup();
Line 37: Line 37:
 
      
 
      
 
      
 
      
// This is the main loop. It is executed continuously until the variable 'done' is set to true
+
    // 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
 
     boolean done = false; // This instantiates the variable 'done' and sets it to false
 
     while (!done)  
 
     while (!done)  
 
         {
 
         {
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
                ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
             // ::::::::::::: START CODE (Code goes between this thing and.... *look down*) :::::::::::::
 
             // ::::::::::::: START CODE (Code goes between this thing and.... *look down*) :::::::::::::
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
                ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
              
 
              
 
             // **WALL FINDING**  
 
             // **WALL FINDING**  
Line 50: Line 50:
 
             // - When it hits left bump sensor, it turn 45 degrees right, and vice versa  
 
             // - 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   
 
             // - When it finds a wall, it exits loop, and code can be implemented afterwards for another behavior   
 
+
   
 
             while( ! roombacomm.wall())       
 
             while( ! roombacomm.wall())       
 
                 {           
 
                 {           
 
                    
 
                    
 
                     roombacomm.goForward();
 
                     roombacomm.goForward();
 
+
   
 
                     if (roombacomm.bumpLeft())             
 
                     if (roombacomm.bumpLeft())             
 
                         {                 
 
                         {                 
Line 66: Line 66:
 
                     roombacomm.updateSensors();     
 
                     roombacomm.updateSensors();     
 
                 }   
 
                 }   
 
+
   
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
                ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            // ::::::::::::: END CODE (Code goes between this thing and... *look up*) :::::::::::::
+
                // ::::::::::::: END CODE (Code goes between this thing and... *look up*) :::::::::::::
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
                ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
         }
 
         }
 
+
   
   
+
       
//This stops Roomba and disconnects it from your computer.
+
    //This stops Roomba and disconnects it from your computer.
 
     roombacomm.stop();  
 
     roombacomm.stop();  
 
     roombacomm.disconnect();
 
     roombacomm.disconnect();

Revision as of 13:45, 1 February 2007

   ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
   // 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