We will use encoder measurements to make precise turns in degrees. Once again we will use circumference but this time it is the circumference of the turning circle of the robot.
First we need to measure the turning circle of the tobot and save that in a global variable. the mesurement is the distance between the two wheels measured at the center. mak a global varialbe Rd.
float Rd = 13.6; //Robot diameter
Change the 13.6 to whatever you measure on your robot.
With this variable we can calculate how far the wheel will go for a set number of degrees around the circle.
360 degrees = Pi*Rd inches
so any angle in degrees that we may call target requires the wheels to roll:
targetPiRd/360 inches
Recall that the number of inches the robot has moved from our inchdrive function is:
inches = LF.position(rev)PiD; // where D is the wheel diameter in inches.
So the position in degrees around the circle is:
deg = LF.position(rev)(D360)/Rd;
The Pi in the numerator cancels with the Pi in the denominator .
The process is first set all the variables and reset our encoder to zero then:
Turn the robot a small amount
Measure and calculate the degrees turned
Calculate the error