test_ekf.cpp
Go to the documentation of this file.
00001 #include "robot_localization/ekf.h"
00002 
00003 #include <gtest/gtest.h>
00004 
00005 TEST (EkfTest, Measurements)
00006 {
00007   RobotLocalization::Ekf ekf;
00008 
00009   Eigen::VectorXd measurement(12);
00010   for(size_t i = 0; i < 12; ++i)
00011   {
00012     measurement[i] = i;
00013   }
00014 
00015   Eigen::MatrixXd measurementCovariance(12, 12);
00016   for(size_t i = 0; i < 12; ++i)
00017   {
00018     measurementCovariance(i, i) = 0.5;
00019   }
00020 
00021   std::vector<int> updateVector(12, true);
00022 
00023   // Ensure that measurements are being placed in the queue correctly
00024   ekf.enqueueMeasurement("odom0",
00025                          measurement,
00026                          measurementCovariance,
00027                          updateVector,
00028                          1000);
00029 
00030   std::map<std::string, Eigen::VectorXd> postUpdateStates;
00031 
00032   ekf.integrateMeasurements(1001,
00033                             postUpdateStates);
00034 
00035   EXPECT_EQ(ekf.getState(), measurement);
00036   EXPECT_EQ(ekf.getEstimateErrorCovariance(), measurementCovariance);
00037 
00038   // Now fuse another measurement and check the output.
00039   // We know what the filter's state should be when
00040   // this is complete, so we'll check the difference and
00041   // make sure it's suitably small.
00042   Eigen::VectorXd measurement2 = measurement;
00043 
00044   measurement2 *= 2.0;
00045 
00046   ekf.enqueueMeasurement("odom0",
00047                          measurement,
00048                          measurementCovariance,
00049                          updateVector,
00050                          1002);
00051 
00052   ekf.integrateMeasurements(1003,
00053                             postUpdateStates);
00054 
00055   measurement[0] = -2.8975;
00056   measurement[1] = -0.42068;
00057   measurement[2] = 5.5751;
00058   measurement[3] = 2.7582;
00059   measurement[4] = -2.0858;
00060   measurement[5] = -2.0859;
00061   measurement[6] = 3.7596;
00062   measurement[7] = 4.3694;
00063   measurement[8] = 5.1206;
00064   measurement[9] = 9.2408;
00065   measurement[10] = 9.8034;
00066   measurement[11] = 11.796;
00067 
00068   measurement = measurement.eval() - ekf.getState();
00069 
00070   for(size_t i = 0; i < 12; ++i)
00071   {
00072     EXPECT_LT(::fabs(measurement[i]), 0.001);
00073   }
00074 }
00075 
00076 int main(int argc, char **argv)
00077 {
00078   testing::InitGoogleTest(&argc, argv);
00079   return RUN_ALL_TESTS();
00080 }


robot_localization
Author(s): Tom Moore
autogenerated on Mon Oct 6 2014 04:11:15