I am trying to get the rotation of a swerve drive wheel using an srx mag encoder and the DutyCycleEncoder class on wpilib. When I display the values in smartdashboard they don’t appear to be changing by much. Why is this?
SwerveModule.java (3.9 KB)
I am trying to get the rotation of a swerve drive wheel using an srx mag encoder and the DutyCycleEncoder class on wpilib. When I display the values in smartdashboard they don’t appear to be changing by much. Why is this?
SwerveModule.java (3.9 KB)
It looks like you’re printing the PositionOffset which is the position when the position was last reset and shouldn’t be changing. I think you want either get().
Another thing is that setDutyCycleRange doesn’t scale the values, it’s used to limit the values for sensors that have flat spots as it rolls over. It does nothing outside of 0 - 1.
Do you think you could explain how a magnetic encoder converts rotation to a PWM signal and how that PWM signal can be used through the DutyCycleEncoder class to get the angular position?
The magnetic encoder has smarts inside it, including a clock. It continuously outputs a pulse chain structured such that every 4096 us there’s a new pulse. The amount of time the pulse is high is directly linear to the measured input angle, and then it goes low for the remainder of the cycle. The DutyCycleEncoder class uses the FPGA to precisely measure the time the pulse is high (versus the total high and low time), and that is then linearly scaled back into an angle for the robot code.
DutyCycleEncoder further uses the FPGA to handle rollover, so multiple rotations are also handled (eg if it went from 0 to 4095 or 4095 to 0).
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.