Going Straight
Most programming languages provide for a function that synchronizes the two wheels so that they move together at the exact same speed for the same duration (time, rotations, degrees). In NXT-G, this is called the Move Block (see image below). In RobotC this function is implemented by setting the
nSyncedMotors variable to indicate how the motors are to be synched:
synchBC,
synchCB,
synchNone.
The challenge in going straight is knowing when to stop (i.e., how far to go).
What if you wanted the robot to travel 24 inches? How many times does each wheel have to rotate?
What if you wanted the robot to travel for 18 inches? How many times does each wheel have to rotate?
There are a couple of ways you could determine how many rotations of the wheel is needed:
- View Mode The NXT Brick supports a "View Mode" which lets you move (push) the robot and the rotations would be shown on the LCD screen.
- Trial and Error You could enter different values for the motor to turn until you found the value that makes the robot do what you wanted it to do.
- Math (Multiplication/Division) Place a mark on one spot on the wheel and then put that wheel on a ruler with the mark set at the beginning of the ruler. Then roll the wheel one rotation down the ruler. How far does the wheel travel with one rotation? Once you know how far the wheel travels with one rotation, then you can divide the total distance you want to travel by the distance travelled by one rotation of the wheel. This will tell you how many rotations you need the wheel to make in order to travel the longer distance.
- Simple Algebra/Geometry Each wheel has a specific diameter. This diameter is shown in millimeters on the side of the tire (see image). Multiply the diameter by PI (3.14159) to get the circumference of the wheel. Now divide the distance you want to travel by the circumference of the wheel. This will give you the number of rotations you need the wheel to turn. Remember, the wheel's diameter is shown in millimeters. So, you may need to convert that to inches. Or, measure the distance you need to travel in millimeters instead of inches.
- Programming with Algebra/Geometry As you can see from the Algebra/Geometry method, there are a number of calculations you need to make: multiplying by PI, dividing the distance to travel by the circumference of the wheel, converting millimeters to inches and inches to millimeters. These calculations can be made easier with the help from some Programming. This method takes advantage of the power of computer programs to simplify your tasks. In this method, a small program (subroutine, MyBlock, function) would convert a desired degree of rotation for the robot into specific rotations of the motors.
You can determine the number of degrees to turn using simple Algebra. Divide circumference of the wheel into the distance to be travelled and multiple by 360 degrees. This will tell you how many degrees the wheel has to turn in order to travel that distance.