test_kalman.cpp
Go to the documentation of this file.
2 #include <gtest/gtest.h>
3 #include <ros/ros.h>
4 #include <Eigen/Dense>
5 #include <ros/console.h>
6 #include <log4cxx/logger.h>
7 
8 // Declare a test
9 // TEST(TestSuite, testCase1)
10 // {
11 // <test things here, calling EXPECT_* and/or ASSERT_* macros as needed>
12 // }
13 
15 
16 TEST(KalmanFilter, testFunctionality)
17 {
18  KalmanFilter* filter = new KalmanFilter();
19 
20  // configure default namespace: "KalmanFilter"
21  EXPECT_TRUE(filter->configure());
22 
23  const int n = 1, m = 1;
24 
25  const std::vector<double> measurements = {0.39, 0.50, 0.48, 0.29, 0.25, 0.32, 0.34, 0.48, 0.41, 0.45};
26  const std::vector<double> state_estimates = {0., 0.3545454545, 0.4238095238, 0.4419354839, 0.4048780488,
27  0.3745098039, 0.3655737705, 0.361971831, 0.3765432099, 0.3802197802};
28  const std::vector<double> error_cov_estimates = {1., 0.0909090909, 0.0476190476, 0.0322580645,
29  0.0243902439, 0.0196078431, 0.0163934426, 0.014084507, 0.012345679, 0.010989011};
30  const std::vector<double> state_updates = {0.3545454545, 0.4238095238, 0.4419354839, 0.4048780488,
31  0.3745098039, 0.3655737705, 0.361971831, 0.3765432099, 0.3802197802, 0.3871287129};
32  const std::vector<double> error_cov_updates = {0.0909090909, 0.0476190476, 0.0322580645,
33  0.0243902439, 0.0196078431, 0.0163934426, 0.014084507, 0.012345679, 0.010989011, 0.0099009901};
34  const double eps = 0.0001;
35  std::vector<double> measurement, state_out;
36  Eigen::MatrixXd error_cov_out;
37 
38  EXPECT_TRUE(filter->getErrorCovarianceMatrix(error_cov_out));
39  EXPECT_TRUE(filter->getCurrentState(state_out));
40 
41  for (int i = 0; i < measurements.size(); i++)
42  {
43  // configure and check every step
44  if (i != 0)
45  {
46  EXPECT_TRUE(filter->predict(state_out));
47  }
48 
49  EXPECT_TRUE(state_out.size() == 1);
50  EXPECT_NEAR (state_out[0], state_estimates[i], eps);
51 
52  EXPECT_TRUE(filter->getErrorCovarianceMatrix(error_cov_out));
53  EXPECT_TRUE(error_cov_out.size() == 1);
54  EXPECT_NEAR (error_cov_out(0, 0), error_cov_estimates[i], eps);
55 
56  measurement.clear(); measurement.push_back(measurements[i]);
57  EXPECT_TRUE(filter->update(measurement, state_out));
58  EXPECT_TRUE(state_out.size() == 1);
59  EXPECT_NEAR (state_out[0], state_updates[i], eps);
60 
61  EXPECT_TRUE(filter->getErrorCovarianceMatrix(error_cov_out));
62  EXPECT_TRUE(error_cov_out.size() == 1);
63  EXPECT_NEAR (error_cov_out(0, 0), error_cov_updates[i], eps);
64 
65  }
66 }
67 
68 TEST(KalmanFilter, testFunctionalityWithMoreDims)
69 {
70  KalmanFilter* filter = new KalmanFilter();
71 
72  std::string namespace_ = "KalmanFilterMoreDimensions";
73 
74  EXPECT_TRUE(filter->configure(namespace_));
75 }
76 
77 TEST(KalmanFilter, testParameters)
78 {
79  KalmanFilter* filter = new KalmanFilter();
80 
81  const std::vector<std::string> namespaces_with_param_errors = {"KalmanFilterTestWithoutParameters", "KalmanFilterTestDt",
82  "KalmanFilterTestN", "KalmanFilterTestN",
83  "KalmanFilterTestParameterA", "KalmanFilterTestParameterC", "KalmanFilterTestParameterQ",
84  "KalmanFilterTestParameterR", "KalmanFilterTestParameterP", "KalmanFilterTestParameterX0"
85  };
86 
87  for (int i = 0; i < namespaces_with_param_errors.size(); i++)
88  {
89  EXPECT_FALSE(filter->configure(namespaces_with_param_errors[i]));
90  }
91 }
92 
93 // Run all the tests that were declared with TEST()
94 int main(int argc, char **argv){
95 // ROSCONSOLE_AUTOINIT;
96 // log4cxx::LoggerPtr my_logger = log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME);
97 // my_logger->setLevel(ros::console::g_level_lookup[ros::console::levels::Debug]);
98 
99  testing::InitGoogleTest(&argc, argv);
100  ros::init(argc, argv, "tester");
101  ros::NodeHandle nh;
102  return RUN_ALL_TESTS();
103 }
bool getErrorCovarianceMatrix(Eigen::MatrixXd &data_out)
TEST(KalmanFilter, testFunctionality)
Definition: test_kalman.cpp:16
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
bool predict(std::vector< T > &data_out)
bool getCurrentState(std::vector< T > &data_out)
iirob_filters::MultiChannelKalmanFilter< double > KalmanFilter
Definition: test_kalman.cpp:14
virtual bool update(const std::vector< T > &data_in, std::vector< T > &data_out)
int main(int argc, char **argv)
Definition: test_kalman.cpp:94


iirob_filters
Author(s): Denis Štogl
autogenerated on Fri Sep 18 2020 03:32:19