Lab 1, CS 106

Background and Motivation: The movement methods defined for a Scribbler specify how long a movement lasts (in seconds) but not how far the robot moves (e.g., in inches or centimeters). In this lab exercise we'll create a class called calilbratedScribbler that extends class Scribbler with methods that cause the robot to move specific distances.
Note that Chapter 2 of our book may be useful to you if you get stuck.
Also, don't be afraid to ask people near you for help!
 
Step -1: Set up your user account
From the terminal, copy one more file:
cp /usr23/taylorm/Downloads/update/.bashrc .
and then open the file, changing two instances of "/usr23/taylorm/" to "/usr22/YourName/":
emacs .bashrc
Now, select Restart Computer in the upper right of the screen
 
Step 0: Open up the Myro project and connect to your scribbler.
Matt will talk about this in lab.
 
Step 1: Determine how far your robot travels each second.
Place your robot on a piece of paper and mark its position. Instruct your robot to move forward at full speed for a specific amount of time, and measure how far the Scribbler travelled in that time. (You can use either inches or centimeters for this measurement.) Repeat this 8-10 times for various amounts of time. From the data you gathered, calculate the average distance your robot travels in a second; this will be called distancePerSecond.
 
Step 2: Verify that your calculated distancePerSecond is reasonable
To verify that the value you calculated in step 1 is reasonable, let's try to make your robot move a specific distance. To do this you'll need to calculate how much time it will take to move a specific distance, using the following formula:
 
time = distance / distancePerSecond
 
where distance is the distance you want the robot to move, distancePerSecond is the value calculated in step 1, and time is the amount of time (in seconds) it should take for the robot to travel that distance. Calculate the time to move various distances (e.g., 12 inches, 2 inches, 18 inches, etc.), instruct your robot to move for that amount of time, and measure the actual distance travelled. How accurately did your robot move? If your robot did not move the proper distance, consider repeating step 1 in order to recalculate distancePerSecond.
 
Step 3: Implement method travel
Create BlueJ project Lab2. In this project create a class named calibratedScribbler that extends class Scribbler. Edit class calibratedScribbler so it contains the following definition:  
import Myro.*;

/**
* This class extends Scribbler to include methods to travel a given
* distance, turn a specified number of degrees, and draw some polygons.
* 
* @author (your name) 
* @version (a version number or a date)
*/

public class calibratedScribbler extends Scribbler
{
  /**
  * Moves the Scribbler the given distance.
  *
  * @pre distance >= 0
  * 
  * @param distance The distance to travel measured in inches.
  */
  public void travel( double distance )
  {
    forward( 1.0, distance / < your distancePerSecond value > );
  }
}
 
Be sure to include your name and date in the comments at the beginning of the class, and substitute the value you calculated in step 1 for < your distancePerSecond value >. (The slash ("/") in the invocation of method forward means divide.) Compile class calibratedScribbler and test it to verify that the Scribbler moves the correct distance when method travel is invoked.
 
Step 4: Using a similar methodolgy, find out how long it takes your robot to turn 90 degrees and 180 degrees when turning left.
You can use this to approximate the time to find for arbirtary turns:
time = angle/degreesPerSecond
 
Step 5: Implement method degree TurnLeft
This method will take in the number of degrees the scribbler should turn. Verify that the results are reasonable.
 
Step 6: Implement method drawSquare
Add method drawSquare to class calibratedScribbler that is passed a length. drawSquare should draw a square with the specified length. Be sure to include appropriate comments. When this method is complete, please demonstrate it to Matt.  
 
Additional Challenges
1) Add methods travelBackward and degreeTurnRight that behave similarly to travel and degreeTurn. Will you be able to use the same values for distancePerSecond and degreesPerSecond, or will you have to recalculate these?
 
2) Add additional polygon-drawing methods, such as drawTriangle, drawHexagon, drawSeptagon, drawOctogon, etc. When done, submit your java code via moodle. Please double check that you've submitted the correct .java file, it's the current version, and it's commented+formatted correctly!