# Measure distance using encoders - zumo 32u4

Hi Folks

So I am a complete newbie to robotics and just got the assembled Zumo 32u4 (https://www.pololu.com/product/3125) recently with 50:1 microgears (51.45). I think the microgears used in the assembly is the ones in https://www.pololu.com/product/3039.

I am trying to see how I can calculate the distance using encoders.

is the below correct ?

Distance traveled = (# of counts) * Wheel rotations * circumference

where:
.# of counts - is retrieved from calling the getCountsAndResetLeft from the encoder (https://pololu.github.io/zumo-32u4-arduino-library/class_zumo32_u4_encoders.html).

circumference: I think the sprocket’s diameter is 35 mm in diameter (https://www.pololu.com/file/0J1360/sprocket-set-for-zumo-chassis-dimensions.pdf), so
circumference = pi * diameter
= pi * 35mm
= 109.95574287

wheel rotations = (Degrees turned / 360)
= (Encoder ticks / 360)
= 51.45* 12 / 360
= 1.715 counts / revolution
This is from where there is a set number of pulses that the encoders shoot out every revolution. According to the manual (pg 14 in http://www.zigobot.com/images/stories/Produit/Z3125_Zumo-32u4-robot-kit/zumo_32u4_robot.pdf), I should multiply 12 * 51.45 = 617.4 Counts per revolution.

So:

Distance traveled = (# of counts) * Wheel Rotations * circumference
Distance traveled = (# of counts) * (Encoder ticks / 360) * circumference
Distance traveled = (# of counts) * (Encoder ticks / 360) * pi * diameter
Distance traveled = (# of counts) * 1.715 * pi * 35mm
Distance traveled = (# of counts) * 1.715 * pi * 35mm
Distance traveled = (# of counts) * 188.574 099mm
.# of counts = Distance traveled / 188.574 099mm

Is the above correct ?

Thanks

Toqeer

I think I figured it out:

My formula was wrong !

The manual gives us CPR (count per revolution) as 51.45 *12 = 617.40 CPR

The formula is really:

General formula:
Distance traveled = Wheel rotations * circumference
= (encoder ticks / 360) * circumference

For our case:
Distance traveled = Wheel rotations * circumference
= (encoder ticks / 617.40 CPR) * circumference
= (encoder ticks / 617.40 CPR) * pi * 35
Distance traveled = encoder ticks / 0.178094822

Example:
I know its about 1400 ticks for about 10 inches (I tried it my zumo):
Distance traveled = 1400 / 0.178094822
= 249.3328 ~ 9.8 inches

Please let me know if I made a mistake somewhere, but I think I got it now.

Thanks Folks

Toqeer

Hello.

Your updated process looks good for the most part. It looks like your general formula still has an error; instead of encoder ticks divided by 360, it should be encoder tics divided by the counts per revolution:

Distance traveled = Wheel rotations * circumference = (encoder ticks / counts per revolution) * circumference

Also, you are using the sprocket diameter, but the track adds a little bit to the total diameter. Including the track, the diameter is approximately 39mm.

- Patrick