mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-23 01:21:42 +00:00
[wpimath] Add typedefs for common types
This makes complex code significantly easier to read. frc::Vectord<Size> = Eigen::Vector<double, Size> frc::Matrixd<Rows, Cols> = Eigen::Matrix<double, Rows, Cols>
This commit is contained in:
@@ -10,48 +10,46 @@
|
||||
|
||||
// Tests that integrating dx/dt = e^x works.
|
||||
TEST(NumericalIntegrationTest, Exponential) {
|
||||
Eigen::Vector<double, 1> y0{0.0};
|
||||
frc::Vectord<1> y0{0.0};
|
||||
|
||||
Eigen::Vector<double, 1> y1 = frc::RK4(
|
||||
[](const Eigen::Vector<double, 1>& x) {
|
||||
return Eigen::Vector<double, 1>{std::exp(x(0))};
|
||||
},
|
||||
frc::Vectord<1> y1 = frc::RK4(
|
||||
[](const frc::Vectord<1>& x) { return frc::Vectord<1>{std::exp(x(0))}; },
|
||||
y0, 0.1_s);
|
||||
EXPECT_NEAR(y1(0), std::exp(0.1) - std::exp(0), 1e-3);
|
||||
}
|
||||
|
||||
// Tests that integrating dx/dt = e^x works when we provide a U.
|
||||
TEST(NumericalIntegrationTest, ExponentialWithU) {
|
||||
Eigen::Vector<double, 1> y0{0.0};
|
||||
frc::Vectord<1> y0{0.0};
|
||||
|
||||
Eigen::Vector<double, 1> y1 = frc::RK4(
|
||||
[](const Eigen::Vector<double, 1>& x, const Eigen::Vector<double, 1>& u) {
|
||||
return Eigen::Vector<double, 1>{std::exp(u(0) * x(0))};
|
||||
frc::Vectord<1> y1 = frc::RK4(
|
||||
[](const frc::Vectord<1>& x, const frc::Vectord<1>& u) {
|
||||
return frc::Vectord<1>{std::exp(u(0) * x(0))};
|
||||
},
|
||||
y0, Eigen::Vector<double, 1>{1.0}, 0.1_s);
|
||||
y0, frc::Vectord<1>{1.0}, 0.1_s);
|
||||
EXPECT_NEAR(y1(0), std::exp(0.1) - std::exp(0), 1e-3);
|
||||
}
|
||||
|
||||
// Tests that integrating dx/dt = e^x works with RKF45.
|
||||
TEST(NumericalIntegrationTest, ExponentialRKF45) {
|
||||
Eigen::Vector<double, 1> y0{0.0};
|
||||
frc::Vectord<1> y0{0.0};
|
||||
|
||||
Eigen::Vector<double, 1> y1 = frc::RKF45(
|
||||
[](const Eigen::Vector<double, 1>& x, const Eigen::Vector<double, 1>& u) {
|
||||
return Eigen::Vector<double, 1>{std::exp(x(0))};
|
||||
frc::Vectord<1> y1 = frc::RKF45(
|
||||
[](const frc::Vectord<1>& x, const frc::Vectord<1>& u) {
|
||||
return frc::Vectord<1>{std::exp(x(0))};
|
||||
},
|
||||
y0, Eigen::Vector<double, 1>{0.0}, 0.1_s);
|
||||
y0, frc::Vectord<1>{0.0}, 0.1_s);
|
||||
EXPECT_NEAR(y1(0), std::exp(0.1) - std::exp(0), 1e-3);
|
||||
}
|
||||
|
||||
// Tests that integrating dx/dt = e^x works with RKDP
|
||||
TEST(NumericalIntegrationTest, ExponentialRKDP) {
|
||||
Eigen::Vector<double, 1> y0{0.0};
|
||||
frc::Vectord<1> y0{0.0};
|
||||
|
||||
Eigen::Vector<double, 1> y1 = frc::RKDP(
|
||||
[](const Eigen::Vector<double, 1>& x, const Eigen::Vector<double, 1>& u) {
|
||||
return Eigen::Vector<double, 1>{std::exp(x(0))};
|
||||
frc::Vectord<1> y1 = frc::RKDP(
|
||||
[](const frc::Vectord<1>& x, const frc::Vectord<1>& u) {
|
||||
return frc::Vectord<1>{std::exp(x(0))};
|
||||
},
|
||||
y0, Eigen::Vector<double, 1>{0.0}, 0.1_s);
|
||||
y0, frc::Vectord<1>{0.0}, 0.1_s);
|
||||
EXPECT_NEAR(y1(0), std::exp(0.1) - std::exp(0), 1e-3);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user