//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:
- Set motor percents to desired value.
- Sleep until provided distance is reached.
- Turn off motors.
- End function.