The Thrifty Nova position and velocity feedback methods return using encoder units. Closed loop control uses these units as well. However oftentimes programmers want to convert to a more user friendly unit. For this we can use the Conversion class.
Creating a Conversion Object
We can create a converter by providing a human readable unit from the PositionUnit or VelocityUnit types, and the EncoderType of the encoder we are using.
To convert from encoder units for reading a value we use the fromMotor method.
double position =converter1.fromMotor(positionMotor.getPosition());SmartDashboard.putNumber("Position (rads)", position);double velocity =converter2.toMotor(velocityMotor.getVelocity());SmartDashboard.putNumber("Velocity (rpms)", velocity);
To Motor Units (for Setting Values)
javaCopy// Position control examplesConversion armConverter =newConversion(PositionUnit.DEGREES,EncoderType.INTERNAL);double targetAngle =90.0; // We want the arm at 90 degreesmotor.setPosition(armConverter.toMotor(targetAngle));// Velocity control examplesConversion shooterConverter =newConversion(VelocityUnit.ROTATIONS_PER_MIN,EncoderType.INTERNAL);double targetRPM =3600; // We want the shooter at 3600 RPMmotor.setVelocity(shooterConverter.toMotor(targetRPM));