Encoder calculations

We are using a CTRE SRX Mag encoder that has 1024 clicks per rotation. We have taken the number of clicks divided by the circumference of our wheel to get clicks per inch. Then we are taking it times a gear ratio but are not getting the robot to drive the correct distance. Our encoder is mounted on the outside of two gears that have a gear ratio of 3 to 1 and then the shaft goes to two output gears that have a gear ratio of 9 to 5 so we are using a compound gear ratio of 3×1.8 to get 5.4 but when we use this gear ratio in our calculation we’re not getting a correct driving distance. Given the way that we are doing our calculations it’s more like the gear ratio ends up being 1 to 21 in order to get the correct driving distance. Any ideas?

Most likely, you’re off by a factor of 4. The CTRE mag encoders are 1024 cycles per revolution, which is 4096 edges per revolution. When using 4x decoding (as is done on the Talon SRX, or can be done with the WPILib encoder object), you count edges rather than cycles.

1 Like

While they both do 4x decoding WPILIB normalizes for cycles, Talon SRX does not. WPILIB will count from 0-1023 in 0.25 increments.

OK but if we increase our numerator 4 times and we decrease our denominator by four so that our gear ratio is 1 to 5.4 and clicks is 4096 that will put us off by a factor of 16 instead of four. I’m just helping with the math I don’t do the actual programming.

Why would you both increase the numerator and decrease the denominator?

You note that your actual gear ratio is 5.4:1, but your numbers make it look like 21:1. As 21/5.4 is very nearly 4, this strongly suggests that you are counting 4 times as many edges as you think you are, which is a very likely mistake due to the way quadrature encoders work.

When we were using 1024 clicks and 21.6 (coincidence that it was off by a factor of 4)for a gear ratio we coincidentally ended up with the correct driving distance. But when we changed the clicks to 4096 that’s changing it by factor of four and when we put in our actual gear ratio of 1 to 5.4 that change that also by a factor of four the opposite direction.

OK sorry we’re looking like idiots. Our programmer who does all this is very sick and is unable to help so we’re trying to jump in and help. We originally had 1024 clicks divided by approximately 18.84 circumference and then we took that times gear ratio of 1/21.6 ( A wrong gear ratio which was coincidentally four times what it really is )That gives us a scale factor of about 2.517

With the changes now we have 4096 divided by our circumference of approximately 18.84 times scale factor of 1 to 5.4 which gives us about 40.274

So now are scaling factor of 40.274 is 16 times more than our original number of 2.517 and it actually worked with 2.517 we just know that the gear ratio that we put in of 1:21.6 was not correct.