Thrifty Nova
  • Software Resources
    • Getting Started
    • Configure Controller Settings
      • Factory Default
      • Motor Type - Minion Setting
      • Inverting the Motor
      • Brake Mode
      • Maximum Output
      • Ramp Up/Ramp Down
      • Current Limiting
      • Soft Limits
      • Hard Limits
      • Setting Encoder Position
      • Follower Mode
    • Configure Onboard PID
    • Configure CAN Frequency
    • IO Signal Management
    • Set Output
    • Logging
    • Get Feedback
    • Unit Conversions
    • Subsystem Examples
      • Simple Elevator Example
      • Swerve Module Example
      • Simple Arm Example
  • Electrical Resources
    • Wiring the Thrifty Nova
    • LED Color Codes
    • Brushless Hall Sensor Connector
    • USB Communications
    • 10 Pin Data Connector
      • Intro to Sensors
      • Sensor Hat
      • Motor Runner Board
    • Hard Reset
  • Mechanical
    • Mounting Options
  • Software Releases
    • Software Releases
  • Thrifty Config
    • Thrifty Config Demo Video
Powered by GitBook
On this page
  • Creating a Conversion Object
  • Position Units
  • Velocity Units
  • Using the Conversion Object
  • To Motor Units (for Setting Values)
  • From Motor Units (for Reading Values)

Was this helpful?

Export as PDF
  1. Software Resources

Unit Conversions

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.

double targetPosition = Math.PI / 2; // radians
positionMotor.setPosition( converter1.toMotor(targetPosition) );

double targetVelocity = 2500; // RPMs
velocityMotor.setVelocity( converter2.toMotor(targetVelocity) );

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 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));

From Motor Units (for Reading Values)

javaCopy// Position reading examples
Conversion armConverter = new Conversion(PositionUnit.DEGREES, EncoderType.INTERNAL);
double currentAngle = armConverter.fromMotor(motor.getPosition());
SmartDashboard.putNumber("Arm Angle", currentAngle);

// Velocity reading examples
Conversion shooterConverter = new Conversion(VelocityUnit.ROTATIONS_PER_MIN, EncoderType.INTERNAL);
double currentRPM = shooterConverter.fromMotor(motor.getVelocity());
SmartDashboard.putNumber("Shooter RPM", currentRPM);
PreviousGet FeedbackNextSubsystem Examples

Last updated 6 months ago

Was this helpful?