# Using shaft encoders as a gyroscope

I’m trying to use two tracking wheels instead of a gyroscope, but haven’t been able to figure out how to convert their measurements into the robots heading. I have all of the necessary constants but I just don’t know what equation I need to use.

void encoderGyro() {
double circumference = 40.8407045; // a 360 turn is equal to 40.8407045 inches of travel (distance between tracking wheels * Pi)
double trackerRotation = 8.639379797; // each 360 rotation of the encoder is 8.639379797 inches (diameter of tracking wheel * Pi)
double encoderTick = 0.02399827721; // 1 degree of shaft encoder rotation is 0.02399827721 inches (trackerRotation/360)
double gyroDegree = 0.1134464014; // 1 degree of turning is 0.1134464014 inches (circumference/360)
double ticksPer360 = 1701.818182; // a measure of 1701.818182 degrees is a 360 degree turn (circumference/encdoerTick)
double ticksPerDegree = 4.727272729; // 4.727272729 ticks is equal to 1 degree (ticksPer360/360)
int ltrack = leftTrack.get_value();
int rtrack = rightTrack.get_value();
double lDistance = ltrack *0.02399827721;
double rDistance = rtrack *0.02399827721;

double rightDegree = rtrackticksPerDegree;
double leftDegree = ltrack
ticksPerDegree;
double gyroValue = ???;
lcd::set_text(5,std::to_string(gyroValue));
}

The Pilons odometry document is a great resource for this:
pilons-position-tracking.pdf (437.5 KB)

5 Likes

Thanks man I got it working using 5225As document. I’ve looked at it before but had completely forgotten about the absolute orientation equation.

2 Likes