moveForward

//Moves forward a certain distance (inch) at the given speed (percent). Negative PERCENT = backwards
void moveForward(int percent, float distance)
{

if(percent > 0) {
 rightMotor.SetPercent(12);
 leftMotor.SetPercent(12);
} else {
  rightMotor.SetPercent(-12);
  leftMotor.SetPercent(-12);
}

Sleep(100);

//Set both motors to desired percent
rightMotor.SetPercent(percent);
leftMotor.SetPercent(percent);

//Sleep until the distance is reached
Sleep(MOVE_ADJUST2 * distance / abs(percent) - 0.1);

rightMotor.Stop();
leftMotor.Stop();

return;
}

Algorithm for moveForward:

  1. Set motor percents to desired value.
  2. Sleep until provided distance is reached.
  3. Turn off motors.
  4. End function.