Skip to content

Commit

Permalink
Merge branch 'master' into enable-aruco
Browse files Browse the repository at this point in the history
  • Loading branch information
srimanachanta committed Oct 10, 2023
2 parents 3af2b94 + 5f3b5d2 commit 0e61777
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 64 deletions.
23 changes: 0 additions & 23 deletions LICENSE_MathUtils_orthogonalizeRotationMatrix.txt

This file was deleted.

1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ ext {
wpilibVersion = "2023.4.2"
opencvVersion = "4.6.0-4"
joglVersion = "2.4.0-rc-20200307"
javalinVersion = "5.6.2"
pubVersion = versionString
isDev = pubVersion.startsWith("dev")

Expand Down
2 changes: 1 addition & 1 deletion photon-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ apply from: "${rootDir}/shared/common.gradle"
dependencies {
implementation project(':photon-targeting')

implementation 'io.javalin:javalin:4.2.0'
implementation "io.javalin:javalin:$javalinVersion"

implementation 'org.msgpack:msgpack-core:0.9.0'
implementation 'org.msgpack:jackson-dataformat-msgpack:0.9.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,17 @@
package org.photonvision.common.util.math;

import edu.wpi.first.math.MatBuilder;
import edu.wpi.first.math.Matrix;
import edu.wpi.first.math.Nat;
import edu.wpi.first.math.VecBuilder;
import edu.wpi.first.math.geometry.CoordinateSystem;
import edu.wpi.first.math.geometry.Pose3d;
import edu.wpi.first.math.geometry.Quaternion;
import edu.wpi.first.math.geometry.Rotation3d;
import edu.wpi.first.math.geometry.Transform3d;
import edu.wpi.first.math.numbers.N3;
import edu.wpi.first.math.util.Units;
import edu.wpi.first.util.WPIUtilJNI;
import java.util.Arrays;
import java.util.List;
import org.ejml.data.DMatrixRMaj;
import org.ejml.dense.row.factory.DecompositionFactory_DDRM;
import org.ejml.simple.SimpleMatrix;
import org.opencv.core.Mat;

public class MathUtils {
Expand Down Expand Up @@ -232,38 +227,4 @@ public static void rotationToOpencvRvec(Rotation3d rotation, Mat rvecOutput) {
var axis = rotation.getAxis().times(angle);
rvecOutput.put(0, 0, axis.getData());
}

/**
* Orthogonalize an input matrix using a QR decomposition. QR decompositions decompose a
* rectangular matrix 'A' such that 'A=QR', where Q is the closest orthogonal matrix to the input,
* and R is an upper triangular matrix.
*
* <p>The following function is released under the BSD license avaliable in
* LICENSE_MathUtils_orthogonalizeRotationMatrix.txt.
*/
public static Matrix<N3, N3> orthogonalizeRotationMatrix(Matrix<N3, N3> input) {
var a = DecompositionFactory_DDRM.qr(3, 3);
if (!a.decompose(input.getStorage().getDDRM())) {
// best we can do is return the input
return input;
}

// Grab results (thanks for this _great_ api, EJML)
var Q = new DMatrixRMaj(3, 3);
var R = new DMatrixRMaj(3, 3);
a.getQ(Q, false);
a.getR(R, false);

// Fix signs in R if they're < 0 so it's close to an identity matrix
// (our QR decomposition implementation sometimes flips the signs of columns)
for (int colR = 0; colR < 3; ++colR) {
if (R.get(colR, colR) < 0) {
for (int rowQ = 0; rowQ < 3; ++rowQ) {
Q.set(rowQ, colR, -Q.get(rowQ, colR));
}
}
}

return new Matrix<>(new SimpleMatrix(Q));
}
}
2 changes: 1 addition & 1 deletion photon-server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ dependencies {
implementation project(':photon-core')
implementation project(':photon-targeting')

implementation "io.javalin:javalin:5.6.2"
implementation "io.javalin:javalin:$javalinVersion"

implementation wpilibTools.deps.wpilibJava("wpiutil")
implementation wpilibTools.deps.wpilibJava("wpimath")
Expand Down

0 comments on commit 0e61777

Please sign in to comment.