2 #include <gtest/gtest.h> 6 #include <log4cxx/logger.h> 23 const int n = 1, m = 1;
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;
41 for (
int i = 0; i < measurements.size(); i++)
46 EXPECT_TRUE(filter->
predict(state_out));
49 EXPECT_TRUE(state_out.size() == 1);
50 EXPECT_NEAR (state_out[0], state_estimates[i], eps);
53 EXPECT_TRUE(error_cov_out.size() == 1);
54 EXPECT_NEAR (error_cov_out(0, 0), error_cov_estimates[i], eps);
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);
62 EXPECT_TRUE(error_cov_out.size() == 1);
63 EXPECT_NEAR (error_cov_out(0, 0), error_cov_updates[i], eps);
72 std::string namespace_ =
"KalmanFilterMoreDimensions";
74 EXPECT_TRUE(filter->
configure(namespace_));
81 const std::vector<std::string> namespaces_with_param_errors = {
"KalmanFilterTestWithoutParameters",
"KalmanFilterTestDt",
82 "KalmanFilterTestN",
"KalmanFilterTestN",
83 "KalmanFilterTestParameterA",
"KalmanFilterTestParameterC",
"KalmanFilterTestParameterQ",
84 "KalmanFilterTestParameterR",
"KalmanFilterTestParameterP",
"KalmanFilterTestParameterX0" 87 for (
int i = 0; i < namespaces_with_param_errors.size(); i++)
89 EXPECT_FALSE(filter->
configure(namespaces_with_param_errors[i]));
94 int main(
int argc,
char **argv){
99 testing::InitGoogleTest(&argc, argv);
102 return RUN_ALL_TESTS();
bool getErrorCovarianceMatrix(Eigen::MatrixXd &data_out)
TEST(KalmanFilter, testFunctionality)
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
virtual bool update(const std::vector< T > &data_in, std::vector< T > &data_out)
int main(int argc, char **argv)