We are currently setting up our swerve drive for this season. The absolute encoder is green but our programmers do not know how to actually define the absolute encoder. Is there a resource we can look at or is it super simple way to declare it in the code.
There almost certainly is, but we would need to know what model encoder is in use.
If you told us what swerve module you’re using, along with the exact combination of hardware (drive motor, rotate motor and encoder), someone will be able to point you to a repository that you can look at as an example for your exact situation.
CTRE Cancoder
MK4i
CTRE Cancoder
Neo motors
Spark Max Motor Controllers
To declare a cancoder in the code, you first need to make sure you have the phoenix 6 or 5 library installed.
In phoenix 6, it’s as simple as creating a Cancoder
and applying a CancoderConfiguration
to it. After that, use Status Signals to get its position.
From there, you’ll either need to reset the NEO’s position to the Cancoder’s position (with the required conversions), or do the pid in the code with a PIDController.
Declare a CANCoder variable
private int ENCODER_ID = 1; //your can id here
private CANCoder angleEncoder = new CANCoder(ENCODER_ID);
Then you can get the reading with
angleEncoder.getAbsolutePosition();
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.