unscented_kalman_filter_test.cc
Go to the documentation of this file.
1 /*
2  * Copyright 2016 The Cartographer Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
20 #include "gtest/gtest.h"
21 
22 namespace cartographer {
23 namespace kalman_filter {
24 namespace {
25 
26 Eigen::Matrix<double, 1, 1> Scalar(double value) {
27  return value * Eigen::Matrix<double, 1, 1>::Identity();
28 }
29 
30 // A simple model that copies the first to the second state variable.
31 Eigen::Matrix<double, 2, 1> g(const Eigen::Matrix<double, 2, 1>& state) {
32  Eigen::Matrix<double, 2, 1> new_state;
33  new_state << state[0], state[0];
34  return new_state;
35 }
36 
37 // A simple observation of the first state variable.
38 Eigen::Matrix<double, 1, 1> h(const Eigen::Matrix<double, 2, 1>& state) {
39  return Scalar(state[0]) - Scalar(5.);
40 }
41 
42 TEST(KalmanFilterTest, testConstructor) {
43  UnscentedKalmanFilter<double, 2> filter(GaussianDistribution<double, 2>(
44  Eigen::Vector2d(0., 42.), 10. * Eigen::Matrix2d::Identity()));
45  EXPECT_NEAR(42., filter.GetBelief().GetMean()[1], 1e-9);
46 }
47 
48 TEST(KalmanFilterTest, testPredict) {
49  UnscentedKalmanFilter<double, 2> filter(GaussianDistribution<double, 2>(
50  Eigen::Vector2d(42., 0.), 10. * Eigen::Matrix2d::Identity()));
51  filter.Predict(
52  g, GaussianDistribution<double, 2>(Eigen::Vector2d(0., 0.),
53  Eigen::Matrix2d::Identity() * 1e-9));
54  EXPECT_NEAR(filter.GetBelief().GetMean()[0], 42., 1e-2);
55  EXPECT_NEAR(filter.GetBelief().GetMean()[1], 42., 1e-2);
56 }
57 
58 TEST(KalmanFilterTest, testObserve) {
59  UnscentedKalmanFilter<double, 2> filter(GaussianDistribution<double, 2>(
60  Eigen::Vector2d(0., 42.), 10. * Eigen::Matrix2d::Identity()));
61  for (int i = 0; i < 500; ++i) {
62  filter.Predict(
63  g, GaussianDistribution<double, 2>(Eigen::Vector2d(0., 0.),
64  Eigen::Matrix2d::Identity() * 1e-9));
65  filter.Observe<1>(
66  h, GaussianDistribution<double, 1>(Scalar(0.), Scalar(1e-2)));
67  }
68  EXPECT_NEAR(filter.GetBelief().GetMean()[0], 5, 1e-2);
69  EXPECT_NEAR(filter.GetBelief().GetMean()[1], 5, 1e-2);
70 }
71 
72 } // namespace
73 } // namespace kalman_filter
74 } // namespace cartographer
float value


cartographer
Author(s):
autogenerated on Wed Jun 5 2019 21:57:59