Added support for CANandCoder

This commit is contained in:
thenetworkgrinch
2023-08-09 15:05:33 -05:00
parent d356dec4d0
commit f88fdfb6cf
4 changed files with 66 additions and 47 deletions

View File

@@ -19,13 +19,16 @@ public class SparkMaxEncoderSwerve extends SwerveAbsoluteEncoder
/**
* Create the {@link AbsoluteEncoder} object as a duty cycle. from the {@link CANSparkMax} motor.
*
* @param motor Motor to create the encoder from.
* @param motor Motor to create the encoder from.
* @param conversionFactor The conversion factor to set if the output is not from 0 to 360.
*/
public SparkMaxEncoderSwerve(SwerveMotor motor)
public SparkMaxEncoderSwerve(SwerveMotor motor, int conversionFactor)
{
if (motor.getMotor() instanceof CANSparkMax)
{
encoder = ((CANSparkMax) motor.getMotor()).getAbsoluteEncoder(Type.kDutyCycle);
encoder.setVelocityConversionFactor(conversionFactor);
encoder.setPositionConversionFactor(conversionFactor);
} else
{
throw new RuntimeException("Motor given to instantiate SparkMaxEncoder is not a CANSparkMax");