Advertisement
Sonikku1980

Project 4 Back and Forth

Mar 30th, 2015
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.93 KB | None | 0 0
  1. /*
  2.     Authors: Esteban, Robert
  3.     Assignment: Project 4  
  4.     Date: 3/25/15
  5.     Description:    Robot drives forwa
  6. */
  7.  
  8.  
  9. import lejos.nxt.*;
  10. import lejos.robotics.navigation.DifferentialPilot;
  11.  
  12.  
  13. public class project4  //make sure the classname matches the filename (case-sensitive)
  14. {
  15.     private DifferentialPilot bot;  //field declaration for a DifferentialPilot object
  16.        
  17.    
  18.     //the code in the main method will not change (except for the classname)
  19.     public static void main(String[] args)
  20.     {
  21.         project4 myProgram = new project4(); //matches classname (case-sensitive)
  22.         myProgram.run();
  23.     }//main()
  24.    
  25.  
  26.     //the constructor generally instantiates field objects and sets other initial state information
  27.     public project4()   //matches classname (case-sensitive)
  28.     {
  29.         bot = new DifferentialPilot(56, 108, Motor.B, Motor.C);  //instantiate a DifferentialPilot object named "bot"
  30.        
  31.     }//constructor
  32.    
  33.    
  34.     //your code goes in this method
  35.     public void run()
  36.     {
  37.         bot.travel(2400); // Travels 800 forward
  38.         bot.rotate(-210); // Turns around
  39.         bot.travel(2400); //Comes back to starting point
  40.     }//run()
  41.    
  42.    
  43.    
  44.    
  45.     //the following method writes a string to the screen. Useful for debugging.
  46.     public void displayString(String msg)
  47.     {
  48.         LCD.clear();
  49.         LCD.drawString(msg, 0, 0);  //writes the msg to the screen
  50.         LCD.refresh();
  51.     }//displayString()
  52.  
  53.  
  54.  
  55.     //the following method writes an int (whole number) to the screen. Useful for debugging.
  56.     public void displayInt(int num)
  57.     {
  58.         LCD.clear();
  59.         LCD.drawInt(num, 4, 0, 0);  //writes the num to the screen
  60.         LCD.refresh();
  61.     } //displayInt
  62.  
  63.    
  64.    
  65.     //the following method allows the bot to do what it was doing, but suspends execution of the
  66.     //next statement. When this method returns, the program continues executing where it left off.
  67.     public void pause(int milli)
  68.     {
  69.         try
  70.         {
  71.             Thread.sleep(milli);
  72.         }//try
  73.         catch(InterruptedException e)
  74.         {
  75.         }//catch
  76.     }//sleep()
  77.    
  78. }//class project4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement