RevRobotics CANSparkMax Velocity to MetersPerSecond

How do I get MetersPerSecond using Neo CANSparkMax encoder?

Need this value for SwerveModuleState

You can ask the encoder to return its current velocity, and preform some math like the following:

driveEncoder.getVelocity() / Constants.GEAR_RATIO_DRIVE) * Math.PI * Constants.DRIVE_WHEEL_DIAMETER)
        / Constants.SECONDS_PER_MINUTE)

However, you can also tell the SparkMax to return its value from .getVelocity() to always be in Meters/Sec by setting a Velocity Conversion Factor, like the following:

driveRelEncoder.setVelocityConversionFactor((Constants.MK4_L2_DRIVE_REDUCTION * Math.PI * Constants.MK4_L2_WHEEL_DIAMETER)/60);

In both cases, you just times the Drive Ratio of the gearbox/swerve module, by Pi, and it’s wheel diameter.

2 Likes