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 change base unit type for Java Units library #7860

Open
jonathandao0 opened this issue Mar 13, 2025 · 0 comments · May be fixed by #7876
Open

Add ability to change base unit type for Java Units library #7860

jonathandao0 opened this issue Mar 13, 2025 · 0 comments · May be fixed by #7876
Labels
component: wpiunits Java units library type: feature Brand new functionality, features, pages, workflows, endpoints, etc.

Comments

@jonathandao0
Copy link

Is your feature request related to a problem? Please describe.
When declaring a variable using the Java Units library, there isn't a clean way to set/change the base unit of a measure when starting from a unit type different than what you want the code to use by default.

For example, if I measure a device using a ruler in inches, but the code would prefer to use meters, you currently have to do this

Distance kElevatorDrumDiameter = Meters.of(Units.inchesToMeters(2));

Additionally when using Epilogue, you currently have to add a lot more boilerplate to log values in a different unit than what is used by vendors.

// For CTRE TalonFX
@NotLogged
public Angle getRotations() {
    // Returns rotations, but we don't want to log values in this unit
    return m_positionSignal.refresh().getValue();
}

public Angle getDegrees() {
    return Degrees.of(getRotations().in(Degrees));
}

public double getDegrees() {
    // You can also do this, but then this function will only be used for logging.
    return getRotations().in(Degrees);
}

Describe the solution you'd like
A decorator pattern would be useful to simply this.

Distance kElevatorDrumDiameter = Inches.of(2).as(Meters);

Which would make adding additional functions for Epilogue unnecessary, simplifying code

// For CTRE TalonFX
public Angle getDegrees() {
    return m_positionSignal.refresh().getValue().as(Degrees);
}
@jonathandao0 jonathandao0 added the type: feature Brand new functionality, features, pages, workflows, endpoints, etc. label Mar 13, 2025
@auscompgeek auscompgeek added the component: wpiunits Java units library label Mar 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: wpiunits Java units 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