//Turns to a certain angle. Negative = left void turnRight(float angle) { //Figure out what direction to turn, set motors if(angle < 0) { LCD.WriteLine("I'm turning left!"); rightMotor.SetPercent(OUTSIDE_TURN_POWER); leftMotor.SetPercent(INSIDE_TURN_POWER); Sleep(100); rightMotor.SetPercent(FAST_OUTSIDE); leftMotor.SetPercent(FAST_INSIDE); } else { LCD.WriteLine("Turning right!"); rightMotor.SetPercent(FAST_INSIDE); leftMotor.SetPercent(FAST_OUTSIDE); } //Turn based on the angle desired Sleep(abs(angle) / TURN_ADJUST); rightMotor.Stop(); leftMotor.Stop(); return; }
Algorithm for turnRight:
- If angle is less than 0, proceed to step 2, otherwise proceed to step 6.
- Output that the robot is turning left.
- Set the right motor to the outside turn power, and the left motor to the inside turn power.
- Pause.
- Set the right and left motor percents to fast. Proceed to step 8.
- Output that the robot is turning right.
- Set the right motor to fast inside, and the left motor to fast outside.
- Turn based off of the desired angle.
- Stop the left and right motors.
- End function.