blob: 6046c37c5266b56ce095cbe0b1125f26ad994a24 [file] [log] [blame]
Austin Schuha647d602018-02-18 14:05:15 -08001#include "frc971/control_loops/jacobian.h"
2
3#include "gtest/gtest.h"
4
5namespace frc971 {
6namespace control_loops {
7namespace 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.
23TEST(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.
31TEST(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