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

## Examine the BoeBot

1. Check both tires for tread. Ensure that all parts, including power and programming cables, are available.
2. Check that your basic stamp is properly plugged into the circuit board, and that it is oriented the correct way.
3. Determine which end of your robot is the "front" and which is the "back"
4. Plug the two motors into the available plugs for ports 12 and 13. Record which wheel is "12" and which wheel is "13"
5. Ensure that no wires or components, besides the motors, are plugged into the breadboard or any of the other ports.
6. 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):

```MyCount VAR Byte
FOR MyCount = 0 TO 200
PULSOUT 12, 800
PULSOUT 13, 700
PAUSE 20
NEXT
```

Run the program, and answer the following questions:

1. Does the Boe-Bot move forward or backward?
2. Reverse the "700" and "800" numbers in the code above and run it again. Does the robot move in the opposite direction?
3. 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":

```MyCount VAR Byte
Left CON 12
Right CON 13
FOR MyCount = 0 TO 200
PULSOUT Left, 800
PULSOUT Right, 700
PAUSE 20
NEXT
```

Run the program.

1. 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:

```MyCount VAR Byte
Left CON 12
Right CON 13
LeftStop CON 750
RightStop CON 750
FOR MyCount = 0 TO 200
PULSOUT Left, LeftStop
PULSOUT Right, RightStop
PAUSE 20
NEXT
```

Run the program. Follow this proceedure:

1. Do the wheels move? If not, the wheels are calibrated.
2. 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.
3. 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:

```MyCount VAR Byte
Left CON 12
Right CON 13
LeftStop CON 750
RightStop CON 750
FOR MyCount = 0 TO 200
PULSOUT Left, LeftStop + 50
PULSOUT Right, RightStop - 50
PAUSE 20
NEXT
FOR MyCount = 0 TO 200
PULSOUT Left, LeftStop - 50
PULSOUT Right, RightStop + 50
PAUSE 20
NEXT
```

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:

```MyCount VAR Byte
Left CON 12
Right CON 13
LeftStop CON 750
RightStop CON 750
EndLoop1 CON 100
FOR MyCount = 0 TO EndLoop1
PULSOUT Left, LeftStop + 50
PULSOUT Right, RightStop - 50
PAUSE 20
NEXT
```

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:

```MyCount VAR Byte
Left CON 12
Right CON 13
LeftStop CON 750
RightStop CON 750
EndLoop6 CON 100
FOR MyCount = 0 TO EndLoop6
PULSOUT Left, LeftStop + 50
PULSOUT Right, RightStop - 50
PAUSE 20
NEXT
```

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:

```MyCount VAR Byte
Left CON 12
Right CON 13
LeftStop CON 750
RightStop CON 750
EndLoop12 CON 100
FOR MyCount = 0 TO EndLoop12
PULSOUT Left, LeftStop + 50
PULSOUT Right, RightStop - 50
PAUSE 20
NEXT
```

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:

1. Are your values for EndLoop1, EndLoop6, and EndLoop12 related? How do they compare to one another?
2. If you reverse the directions of your PULSOUTs, will your robot move exactly 1 inch, 6 inches, and 12 inches in reverse?
3. 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:

```MyCount VAR Byte
Left CON 12
Right CON 13
LeftStop CON 750
RightStop CON 750
Turn CON 100
FOR MyCount = 0 TO Turn
PULSOUT Left, LeftStop + 50
PULSOUT Right, RightStop + 50
PAUSE 20
NEXT
```

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:

```MyCount VAR Byte
Left CON 12
Right CON 13
LeftStop CON 750
RightStop CON 750
Turn CON 100
FOR MyCount = 0 TO Turn
PULSOUT Left, LeftStop - 50
PULSOUT Right, RightStop - 50
PAUSE 20
NEXT
```

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:

1. Are your two values for "Turn" the same to turn in both directions? If not, are they close?
2. Using the code you have above, along with some Copy + Paste, can you make the robot move in a 180° turn?
3. 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:

```MyCount VAR Byte
Left CON 12
Right CON 13
LeftStop CON 750
RightStop CON 750
Turn CON 100
EndLoop12 CON 100
FOR MyCount = 0 TO EndLoop12
PULSOUT Left, LeftStop + 50
PULSOUT Right, RightStop - 50
PAUSE 20
NEXT
FOR MyCount = 0 TO Turn
PULSOUT Left, LeftStop - 50
PULSOUT Right, RightStop - 50
PAUSE 20
NEXT
FOR MyCount = 0 TO EndLoop12
PULSOUT Left, LeftStop + 50
PULSOUT Right, RightStop - 50
PAUSE 20
NEXT
```

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

1. Write a program to move the robot in a square forwards, and then to retrace that same square backwards.
2. Write a program to move the robot in a figure-8 shape.
3. 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)
4. 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.