WPILib AnalogEncoder (java)

We have a US Digital MA3 absolute encoder we’re using with the AnalogEncoder class. When we call its get() method, but what is returned isn’t what we expected. When we turn it one full rotation it goes from 0 to 4. With another rotation, it resets back to 1 and goes up to 5. Then it resets to 2 and goes up to 6, and so on. Aside from just treating the encoder as an AnalogInput and calling the getVoltage() method, is there a way to get absolute values from the AnalogEncoder?

Hmm, thats odd. I wonder if some of those encoders need more filtering to happen with the rollover detection. If you don’t need rollover support, and just need the absolute position, you can safely just use the AnalogInput class and call getVoltage(), as that is all that constructs the fractional part of the value anyway.

If you need rollover support, you could copy the WPILib class and try setting some of the Averaged or Filtered settings on the AnalogTrigger. It’s a relatively simple class.

What do you mean by rollover support? Is it something that helps with calculating distance traveled?

AnalogInput’s getVoltage only returns the current position of the sensor. It doesn’t report if the sensor has gone through multiple rotations. Detecting those multiple rotations is called rollover support, as it detects the values rolling over from the maximum voltage to the minimum voltage. That support is handled by the AnalogTrigger object in the AnalogEncoder class. If you only need to detect the position, and not if it has gone through multiple rotations, you can just use AnalogInput directly.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.