[wpimath] Replace frc/EigenCore.h typedefs with Eigen's where possible (#5597)

This commit is contained in:
Tyler Veness
2023-08-31 11:03:37 -07:00
committed by GitHub
parent 383289bc4b
commit 99f66b1e24
25 changed files with 79 additions and 80 deletions

View File

@@ -30,17 +30,17 @@ TEST(EigenTest, Multiplication) {
}
TEST(EigenTest, Transpose) {
frc::Vectord<3> vec{1, 2, 3};
Eigen::Vector3d vec{1, 2, 3};
const auto transpose = vec.transpose();
Eigen::RowVector<double, 3> expectedTranspose{1, 2, 3};
Eigen::RowVector3d expectedTranspose{1, 2, 3};
EXPECT_TRUE(expectedTranspose.isApprox(transpose));
}
TEST(EigenTest, Inverse) {
frc::Matrixd<3, 3> mat{{1.0, 3.0, 2.0}, {5.0, 2.0, 1.5}, {0.0, 1.3, 2.5}};
Eigen::Matrix3d mat{{1.0, 3.0, 2.0}, {5.0, 2.0, 1.5}, {0.0, 1.3, 2.5}};
const auto inverse = mat.inverse();
const auto identity = Eigen::MatrixXd::Identity(3, 3);

View File

@@ -4,9 +4,9 @@
#include <cmath>
#include <Eigen/Core>
#include <gtest/gtest.h>
#include "frc/EigenCore.h"
#include "frc/controller/DifferentialDriveFeedforward.h"
#include "frc/controller/LinearPlantInversionFeedforward.h"
#include "frc/system/plant/LinearSystemId.h"
@@ -38,9 +38,9 @@ TEST(DifferentialDriveFeedforwardTest, CalculateWithTrackwidth) {
auto [left, right] = differentialDriveFeedforward.Calculate(
currentLeftVelocity, nextLeftVelocity, currentRightVelocity,
nextRightVelocity, dt);
frc::Matrixd<2, 1> nextX = plant.CalculateX(
frc::Vectord<2>{currentLeftVelocity, currentRightVelocity},
frc::Vectord<2>{left, right}, dt);
Eigen::Vector2d nextX = plant.CalculateX(
Eigen::Vector2d{currentLeftVelocity, currentRightVelocity},
Eigen::Vector2d{left, right}, dt);
EXPECT_NEAR(nextX(0), nextLeftVelocity.value(), 1e-6);
EXPECT_NEAR(nextX(1), nextRightVelocity.value(), 1e-6);
}
@@ -72,9 +72,9 @@ TEST(DifferentialDriveFeedforwardTest, CalculateWithoutTrackwidth) {
auto [left, right] = differentialDriveFeedforward.Calculate(
currentLeftVelocity, nextLeftVelocity, currentRightVelocity,
nextRightVelocity, dt);
frc::Matrixd<2, 1> nextX = plant.CalculateX(
frc::Vectord<2>{currentLeftVelocity, currentRightVelocity},
frc::Vectord<2>{left, right}, dt);
Eigen::Vector2d nextX = plant.CalculateX(
Eigen::Vector2d{currentLeftVelocity, currentRightVelocity},
Eigen::Vector2d{left, right}, dt);
EXPECT_NEAR(nextX(0), nextLeftVelocity.value(), 1e-6);
EXPECT_NEAR(nextX(1), nextRightVelocity.value(), 1e-6);
}

View File

@@ -5,10 +5,10 @@
#include <cmath>
#include <numbers>
#include <Eigen/Core>
#include <gtest/gtest.h>
#include <wpi/MathExtras.h>
#include "frc/EigenCore.h"
#include "frc/geometry/Rotation3d.h"
using namespace frc;
@@ -73,25 +73,25 @@ TEST(Rotation3dTest, InitAxisAngleAndRollPitchYaw) {
TEST(Rotation3dTest, InitRotationMatrix) {
// No rotation
const Matrixd<3, 3> R1 = Matrixd<3, 3>::Identity();
const Eigen::Matrix3d R1 = Eigen::Matrix3d::Identity();
const Rotation3d rot1{R1};
EXPECT_EQ(Rotation3d{}, rot1);
// 90 degree CCW rotation around z-axis
Matrixd<3, 3> R2;
R2.block<3, 1>(0, 0) = Vectord<3>{0.0, 1.0, 0.0};
R2.block<3, 1>(0, 1) = Vectord<3>{-1.0, 0.0, 0.0};
R2.block<3, 1>(0, 2) = Vectord<3>{0.0, 0.0, 1.0};
Eigen::Matrix3d R2;
R2.block<3, 1>(0, 0) = Eigen::Vector3d{0.0, 1.0, 0.0};
R2.block<3, 1>(0, 1) = Eigen::Vector3d{-1.0, 0.0, 0.0};
R2.block<3, 1>(0, 2) = Eigen::Vector3d{0.0, 0.0, 1.0};
const Rotation3d rot2{R2};
const Rotation3d expected2{0_deg, 0_deg, 90_deg};
EXPECT_EQ(expected2, rot2);
// Matrix that isn't orthogonal
const Matrixd<3, 3> R3{{1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}};
const Eigen::Matrix3d R3{{1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}};
EXPECT_THROW(Rotation3d{R3}, std::domain_error);
// Matrix that's orthogonal but not special orthogonal
const Matrixd<3, 3> R4 = Matrixd<3, 3>::Identity() * 2.0;
const Eigen::Matrix3d R4 = Eigen::Matrix3d::Identity() * 2.0;
EXPECT_THROW(Rotation3d{R4}, std::domain_error);
}

View File

@@ -6,6 +6,7 @@
#include <gtest/gtest.h>
#include "frc/EigenCore.h"
#include "frc/system/NumericalIntegration.h"
// Tests that integrating dx/dt = e^x works.

View File

@@ -6,6 +6,7 @@
#include <gtest/gtest.h>
#include "frc/EigenCore.h"
#include "frc/system/RungeKuttaTimeVarying.h"
namespace {