Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to get Rotation2d as Measurement<Angle> #6491

Closed
TaylerUva opened this issue Mar 31, 2024 · 0 comments · Fixed by #6492
Closed

Add ability to get Rotation2d as Measurement<Angle> #6491

TaylerUva opened this issue Mar 31, 2024 · 0 comments · Fixed by #6492
Labels
component: wpimath Math library type: feature Brand new functionality, features, pages, workflows, endpoints, etc.

Comments

@TaylerUva
Copy link

TaylerUva commented Mar 31, 2024

Is your feature request related to a problem? Please describe.
My team is trying to convert our code to use Measure as a way to combat usage of incorrect units being used. Rotation2d currently has a constructor that allows creation via Measure<Angle> but no way to get a Measure<Angle> back.

/**
* Constructs a Rotation2d with the given angle.
*
* @param angle The angle of the rotation.
*/
public Rotation2d(Measure<Angle> angle) {
this(angle.in(Radians));
}

Describe the solution you'd like
I suggest the following method be implemented within the Rotation2d class

  /**
   * Returns the angle measurement of the Rotation2d.
   *
   * @return The angle measurement of the Rotation2d.
   */
  public Measure<Angle> getMeasure() {
    return Radians.of(getRadians());
  }

Describe alternatives you've considered
A current alternative is to create a new Measure using Units.Rotations.of(Rotation2d.getRadians()) but this is less clean than Rotation2d.getMeasure()

Additional context
None

@calcmogul calcmogul added type: feature Brand new functionality, features, pages, workflows, endpoints, etc. component: wpimath Math library labels Mar 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: wpimath Math library type: feature Brand new functionality, features, pages, workflows, endpoints, etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants