mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[wpimath] Clean up Eigen usage
* Replace Matrix<> with Vector<> where vectors are explicitly intended. I found these via `rg "Eigen::Matrix<double, \w+, 1>"`. * Pass all Eigen matrices by const reference. I found these via `rg "\(Eigen"` on main (the initializer list constructors make more false positives). * Replace MakeMatrix() and operator<< usage with initializer list constructors. I found these via `rg MakeMatrix` and `rg "<<"` respectively. * Deprecate MakeMatrix()
This commit is contained in:
committed by
Peter Johnson
parent
72716f51ce
commit
9359431bad
@@ -12,12 +12,12 @@
|
||||
|
||||
TEST(StateSpaceUtilTest, MakeMatrix) {
|
||||
// Column vector
|
||||
Eigen::Matrix<double, 2, 1> mat1 = frc::MakeMatrix<2, 1>(1.0, 2.0);
|
||||
Eigen::Vector<double, 2> mat1 = frc::MakeMatrix<2, 1>(1.0, 2.0);
|
||||
EXPECT_NEAR(mat1(0), 1.0, 1e-3);
|
||||
EXPECT_NEAR(mat1(1), 2.0, 1e-3);
|
||||
|
||||
// Row vector
|
||||
Eigen::Matrix<double, 1, 2> mat2 = frc::MakeMatrix<1, 2>(1.0, 2.0);
|
||||
Eigen::RowVector<double, 2> mat2 = frc::MakeMatrix<1, 2>(1.0, 2.0);
|
||||
EXPECT_NEAR(mat2(0), 1.0, 1e-3);
|
||||
EXPECT_NEAR(mat2(1), 2.0, 1e-3);
|
||||
|
||||
@@ -102,44 +102,42 @@ TEST(StateSpaceUtilTest, CovArray) {
|
||||
}
|
||||
|
||||
TEST(StateSpaceUtilTest, WhiteNoiseVectorParameterPack) {
|
||||
Eigen::Matrix<double, 2, 1> vec = frc::MakeWhiteNoiseVector(2.0, 3.0);
|
||||
Eigen::Vector<double, 2> vec = frc::MakeWhiteNoiseVector(2.0, 3.0);
|
||||
static_cast<void>(vec);
|
||||
}
|
||||
|
||||
TEST(StateSpaceUtilTest, WhiteNoiseVectorArray) {
|
||||
Eigen::Matrix<double, 2, 1> vec = frc::MakeWhiteNoiseVector<2>({2.0, 3.0});
|
||||
Eigen::Vector<double, 2> vec = frc::MakeWhiteNoiseVector<2>({2.0, 3.0});
|
||||
static_cast<void>(vec);
|
||||
}
|
||||
|
||||
TEST(StateSpaceUtilTest, IsStabilizable) {
|
||||
Eigen::Matrix<double, 2, 2> A;
|
||||
Eigen::Matrix<double, 2, 1> B;
|
||||
B << 0, 1;
|
||||
Eigen::Matrix<double, 2, 1> B{0, 1};
|
||||
|
||||
// We separate the result of IsStabilizable from the assertion because
|
||||
// templates break gtest.
|
||||
|
||||
// First eigenvalue is uncontrollable and unstable.
|
||||
// Second eigenvalue is controllable and stable.
|
||||
A << 1.2, 0, 0, 0.5;
|
||||
bool ret = frc::IsStabilizable<2, 1>(A, B);
|
||||
Eigen::Matrix<double, 2, 2> A1{{1.2, 0}, {0, 0.5}};
|
||||
bool ret = frc::IsStabilizable<2, 1>(A1, B);
|
||||
EXPECT_FALSE(ret);
|
||||
|
||||
// First eigenvalue is uncontrollable and marginally stable.
|
||||
// Second eigenvalue is controllable and stable.
|
||||
A << 1, 0, 0, 0.5;
|
||||
ret = frc::IsStabilizable<2, 1>(A, B);
|
||||
Eigen::Matrix<double, 2, 2> A2{{1, 0}, {0, 0.5}};
|
||||
ret = frc::IsStabilizable<2, 1>(A2, B);
|
||||
EXPECT_FALSE(ret);
|
||||
|
||||
// First eigenvalue is uncontrollable and stable.
|
||||
// Second eigenvalue is controllable and stable.
|
||||
A << 0.2, 0, 0, 0.5;
|
||||
ret = frc::IsStabilizable<2, 1>(A, B);
|
||||
Eigen::Matrix<double, 2, 2> A3{{0.2, 0}, {0, 0.5}};
|
||||
ret = frc::IsStabilizable<2, 1>(A3, B);
|
||||
EXPECT_TRUE(ret);
|
||||
|
||||
// First eigenvalue is uncontrollable and stable.
|
||||
// Second eigenvalue is controllable and unstable.
|
||||
A << 0.2, 0, 0, 1.2;
|
||||
ret = frc::IsStabilizable<2, 1>(A, B);
|
||||
Eigen::Matrix<double, 2, 2> A4{{0.2, 0}, {0, 1.2}};
|
||||
ret = frc::IsStabilizable<2, 1>(A4, B);
|
||||
EXPECT_TRUE(ret);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user