Changing CANcoders to encoders in swerve programs

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<(_ _)>

1 Like

Can you describe the problems you’re having?

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.

1 Like

Yeah, these are Helium encoders. More importantly, they’re Duty Cycle encoders, meaning, need to to be configured and used as such.

We helped one of our sister teams to get working swerve code for those when they’re connected to the NEOs.

This one is a branch with working Teleop code for it.

Note that in our case they’re connected to SPARK directly, not CAN bus.

Both SPARK motion and encoder setting and programming is here:

Feel free to ask questions if needed.

1 Like

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?

https://docs.reduxrobotics.com/canandcoder/programming/position-and-velocity

I think I just mixed up different types of sensors. After reading other replies, I’ll try to fix my code again! Thank you!

I connected them to Spark MAX. But we’re also considering soldering some of them with CAN wires.

But either way I don’t think you should be representing it with an Analog potentiometer.

Oops… did I mix them up?

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.

1 Like

Thank you for sharing your program with me; I really appreciate it! I’ll refer to it to modify my code.

They’re all connected to Spark MAXes via IDC.

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.

I now realize where another problem is. Thank you! I’ll edit my code right after this weekend.

(Sorry for being late!)

1 Like

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