PARTs Unit
Explanation & History
A PARTs Unit is a simple and robust way to manage different used units across the robot code.
The user creates a new PARTs Unit and specifies the starting value and its unit. After that, the PARTs Unit can be used anywhere to convert the unit on the fly. E.g. feet to meters.
We created this mainly because we were having issues with the base WPI unit conversions; there were issues where types didn't convert correctly for us. Not only did it solve our unit issues, it also allowed us to have full control over our units. Since the source code is so straight forward, it's easier to troubleshoot and use.
Code Example
Using PARTs Units really is easy! Just import the two PARTs Unit classes and create a new PARTs Unit.
package;
// Import the PARTs Units.
import org.parts3492.partslib.PARTsUnit;
// Import the Unit types.
import org.parts3492.partslib.PARTsUnit.PARTsUnitType;
public class MyClass {
// Create our PARTs Unit. Value, The type of the unit.
public PARTsUnit myAngle = new PARTsUnit(180.0, PARTsUnitType.Angle);
// Keep in mind how units convert, some units cannot convert with
// other units. E.g. Meters to Percent.
// Convert our angle to radians! Convert TO radians.
public double myAngleInRadians = myAngle.to(PARTsUnitType.Radians);
}