Quick question about Rev through bore encoder

I’m trying to add rev’s through bore encoder to our arm to make it far more reliable. Given that we don’t have the absolute encoder adapter for the spark max, we have the pwm (red, white, black) cable into the roborio’s DIO. Using the DutyCycleEncoder class, I’m using the getAbsolutePosition() method.

The thing is that I get 0-1 values, and when a rotation occurs, the value passes from 1 to 0. Is there any correct way to use the encoder? Or any suggestions?

Thanks!

On 0-1 values: simply multiply the value by 360 to get it in terms of degrees. You will also want to set an offset for what you want your “zero” to be.

On values passing: If using a WPILib PIDController class to control PID, then call controller.enableContinuousInput(-180, 180) (or 0 and 360, whichever you prefer as the range). This will deal with wraparounds.

Ohh, al right. That makes sense. Thanks!!

1 Like

You will also need to keep the offset in your code as the encoder will not store its offset. We have a class to handle the encoder.

IT returns a Rotation2d but you can do degrees or radians or whatever you want.

This is super useful. Thank you!

1 Like

Make sure you are checking isConnected before using the value otherwise if it is disconnected it will return the offset and may cause unexpected motion

1 Like

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