Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Authors: Esteban, Robert
- Assignment: Project 4
- Date: 3/25/15
- Description: Robot drives forwa
- */
- import lejos.nxt.*;
- import lejos.robotics.navigation.DifferentialPilot;
- public class project4 //make sure the classname matches the filename (case-sensitive)
- {
- private DifferentialPilot bot; //field declaration for a DifferentialPilot object
- //the code in the main method will not change (except for the classname)
- public static void main(String[] args)
- {
- project4 myProgram = new project4(); //matches classname (case-sensitive)
- myProgram.run();
- }//main()
- //the constructor generally instantiates field objects and sets other initial state information
- public project4() //matches classname (case-sensitive)
- {
- bot = new DifferentialPilot(56, 108, Motor.B, Motor.C); //instantiate a DifferentialPilot object named "bot"
- }//constructor
- //your code goes in this method
- public void run()
- {
- bot.travel(2400); // Travels 800 forward
- bot.rotate(-210); // Turns around
- bot.travel(2400); //Comes back to starting point
- }//run()
- //the following method writes a string to the screen. Useful for debugging.
- public void displayString(String msg)
- {
- LCD.clear();
- LCD.drawString(msg, 0, 0); //writes the msg to the screen
- LCD.refresh();
- }//displayString()
- //the following method writes an int (whole number) to the screen. Useful for debugging.
- public void displayInt(int num)
- {
- LCD.clear();
- LCD.drawInt(num, 4, 0, 0); //writes the num to the screen
- LCD.refresh();
- } //displayInt
- //the following method allows the bot to do what it was doing, but suspends execution of the
- //next statement. When this method returns, the program continues executing where it left off.
- public void pause(int milli)
- {
- try
- {
- Thread.sleep(milli);
- }//try
- catch(InterruptedException e)
- {
- }//catch
- }//sleep()
- }//class project4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement