Advertisement
Sonikku1980

Untitled

Apr 1st, 2015
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.15 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 project5  //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.         project5 myProgram = new project5(); //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 project5()   //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(1550); //good
  38.         bot.rotate(-110); //good
  39.         bot.travel(1000); //good
  40.         bot.rotate(-150); //good
  41.         bot.travel(1250); //good
  42.         bot.rotate(90); //good
  43.         bot.travel(1100); //good
  44.         bot.rotate(-150); //good
  45.         bot.travel(1000); //good
  46.         bot.rotate(400); //Start Celebration !!!!
  47.         bot.rotate(-400);
  48.         bot.rotate(400);
  49.         bot.rotate(-400);
  50.     }//run()
  51.    
  52.    
  53.    
  54.    
  55.     //the following method writes a string to the screen. Useful for debugging.
  56.     public void displayString(String msg)
  57.     {
  58.         LCD.clear();
  59.         LCD.drawString(msg, 0, 0);  //writes the msg to the screen
  60.         LCD.refresh();
  61.     }//displayString()
  62.  
  63.  
  64.  
  65.     //the following method writes an int (whole number) to the screen. Useful for debugging.
  66.     public void displayInt(int num)
  67.     {
  68.         LCD.clear();
  69.         LCD.drawInt(num, 4, 0, 0);  //writes the num to the screen
  70.         LCD.refresh();
  71.     } //displayInt
  72.  
  73.    
  74.    
  75.     //the following method allows the bot to do what it was doing, but suspends execution of the
  76.     //next statement. When this method returns, the program continues executing where it left off.
  77.     public void pause(int milli)
  78.     {
  79.         try
  80.         {
  81.             Thread.sleep(milli);
  82.         }//try
  83.         catch(InterruptedException e)
  84.         {
  85.         }//catch
  86.     }//sleep()
  87.    
  88. }//class project5
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement