0 To Auto Swerve AnalogInput Help

This is my start of setting up a Zero to Auto Swerve. One thing I am stuck on is the Absolute encoders. In the program, it uses AnalogInput for the CANCoders, but for our robot we have the CANCoders setup in the CAN network alongside everything else rather than plugged into the analog ports in the rio. If there is a class and import that works for this, that would be insanely helpful. Thank you.

So is your question how do you use the CANCoder to get the position?

This example seems to be close to what you’re looking for, though I’m not entirely sure that I understand what question you’re asking.

You can call CANCoders using their CAN ID:

I use them here in some code I wrote during the offseason:

Call functions are in SwerveCombo.java in the modules folder. The import is com.ctre.phoenix.sensors.CANCoder - it’s from the CTRE Vendor Libraries.

You would have to swap the AnalogInput call functions to something that calls the CANCoder.getAbsolutePosition or something else. I ended up only using them to set the initial angle of the Falcons before using their integrated sensors - it will probably be more complicated in your case.

Hopefully this helps.

I guess this link would be better. Toward the top it creates the absolute encoder using the AnalogInput class for that, which requires you to plug the encoder into the Roborio. The main issue I was having it when swapping to the CANencoder class was the functions called further down in the code is exclusive to AnalogInputs. Hope this explaination makes a bit more sense.

It would probably be the getPosition() function found here:
https://api.ctr-electronics.com/phoenix/release/java/com/ctre/phoenix/sensors/CANCoder.html

hmm, okay looking at what functions are called and what the CANcoder class offers, I would hope the .getVoltage from analog works similar to the CANcoders .getBusVoltage. The one I can not finding it the .getChannel().

hmm.getDeviceId might work