mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51: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:
@@ -9,9 +9,9 @@
|
||||
#include "frc/system/RungeKuttaTimeVarying.h"
|
||||
|
||||
namespace {
|
||||
Eigen::Vector<double, 1> RungeKuttaTimeVaryingSolution(double t) {
|
||||
return Eigen::Vector<double, 1>{12.0 * std::exp(t) /
|
||||
(std::pow(std::exp(t) + 1.0, 2.0))};
|
||||
frc::Vectord<1> RungeKuttaTimeVaryingSolution(double t) {
|
||||
return frc::Vectord<1>{12.0 * std::exp(t) /
|
||||
(std::pow(std::exp(t) + 1.0, 2.0))};
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@@ -23,12 +23,12 @@ Eigen::Vector<double, 1> RungeKuttaTimeVaryingSolution(double t) {
|
||||
//
|
||||
// x(t) = 12 * e^t / ((e^t + 1)^2)
|
||||
TEST(RungeKuttaTimeVaryingTest, RungeKuttaTimeVarying) {
|
||||
Eigen::Vector<double, 1> y0 = RungeKuttaTimeVaryingSolution(5.0);
|
||||
frc::Vectord<1> y0 = RungeKuttaTimeVaryingSolution(5.0);
|
||||
|
||||
Eigen::Vector<double, 1> y1 = frc::RungeKuttaTimeVarying(
|
||||
[](units::second_t t, const Eigen::Vector<double, 1>& x) {
|
||||
return Eigen::Vector<double, 1>{
|
||||
x(0) * (2.0 / (std::exp(t.value()) + 1.0) - 1.0)};
|
||||
frc::Vectord<1> y1 = frc::RungeKuttaTimeVarying(
|
||||
[](units::second_t t, const frc::Vectord<1>& x) {
|
||||
return frc::Vectord<1>{x(0) *
|
||||
(2.0 / (std::exp(t.value()) + 1.0) - 1.0)};
|
||||
},
|
||||
5_s, y0, 1_s);
|
||||
EXPECT_NEAR(y1(0), RungeKuttaTimeVaryingSolution(6.0)(0), 1e-3);
|
||||
|
||||
Reference in New Issue
Block a user