Skip to content

Commit

Permalink
[wpimath] Split WPIMathJNI into logical chunks
Browse files Browse the repository at this point in the history
This makes things easier to find, and speeds up compilation.
  • Loading branch information
calcmogul committed Aug 24, 2023
1 parent 7889b35 commit ee44f85
Show file tree
Hide file tree
Showing 10 changed files with 655 additions and 526 deletions.
7 changes: 6 additions & 1 deletion wpimath/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ include(SubDirList)
include(CompileWarnings)
include(AddTest)

file(GLOB wpimath_jni_src src/main/native/cpp/jni/WPIMathJNI.cpp)
file(GLOB wpimath_jni_src src/main/native/cpp/jni/WPIMathJNI_DARE.cpp
src/main/native/cpp/jni/WPIMathJNI_Eigen.cpp
src/main/native/cpp/jni/WPIMathJNI_Exceptions.cpp
src/main/native/cpp/jni/WPIMathJNI_Pose3d.cpp
src/main/native/cpp/jni/WPIMathJNI_StateSpaceUtil.cpp
src/main/native/cpp/jni/WPIMathJNI_Trajectory.cpp)

# Java bindings
if (WITH_JAVA)
Expand Down
64 changes: 37 additions & 27 deletions wpimath/src/main/java/edu/wpi/first/math/WPIMathJNI.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public static synchronized void forceLoad() throws IOException {
libraryLoaded = true;
}

// DARE wrappers

/**
* Computes the unique stabilizing solution X to the discrete-time algebraic Riccati equation.
*
Expand Down Expand Up @@ -208,6 +210,8 @@ public static native void dareABQRN(
int inputs,
double[] S);

// Eigen wrappers

/**
* Computes the matrix exp.
*
Expand All @@ -227,6 +231,35 @@ public static native void dareABQRN(
*/
public static native void pow(double[] src, int rows, double exponent, double[] dst);

/**
* Performs an inplace rank one update (or downdate) of an upper triangular Cholesky decomposition
* matrix.
*
* @param mat Array of elements of the matrix to be updated.
* @param lowerTriangular Whether mat is lower triangular.
* @param rows How many rows there are.
* @param vec Vector to use for the rank update.
* @param sigma Sigma value to use for the rank update.
*/
public static native void rankUpdate(
double[] mat, int rows, double[] vec, double sigma, boolean lowerTriangular);

/**
* Solves the least-squares problem Ax=B using a QR decomposition with full pivoting.
*
* @param A Array of elements of the A matrix.
* @param Arows Number of rows of the A matrix.
* @param Acols Number of rows of the A matrix.
* @param B Array of elements of the B matrix.
* @param Brows Number of rows of the B matrix.
* @param Bcols Number of rows of the B matrix.
* @param dst Array to store solution in. If A is m-n and B is m-p, dst is n-p.
*/
public static native void solveFullPivHouseholderQr(
double[] A, int Arows, int Acols, double[] B, int Brows, int Bcols, double[] dst);

// Pose3d wrappers

/**
* Obtain a Pose3d from a (constant curvature) velocity.
*
Expand Down Expand Up @@ -299,6 +332,8 @@ public static native double[] logPose3d(
double endQy,
double endQz);

// StateSpaceUtil wrappers

/**
* Returns true if (A, B) is a stabilizable pair.
*
Expand All @@ -314,6 +349,8 @@ public static native double[] logPose3d(
*/
public static native boolean isStabilizable(int states, int inputs, double[] A, double[] B);

// Trajectory wrappers

/**
* Loads a Pathweaver JSON.
*
Expand Down Expand Up @@ -348,19 +385,6 @@ public static native double[] logPose3d(
*/
public static native String serializeTrajectory(double[] elements);

/**
* Performs an inplace rank one update (or downdate) of an upper triangular Cholesky decomposition
* matrix.
*
* @param mat Array of elements of the matrix to be updated.
* @param lowerTriangular Whether mat is lower triangular.
* @param rows How many rows there are.
* @param vec Vector to use for the rank update.
* @param sigma Sigma value to use for the rank update.
*/
public static native void rankUpdate(
double[] mat, int rows, double[] vec, double sigma, boolean lowerTriangular);

public static class Helper {
private static AtomicBoolean extractOnStaticLoad = new AtomicBoolean(true);

Expand All @@ -372,18 +396,4 @@ public static void setExtractOnStaticLoad(boolean load) {
extractOnStaticLoad.set(load);
}
}

/**
* Solves the least-squares problem Ax=B using a QR decomposition with full pivoting.
*
* @param A Array of elements of the A matrix.
* @param Arows Number of rows of the A matrix.
* @param Acols Number of rows of the A matrix.
* @param B Array of elements of the B matrix.
* @param Brows Number of rows of the B matrix.
* @param Bcols Number of rows of the B matrix.
* @param dst Array to store solution in. If A is m-n and B is m-p, dst is n-p.
*/
public static native void solveFullPivHouseholderQr(
double[] A, int Arows, int Acols, double[] B, int Brows, int Bcols, double[] dst);
}
Loading

0 comments on commit ee44f85

Please sign in to comment.