Turning with Encoders

Here is how to properly turn a standard VEX tank chassis, with a quadrature encoder mounted on each side. If you have two encoders, you should incorporate the information from both in your turning code. For example, say you measure manually that by keeping the right wheel fixed and moving the left wheel forward, the robot turns 90 degrees right in 1000 ticks of the left encoder.

Instead of turning right using code like this:

//zero encoders
//motors on
while(left encoder < 1000)  { }
//motors off

Use this instead:

//zero encoders
//motors on
while(left encoder - right encoder < 1000) { }  //the right encoder will count backwards during a right turn
//motors off

Notice that due to geometry, this code will turn the same amount even if the left and right motors are turning at different speeds:

Diagram demonstrating independence of encoder measurement (green) and center of turn. The robot turns 90 degrees as long as the wheels travel the required signed distance

 So this works for spins, turns, and everything in between.
Going forward with encoders should use similar code, except change the condition to something like: while(left encoder + right encoder < dist * 2) { }