mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-22 01:11:42 +00:00
[wpimath] Move math functionality into new wpimath library (#2629)
The wpimath library is a new library designed to separate the reusable math functionality from the common utility library (wpiutil) and the hardware-dependent library (wpilibc/j). Package names / include file names were NOT changed to minimize breakage. In a future year it would be good to revamp these for a more uniform user experience and to reduce the risk of accidental naming conflicts. While theoretically all of this functionality could be placed into wpiutil, several pieces of this library (e.g. DARE) are very time-consuming to compile, so it's nice to avoid this expense for users who only want cscore or ntcore. It also allows for easy future separation of build tasks vs number of workers on memory-constrained machines. This moves the following functionality from wpiutil into wpimath: - Eigen - ejml - Drake - DARE - wpiutil.math package (Matrix etc) - units And the following functionality from wpilibc/j into wpimath: - Geometry - Kinematics - Spline - Trajectory - LinearFilter - MedianFilter - Feed-forward controllers
This commit is contained in:
25
wpimath/src/main/java/edu/wpi/first/math/MathShared.java
Normal file
25
wpimath/src/main/java/edu/wpi/first/math/MathShared.java
Normal file
@@ -0,0 +1,25 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
package edu.wpi.first.math;
|
||||
|
||||
public interface MathShared {
|
||||
/**
|
||||
* Report an error.
|
||||
*
|
||||
* @param error the error to set
|
||||
*/
|
||||
void reportError(String error, StackTraceElement[] stackTrace);
|
||||
|
||||
/**
|
||||
* Report usage.
|
||||
*
|
||||
* @param id the usage id
|
||||
* @param count the usage count
|
||||
*/
|
||||
void reportUsage(MathUsageId id, int count);
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2018-2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
package edu.wpi.first.math;
|
||||
|
||||
public final class MathSharedStore {
|
||||
private static MathShared mathShared;
|
||||
|
||||
private MathSharedStore() {
|
||||
}
|
||||
|
||||
/**
|
||||
* get the MathShared object.
|
||||
*/
|
||||
public static synchronized MathShared getMathShared() {
|
||||
if (mathShared == null) {
|
||||
mathShared = new MathShared() {
|
||||
@Override
|
||||
public void reportError(String error, StackTraceElement[] stackTrace) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reportUsage(MathUsageId id, int count) {
|
||||
}
|
||||
};
|
||||
}
|
||||
return mathShared;
|
||||
}
|
||||
|
||||
/**
|
||||
* set the MathShared object.
|
||||
*/
|
||||
public static synchronized void setMathShared(MathShared shared) {
|
||||
mathShared = shared;
|
||||
}
|
||||
|
||||
/**
|
||||
* Report an error.
|
||||
*
|
||||
* @param error the error to set
|
||||
*/
|
||||
public static void reportError(String error, StackTraceElement[] stackTrace) {
|
||||
getMathShared().reportError(error, stackTrace);
|
||||
}
|
||||
|
||||
/**
|
||||
* Report usage.
|
||||
*
|
||||
* @param id the usage id
|
||||
* @param count the usage count
|
||||
*/
|
||||
public static void reportUsage(MathUsageId id, int count) {
|
||||
getMathShared().reportUsage(id, count);
|
||||
}
|
||||
}
|
||||
19
wpimath/src/main/java/edu/wpi/first/math/MathUsageId.java
Normal file
19
wpimath/src/main/java/edu/wpi/first/math/MathUsageId.java
Normal file
@@ -0,0 +1,19 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
package edu.wpi.first.math;
|
||||
|
||||
public enum MathUsageId {
|
||||
kKinematics_DifferentialDrive,
|
||||
kKinematics_MecanumDrive,
|
||||
kKinematics_SwerveDrive,
|
||||
kTrajectory_TrapezoidProfile,
|
||||
kFilter_Linear,
|
||||
kOdometry_DifferentialDrive,
|
||||
kOdometry_SwerveDrive,
|
||||
kOdometry_MecanumDrive
|
||||
}
|
||||
Reference in New Issue
Block a user