Hello, I am a programmer from 7636. Our team bought some new absolute encoders called “Canandcoder” by Redux Robotics, and we installed them on our MK4i swerve. However, we’ve never used this kind of encoder before (we used CANcoders this season), and we encountered many errors when trying to modify our previous code.
Our code is based on this repo:
Thanks in advance! Sorry for my bad English, I’m not a native speaker<(_ _)>
Are you running it connected to the spark max or on the CAN? If the spark max look at this documentation if on the CAN use this document. That will require you adding redux’s vendor lib. But either way I don’t think you should be representing it with an Analog potentiometer.
Are these encoders plugged into a SPARK MAX or are they connected only with the CANbus? Have you checked the example code on the website for either use case?
If you connect and power the Canandcoder over the Spark Max’s 10-pin, to read the PWM value, you want to use the SparkMaxAbsoluteEncoder “duty cycle” option that you get via .getAbsoluteEncoder, rather than any of the analog options (via getAnalog) – see our docs specific to this use case for some code examples.
While Rev’s docs are a little sparse on how to use duty cycle encoders, they use this functionality for MAXSwerve in order to read from their Throughbore which senses absolute position over the same pin.
Yep, that’s the setup. Note that the code uses these encoders as Duty Cycle absolute encoders. And we do not zero them to the “straight” position (even though you can), we just recorded the absolute values for them and use those as a “zero points” for the individual modules.