# Turning

These custom functions for pivoting or turning the robot use the wheel encoders:

`pivotAngle()`

— pivot on both wheels by specific angle`turnAngle()`

— turn on one wheel by specific angle

## pivotAngle()

A custom function named `pivotAngle()`

uses the wheel encoders to make your robot pivot by a specified angle.

When pivoting, the robot turns in a circle centered between the robot's wheels. The distance between the centers of the RedBot wheel treads is 6.125 inches, which represents the diameter of the robot's pivot circle. If the robot pivoted 360°, the distance traveled by each wheel would be equal to the circumference of this pivot circle:

**C = 𝛑 × d = 3.14 × 6.125 = 19.23 inches**

Usually you will want your RedBot to pivot by a specific angle that is less than 360° — such as 45°, 90°, 180°, etc. For any specific angle, you can calculate its **arc length** (i.e., a "partial circumference"):

**L = 𝛂 / 360° × 𝛑 × d**

The arc length (**L**) represents the distance each wheel will travel while pivoting by a specific angle (𝛂).

For example, when pivoting by 90°, the arc length is:

L = 90° / 360° × 𝛑 × d = 0.25 × 3.14 × 6.125 = 4.81 inches

Once this arc length is calculated for a specific angle, the wheel encoders can be used to control how long the wheels are pivoted. This is what the `pivotAngle()`

function does.

When calling the `pivotAngle()`

function, you must pass in a value for the desired **angle** (degrees) by listing the value inside the parentheses after the function's name.:

A

**positive**angle will pivot the robot**clockwise**to the right.A

**negative**angle will pivot the robot**counter-clockwise**to the left.

For example, to make your robot pivot 90 degrees right:

To make your robot pivot 90 degrees left:

The `pivotAngle()`

function requires these objects as part of your global variables before the `setup()`

function:

Add the `pivotAngle()`

custom function **after** the `loop()`

function:

## turnAngle()

A custom function named `turnAngle()`

uses the wheel encoders to make your robot turn on one wheel by a specified angle.

Turning on one wheel is less tight than pivoting (which has a "zero turn radius"):

When turning on one wheel, the robot turns in a circle centered on the stopped wheel. The distance between the centers of the RedBot wheel treads is 6.125 inches, which represents the radius of the robot's turn circle, so the diameter of this turn circle is 12.25 inches. If the robot turned 360° on one wheel, the distance traveled by the driving wheel would be equal to the circumference of this turn circle:

**C = 𝛑 × d = 3.14 × 12.25 = 38.47 inches**

Usually you will want your RedBot to turn by a specific angle that is less than 360° — such as 45°, 90°, 180°, etc. For any specific angle, you can calculate its **arc length** (i.e., a "partial circumference"):

**L = 𝛂 / 360° × 𝛑 × d**

The arc length (**L**) represents the distance that the driving wheel will travel while turning by that specific angle (𝛂).

For example, when turning on one wheel by 90°, the arc length is:

L = 90° / 360° × 𝛑 × d = 0.25 × 3.14 × 12.25 = 9.62 inches

Once this arc length is calculated for a specific angle, the wheel encoders can be used to control how long the driving wheel travels. This is what the `turnAngle()`

function does.

When calling the `turnAngle()`

function, you must pass in a value for the desired **angle** (degrees) by listing the value inside the parentheses after the function's name.:

A

**positive**angle will turn the robot**clockwise**to the right.A

**negative**angle will turn the robot**counter-clockwise**to the left.

For example, to make your robot turn on one wheel 90 degrees right:

To make your robot turn on one wheel 90 degrees left:

The `turnAngle()`

function requires these objects as part of your global variables before the `setup()`

function:

Add the `turnAngle()`

custom function **after** the `loop()`

function: