Austin Schuh | a647d60 | 2018-02-18 14:05:15 -0800 | [diff] [blame] | 1 | #include "frc971/control_loops/jacobian.h" |
| 2 | |
| 3 | #include "gtest/gtest.h" |
| 4 | |
| 5 | namespace frc971 { |
| 6 | namespace control_loops { |
| 7 | namespace testing { |
| 8 | |
| 9 | ::Eigen::Matrix<double, 4, 4> A = (::Eigen::Matrix<double, 4, 4>() << 1, 2, 4, |
| 10 | 1, 5, 2, 3, 4, 5, 1, 3, 2, 1, 1, 3, |
| 11 | 7).finished(); |
| 12 | |
| 13 | ::Eigen::Matrix<double, 4, 2> B = |
| 14 | (::Eigen::Matrix<double, 4, 2>() << 1, 1, 2, 1, 3, 2, 3, 7).finished(); |
| 15 | |
| 16 | // Function to recover A and B from. |
| 17 | ::Eigen::Matrix<double, 4, 1> AxBufn(const ::Eigen::Matrix<double, 4, 1> &X, |
| 18 | const ::Eigen::Matrix<double, 2, 1> &U) { |
| 19 | return A * X + B * U; |
| 20 | } |
| 21 | |
| 22 | // Test that we can recover A from AxBufn pretty accurately. |
| 23 | TEST(RungeKuttaTest, Ax) { |
| 24 | ::Eigen::Matrix<double, 4, 4> NewA = |
| 25 | NumericalJacobianX<4, 2>(AxBufn, ::Eigen::Matrix<double, 4, 1>::Zero(), |
| 26 | ::Eigen::Matrix<double, 2, 1>::Zero()); |
| 27 | EXPECT_TRUE(NewA.isApprox(A)); |
| 28 | } |
| 29 | |
| 30 | // Test that we can recover B from AxBufn pretty accurately. |
| 31 | TEST(RungeKuttaTest, Bu) { |
| 32 | ::Eigen::Matrix<double, 4, 2> NewB = |
| 33 | NumericalJacobianU<4, 2>(AxBufn, ::Eigen::Matrix<double, 4, 1>::Zero(), |
| 34 | ::Eigen::Matrix<double, 2, 1>::Zero()); |
| 35 | EXPECT_TRUE(NewB.isApprox(B)); |
| 36 | } |
| 37 | |
| 38 | } // namespace testing |
| 39 | } // namespace control_loops |
| 40 | } // namespace frc971 |