Swerve Drive Beginners please help

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.

Our code can be viewed at: GitHub - riverdalerobotics/SwerveTest2023

Also, have looked online, and still can’t figure out how to wire the CANCoders to the Analog Inputs which we are using for our absolute encoders.

Thank you so much for your assistance. Please tell us if you need more information.

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.

1 Like

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

Just to clarify: we should instead wire the cancoders into the can bus containing the motor controllers?

yes

@jxgreer team 8086 is also using the 0 to Autonomous for our swerve drive. We are getting an error at the end of the SwerveJoystickCmd.java.


It does not give us any helpful suggestions. Did you encounter this?