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?
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.
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