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 force and torque units to wpiunits #6676

Closed
wants to merge 10 commits into from
48 changes: 48 additions & 0 deletions wpiunits/src/main/java/edu/wpi/first/units/Units.java
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,43 @@ private Units() {
public static final Mult<Mult<Mass, Distance>, Distance> KilogramSquareMeters =
Kilograms.mult(Meters).mult(Meters);

// Force
/** The base SI unit for force. */
public static final Mult<Mass, Velocity<Velocity<Distance>>> Newtons =
derive(Kilograms.mult(Meters.per(Second).per(Second))).named("Newtons").symbol("N").make();

/** Singular alias for Newtons. */
public static final Mult<Mass, Velocity<Velocity<Distance>>> Newton = Newtons; // alias;

/** A unit of force equivalent to 4.448222 {@link #Newtons}. */
public static final Mult<Mass, Velocity<Velocity<Distance>>> PoundsForce =
derive(Newtons).aggregate(4.448222).named("Pounds-Force").symbol("lb.").make();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fun fact, the units work out such that using derive(Pounds.mult(Gs)) would accomplish the same thing while letting the library handle the unit conversions for you

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So that leaves the big PR I worked on last week. I'm sure it will take some time to sift through if its got any merit.


// Torque
/** The base SI unit for torque. */
public static final Mult<Mult<Mass, Velocity<Velocity<Distance>>>, Distance> NewtonMeters =
derive(Newtons.mult(Meters)).named("Newton-Meters").symbol("Nm").make();

/** Singular alias for NewtonMeters. */
public static final Mult<Mult<Mass, Velocity<Velocity<Distance>>>, Distance> NewtonMeter =
NewtonMeters; // alias;

/** A unit of torque equivalent to 1.355818 {@link #NewtonMeters}. */
public static final Mult<Mult<Mass, Velocity<Velocity<Distance>>>, Distance> PoundFeet =
derive(NewtonMeters).aggregate(1.355818).named("Pound-Feet").symbol("lb-ft").make();

/** Singular alias for PoundFeet. */
public static final Mult<Mult<Mass, Velocity<Velocity<Distance>>>, Distance> PoundFoot =
PoundFeet;

/** A unit of torque equivalent to 0.1129848 {@link #NewtonMeters}. */
public static final Mult<Mult<Mass, Velocity<Velocity<Distance>>>, Distance> PoundInches =
derive(NewtonMeters).aggregate(0.1129848).named("Pound-Inches").symbol("lb-in").make();

/** Singular alias for PoundInches. */
public static final Mult<Mult<Mass, Velocity<Velocity<Distance>>>, Distance> PoundInch =
PoundInches;

// Unitless
/** A dimensionless unit that performs no scaling whatsoever. */
public static final Dimensionless Value = BaseUnits.Value;
Expand Down Expand Up @@ -328,6 +365,17 @@ private Units() {
*/
public static final Energy Kilojoule = Kilojoules; // alias

/** A unit of energy equal to 1.355818 Joules. */
public static final Energy FootPounds =
derive(Joules).aggregate(1.355818).named("Foot-Pounds").symbol("ft-lb").make();

/** Singular alias for FootPounds. */
public static final Energy FootPound = FootPounds;

/** A unit of energy equal to 0.1129848 Joules */
public static final Energy InchPounds =
derive(Joules).aggregate(0.1129848).named("Inch-Pounds").symbol("in-lb").make();

// Power
/** The base unit of power. Equivalent to one {@link #Joule} per {@link #Second}. */
public static final Power Watts = BaseUnits.Power;
Expand Down
Loading