[wpiunits] Java units API rewrite (#6958)

Java generics are too limited to do what we need. This refactors generic code previously in Unit and Measure into unit-specific classes that can have unit-safe math operations (notably, times and divide) that can return values in known units instead of a wildcarded Measure<?>.

Unit-specific measure implementations are automatically generated by ./wpiunits/generate_units.py, which generates generic interfaces and mutable and immutable implementations of those interfaces. These make up the bulk of the diff of this PR (approximately 9300 LOC).

This also adds units for angular and linear velocities, accelerations, and momenta; moment of inertia; and torque.
This commit is contained in:
Sam Carlberg
2024-09-07 13:59:29 -04:00
committed by GitHub
parent 496e7c1bba
commit a9b885070e
178 changed files with 14750 additions and 2158 deletions

View File

@@ -9,8 +9,7 @@ import edu.wpi.first.epilogue.logging.NTDataLogger;
import edu.wpi.first.epilogue.logging.errors.ErrorHandler;
import edu.wpi.first.epilogue.logging.errors.ErrorPrinter;
import edu.wpi.first.networktables.NetworkTableInstance;
import edu.wpi.first.units.Measure;
import edu.wpi.first.units.Time;
import edu.wpi.first.units.measure.Time;
/**
* A configuration object to be used by the generated {@code Epilogue} class to customize its
@@ -29,13 +28,13 @@ public class EpilogueConfiguration {
* The period Epilogue will log at. By default this is the period that the robot runs at. This is
* the field used by bind to configure speed when adding the periodic logging function
*/
public Measure<Time> loggingPeriod;
public Time loggingPeriod;
/**
* The offset from the periodic run that Epilogue will log at. By default this will be half of the
* robots period. This is the field used by bind when adding the periodic logging function
*/
public Measure<Time> loggingPeriodOffset;
public Time loggingPeriodOffset;
/**
* The minimum importance level of data to be logged. Defaults to debug, which logs data of all

View File

@@ -211,7 +211,7 @@ public interface DataLogger {
* @param unit the unit to log the measurement in
* @param <U> the dimension of the unit
*/
default <U extends Unit<U>> void log(String identifier, Measure<U> value, U unit) {
default <U extends Unit> void log(String identifier, Measure<U> value, U unit) {
log(identifier, value.in(unit));
}