-
Notifications
You must be signed in to change notification settings - Fork 614
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
[wpiunits] Improves usage ergonomics and add more unit types #6710
Conversation
@PeterJohnson What am I missing for it? EDIT: also CMake is failing which is interesting since no C++ files were altered and this is a fresh pull from main. |
Both the failures are unrelated to your PR, you can ignore them. Comment on PR for robotpy / comment (pull_request) is failing because you modified a file under CMake Windows is failing because it's having problems building the dependencies. |
Superseded by #6958. |
So the main inspiration for this reorganization was to provide a means of creating measures in this form
Measure<LinearAcceleration> measure = RadiansPerSecondPerSecond.of(3.0)
instead of
Measure<Velocity<Velocity<Distance>>> measure = RadiansPerSecondPerSecond.of(3)
which from some loose feedback I've received is a major deterrent for teams/groups/students utilizing this API.
This removes the
Velocity
class entirely with its functionality being taken up by the new derived classes and thePer
type.Also
Power
,Energy
, andVoltage
have been removed as base units since they are derived from others.The
BaseUnits
class is more representative now of the actual SI base unit quantities. WithAngle
andDimensionless
still inthe class for Java language purposes.
In order to make this work please understand the following caveats.
Mult
andPer
respectively.times
andper
methods useful for generating units of the new types.combine
method similar to the combine method inMult
andPer
to handle unit type creation.cache
variables similar to those found inMult
andPer
are added in these new derived types to allow for thecombine
static methods in those classes to function.Mult
andPer
so as not to have code duplication in regards to , but the Java language spec doesn't really allow for this in the current implementation ofMult
andPer
. There could be a simple fix for this that I haven't discovered yet.times
anddivide
methods in theMeasure
class have been modified to take into account the lack of theVelocity
class.times
method in theMeasure
class now checks commutativity of the units.Summary of the new unit types and how they are derived. Sorry if this is appears to be a lesson in physics.
AngularVelocity
is derived as a quotient ofAngle
andTime
AngularAcceleration
is derived as a quotient ofAngularVelocity
andTime
LinearVelocity
is derived as a quotient ofDistance
andTime
LinearAcceleration
is derived as a quotient ofLinearVelocity
andTime
Force
is derived as a product ofMass
andLinearAcceleration
Energy
is derived as a product ofForce
andDistance
Power
is derived as a quotient ofEnergy
andTime
Voltage
is derived as a quotient ofPower
andCurrent
LinearMomentum
is derived as a product ofMass
andLinearVelocity
AngularMomentum
is derived as a product ofDistance
andLinearMomentum
MomentOfInertia
is derived as a quotient ofAngularMomentum
andAngularVelocity
Torque
is derived as a product ofMomentOfInertia
andAngularMomentum
. (This solved a problem withEnergy
andTorque
having the same unit composition and is a reasonably valid alternative from a physics standpoint).This document from NIST (National Institute of Standards and Technology) was very helpful in this work
Just to note I have a PR #6676 that has yet to be merged and attempts to add force and torque units. These have been included in this PR and in fact was the inspiration for this PR. I'm leaving PR #6676 open until told what to do with it.
This
Measure
type for torque in PR #6676 wasMeasure<Mult<Mult<Mass, Velocity<Velocity<Distance>>>>
As always feedback is requested and appreciated.
EDIT: Changes made. Originally Trapezoid profile had its Velocity constructor removed and replaced with one for both linear and angular velocity. Unfortunately Java's type erasure prevented this as a direct constructor. At the time I removed this constructor entirely. I have now added it back in as two static methods so as to avoid Java type erasure conflicts.