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.
private Conversion converter1 = new Conversion(
PositionUnit.RADIANS, EncoderType.INTERNAL);
private Conversion converter2 = new Conversion(
VelocityUnit.ROTATIONS_PER_MIN, EncoderType.INTERNAL);
Available Units
Position Units
Unit
Description
Common Use Cases
RADIANS
Angular position in radians
Mathematical calculations, arms
DEGREES
Angular position in degrees
Human-readable angles, swerve modules
ROTATIONS
Complete rotations
Wheel rotations, continuous mechanisms
Velocity Units
Unit
Description
Common Use Cases
RADIANS_PER_SEC
Angular velocity in radians/s
Mathematical calculations
DEGREES_PER_SEC
Angular velocity in degrees/s
Angular motion control
ROTATIONS_PER_SEC
Rotations per second
High-speed mechanisms
ROTATIONS_PER_MIN
Rotations per minute
Shooters, intakes
Using the Conversion Object
To convert to encoder units for setting a value we use the toMotor method.
javaCopy// Position control examples
Conversion armConverter = new Conversion(PositionUnit.DEGREES, EncoderType.INTERNAL);
double targetAngle = 90.0; // We want the arm at 90 degrees
motor.setPosition(armConverter.toMotor(targetAngle));
// Velocity control examples
Conversion shooterConverter = new Conversion(VelocityUnit.ROTATIONS_PER_MIN, EncoderType.INTERNAL);
double targetRPM = 3600; // We want the shooter at 3600 RPM
motor.setVelocity(shooterConverter.toMotor(targetRPM));