mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-23 01:21:42 +00:00
[wpimath] Add basic wpiunits support (#5821)
To reduce the need for users to manually perform unit conversions, this allows Measure objects from wpiunits to be passed into most places in wpimath that currently expect doubles in terms of SI units like meters. For example, users would need to know that unit conversion is required - and what the correct units are. Using units would be more difficult to write code for than just hardcoding a value or using Units.inchesToMeters. Now, using units has no more developer overhead than using raw numbers.
This commit is contained in:
@@ -20,11 +20,11 @@ public final class BaseUnits {
|
||||
public static final Velocity<Distance> Velocity =
|
||||
new Velocity<>(Distance, Time, "Meter per Second", "m/s");
|
||||
|
||||
/** The standard unit of mass, grams. */
|
||||
/** The standard unit of mass, kilograms. */
|
||||
public static final Mass Mass = new Mass(1, "Kilogram", "Kg");
|
||||
|
||||
/** The standard unit of angles, revolutions. */
|
||||
public static final Angle Angle = new Angle(1, "Revolution", "R");
|
||||
/** The standard unit of angles, radians. */
|
||||
public static final Angle Angle = new Angle(1, "Radian", "rad");
|
||||
|
||||
/** The standard "unitless" unit. */
|
||||
public static final Dimensionless Value = new Dimensionless(1, "<?>", "<?>");
|
||||
|
||||
@@ -38,10 +38,9 @@ public final class Units {
|
||||
public static final Time Minute = Minutes; // singularized alias
|
||||
|
||||
// Angle
|
||||
public static final Angle Revolutions = BaseUnits.Angle;
|
||||
public static final Angle Rotations = new Angle(1, "Rotation", "R"); // alias
|
||||
public static final Angle Radians =
|
||||
derive(Revolutions).splitInto(2 * Math.PI).named("Radian").symbol("rad").make();
|
||||
public static final Angle Radians = BaseUnits.Angle;
|
||||
public static final Angle Revolutions = new Angle(2 * Math.PI, "Revolution", "R");
|
||||
public static final Angle Rotations = new Angle(2 * Math.PI, "Rotation", "R"); // alias revolution
|
||||
public static final Angle Degrees =
|
||||
derive(Revolutions).splitInto(360).named("Degree").symbol("°").make();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user