FIRST Robotics Competition Discussions

Showing results for 
Search instead for 
Did you mean: 

Problems reading Shaft Encoder's rate

We have a shaft encoder installed on a motor and we are trying to read its rate.

We output a constant value to the controller, yet we read different values as the Encoder vi get output. The difference can be up to 40% of the value (e.g., we read 7812 and 5555 for the same motor setting, the read was timed every 30msec).

Any idea what our problem is?

0 Kudos
Message 1 of 5

It could be a wiring problem or a code problem.

To help decide where the problem lies, I'd suggest using the built-in test examples to see if that code can read your encoder properly.

Go to Getting Started -> Support ->Find FRC examples...

Look under Sensors for Encoder.lvproj

The front panel of that shows the proper wiring.

Then, change the IP of the example on the Project Explorer window to match your team IP by right-clicking on RT CompactRIO Target( and choosing Properties from the popup menu. Then enter the proper IP address, e.g.,

Now you can just run the example using the run arrow and watch the encoder feedback on the front panel as you spin the encoder.

If the code doesn't work, then you have a wiring problem.

If the code does work, then your original code has a code problem.

Message 2 of 5

I definitely should have thought of that myself

Anyway, using the Motor with Encoder example we found out the problem is not with our code, as the example behaves the same (we reduced the error between the encoder's rate reads to about 15% by configuring it to average 20 samples, an option we missed with out own code).

Our hardware also seems to be OK, as our electronics team tested the encoder output signal using an osciloscope and found it to be of a stable rate.

0 Kudos
Message 3 of 5

Just to close this issue - the hardware was re-checked and found to be at fault.

Thanks again.

0 Kudos
Message 4 of 5

Thank you for the closure

0 Kudos
Message 5 of 5