This is our team’s first time trying Swerve Drive.
We are using AndyMark Swerve and Steer, and we are modifying “FRC 0 to Autonomous”(youtube) Swerve Drive Code. We need to use the Encoder class for our turning encoder, not Rev’s RelativeEncoder class. We are unsure of how to replace code that relies on the RelativeEncoder class.
To replace the RelativeEncoder class with the Encoder class, you’ll need to make the following changes in your code:
import edu.wpi.first.wpilibj.Encoder;
Replace the RelativeEncoder object creation with an Encoder object creation:
RelativeEncoder relativeEncoder = new RelativeEncoder(port);
Encoder encoder = new Encoder(portA, portB);
Replace all references to the RelativeEncoder object with the Encoder object in the rest of your code.
It’s important to note that the Encoder class does not have a getDistance() method like the RelativeEncoder class. To get the current position of the encoder, you can use the get() method, and to get the rate at which the encoder is changing, you can use the getRate() method.
you cannot wire cancoders to analog inputs, instead you have to wire them to the can bus. also, if you are using cancoders, you are going to need to use CTRE’s API, this won’t really change much in your code other than needing to download the vendor dependencies from WPIlib (make sure to download v5 instead of pro) and use this class instead of the regular encoder class, if you want to, you could also use CTRE’s cancoder class instead of WPILIB’s interface, as it has some handy features such as being able to use degrees