# Introduction to Robotics/Robotics and BoeBots/Lab/Students

Robotics and BoeBots: Lecture (For Students) (For Teachers) — Lab (For Students) (For Teachers) — Assignment (For Students) (For Teachers) — Quiz (For Students) (For Teachers)

## Examine the BoeBot

* Check both tires for tread. Ensure that all parts, including power and programming cables, are available.
* Check that your basic stamp is properly plugged into the circuit board, and that it is oriented the correct way.
* Determine which end of your robot is the "front" and which is the "back"
* Plug the two motors into the available plugs for ports 12 and 13. Record which wheel is "12" and which wheel is "13"
* Ensure that no wires or components, besides the motors, are plugged into the breadboard or any of the other ports.
* If the Robot has a slide-switch on the top, ensure that it is in the "0" position for programming.

## Basic Moving

Open the Parallax programming environment. Enter the following code (capitalization is not important):
Run the program, and answer the following questions:
* Does the Boe-Bot move forward or backward?
* Reverse the "700" and "800" numbers in the code above and run it again. Does the robot move in the opposite direction?
* Does the robot move in a straight line, or does it curve to the left or right?

## Orientation

We are going to define two constants for the port values. Write the following code into your program. Depending on which ports your motors are plugged into, you may need to change the values for "Left" and "Right":
Run the program.
* Does the robot do the same thing as the code above?
Record the values for "Left" and "Right" for later use.

## Motors and Calibration

The motors operate according to the following PULSEOUT values:

### 650

    Full-speed counter-clockwise

### 750

    Stopped

### 850

    Full-speed clockwise
However, these values might be a little different for each robot, and so we need to calibrate them. Write the following code:
Run the program. Follow this proceedure:
* Do the wheels move? If not, the wheels are calibrated.
* Adjust the values for "LeftStop" and "RightStop", depending on which direction the wheels are moving. For instance, if the left wheel is slowly moving counter-clockwise, you would want to increase the value for LeftStop. If the wheels get faster, you are changing the number in the wrong direction.
* Run the program again. Go to #1
Continue playing with the numbers until the wheels do not move. Record the values for "LeftStop" and "RightStop" for future use. Demonstrate to your instructor that the BoeBot is properly calibrated by running the code above.

## Calibration Testing

Using your values for "Left", "Right", "LeftStop", and "RightStop" that you found above, write the following program. Remember to use your values for these constants, and not the values that are written here:
Run the program. What does this code do?
Because the wheels are on opposite sides of the robot, we need to turn them in opposite directions if we want to move in a straight line. To move forward, we want to turn the wheel on the left clockwise, and the wheel on the right counter-clockwise. To move backward, we do the reverse. Demonstrate to your instructor that you can move the BoeBot forward and backward in a straight line. Sometimes a line won't be perfectly straight. This is normal.

## Distances

We are going to define several new constants, so that we can make the boebot move certain distances. Write the following code:
Run the program. You want to change the value of "EndLoop1" so that the BoeBot travels exactly 1 inch forward. Record the value of "EndLoop1" for future use. Modify the code to say:
Run the program. Now, modify the value of "EndLoop6" so that the BoeBot travels exactly 6 inches forward. Record the value of "EndLoop6" for future use. Modify the code to say:
Run the program. Now, modify the value of "EndLoop12" so that the BoeBot travels exactly 12 inches forward. Record the value of "EndLoop12" for future use.
Demonstrate to your instructor that your robot can move exactly 1 inch, 6 inches, and 12 inches.
Questions:
* Are your values for EndLoop1, EndLoop6, and EndLoop12 related? How do they compare to one another?
* If you reverse the directions of your PULSOUTs, will your robot move exactly 1 inch, 6 inches, and 12 inches in reverse?
* Using the code that you already have with Copy + Paste, can you write a program to make the robot move exactly 11 inches? 20 inches? 25 inches?

## Turning

To make the robot move in a straight line, we need to turn the wheels at the same speed in opposite directions. To make the robot turn on an angle, we can do one of the following:
* Stop one wheel, and turn the other wheel forward.
* Turn one wheel forward, and the other wheel backward.
Write the following code:
Run the program. Modify the value of "Turn" so that the robot turns exactly 90° Record the value of "Turn", and record the direction that the BoeBot turns for future use. Now, re-write the code to say the following:
Run the program. The BoeBot should turn in the opposite direction. Modify the value of "Turn" so that the robot turns exactly 90°. Record the value for "Turn" and the direction that it turned for future use.
Demonstrate to your professor that you can make your robot turn both left and right at 90° angles.
Questions:
* Are your two values for "Turn" the same to turn in both directions? If not, are they close?
* Using the code you have above, along with some Copy + Paste, can you make the robot move in a 180° turn?
* Using the code you have above, along with some Copy + Paste, can you make the robot move in a 360° (full revolution) turn?

## Putting it All Together

Write the following code. See if you can figure out what it does before you run it:
Run the Program. What does this do? Using this code above, and some Copy + Paste, can you make the robot travel in a perfect square? Demonstrate your square to your instructor.

## Bonus Problems
### Easy Problems

* Write a program to move the robot in a square forwards, and then to retrace that same square backwards.
* Write a program to move the robot in a figure-8 shape.
* Write a program to make the robot pace back and forth over a line (move forward, do a 180° turn, move in the other direction)
* Write a program to make your robot move forward, turn 180°, move backwards (which will be the same direction), turn 180° again, and then continue to move forward. The robot should move in one direction, but do part of the trip backwards.
Demonstrate each to your instructor.

### Difficult Problems

* Figure out how to turn your robot on a 45° angle. Use this technique along with code you have already written, to move your robot in an octagon.
* Figure out how to turn your robot on a 60° angle. Use this technique along with code you have already written, to move your robot in an equilateral triangle.
* Using the 60° turn you figured out above, teach your robot how to make a 3-point turn, like in a regular car.

## Questions

* Why do we use the FOR / NEXT loops? Do loops make the program harder or easier? Are loops important?
* What are the benefits to using constant (CON) values in your program? Are there any problems to using them?