MRPT  2.0.4
KFSLAMApp_unittest.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include <gtest/gtest.h>
11 #include <mrpt/apps/KFSLAMApp.h>
12 #include <mrpt/system/filesystem.h>
13 #include <test_mrpt_common.h>
14 #include <functional>
15 
16 using config_changer_t = std::function<void(mrpt::config::CConfigFileBase&)>;
17 
19  const std::string& ini_filename, const std::string& rawlog_filename,
20  config_changer_t cfg_changer)
21 {
22  using namespace std::string_literals;
23 
24  const auto ini_fil = mrpt::UNITTEST_BASEDIR +
25  "/share/mrpt/config_files/kf-slam/"s + ini_filename;
27 
28  const auto rawlog_fil =
29  mrpt::UNITTEST_BASEDIR + "/share/mrpt/datasets/"s + rawlog_filename;
31 
32  try
33  {
36 
37  const char* argv[] = {"kf-slam", ini_fil.c_str(), rawlog_fil.c_str()};
38  const int argc = sizeof(argv) / sizeof(argv[0]);
39 
40  app.initialize(argc, argv);
41 
42  // Output 3D scenes to a temporary directory:
43  app.params.write(
44  "MappingApplication", "logOutput_dir",
45  mrpt::system::getTempFileName() + "_dir"s);
46 
47  cfg_changer(app.params);
48  app.run();
49 
50  // Check results:
51  EXPECT_LT(app.loc_error_wrt_gt, 0.1);
52  }
53  catch (const std::exception& e)
54  {
55  std::cerr << mrpt::exception_to_str(e);
56  GTEST_FAIL();
57  }
58 }
59 
60 TEST(KFSLAMApp, EKF_SLAM_3D)
61 {
63  "EKF-SLAM_6D_test.ini", "kf-slam_6D_demo.rawlog",
65  using namespace std::string_literals;
66  c.write("MappingApplication", "SHOW_3D_LIVE", false);
67  c.write("MappingApplication", "SAVE_3D_SCENES", true);
68  });
69 }
70 
71 TEST(KFSLAMApp, EKF_SLAM_2D)
72 {
74  "EKF-SLAM_test_2d.ini", "kf-slam_demo.rawlog",
76  using namespace std::string_literals;
77  c.write("MappingApplication", "SHOW_3D_LIVE", false);
78  c.write("MappingApplication", "SAVE_3D_SCENES", true);
79  });
80 }
81 
82 TEST(KFSLAMApp, EKF_SLAM_3D_data_assoc_JCBB_Maha)
83 {
85  "EKF-SLAM_6D_test_datassoc.ini", "kf-slam_6D_demo_DA.rawlog",
87  using namespace std::string_literals;
88  c.write("RangeBearingKFSLAM", "data_assoc_method", "assocJCBB");
89  c.write("RangeBearingKFSLAM", "data_assoc_metric", "metricMaha");
90 
91  c.write("MappingApplication", "SHOW_3D_LIVE", false);
92  c.write("MappingApplication", "SAVE_3D_SCENES", false);
93  });
94 }
95 
96 TEST(KFSLAMApp, EKF_SLAM_3D_data_assoc_NN_Maha)
97 {
99  "EKF-SLAM_6D_test_datassoc.ini", "kf-slam_6D_demo_DA.rawlog",
101  using namespace std::string_literals;
102  c.write("RangeBearingKFSLAM", "data_assoc_method", "assocNN");
103  c.write("RangeBearingKFSLAM", "data_assoc_metric", "metricMaha");
104 
105  c.write("MappingApplication", "SHOW_3D_LIVE", false);
106  c.write("MappingApplication", "SAVE_3D_SCENES", false);
107  });
108 }
EXPECT_LT(out.final_rmse, 3.0)
EXPECT_TRUE(mrpt::system::fileExists(ini_fil))
EKF-SLAM application wrapper class.
Definition: KFSLAMApp.h:23
void initialize(int argc, const char **argv)
Initializes the application from CLI parameters.
Definition: KFSLAMApp.cpp:35
bool fileExists(const std::string &fileName)
Test if a given file (or directory) exists.
Definition: filesystem.cpp:128
void setMinLoggingLevel(const VerbosityLevel level)
Set the minimum logging level for which the incoming logs are going to be taken into account...
mrpt::config::CConfigFileMemory params
Populated in initialize().
Definition: KFSLAMApp.h:52
void run()
Runs with the current parameter set.
Definition: KFSLAMApp.cpp:67
TEST(KFSLAMApp, EKF_SLAM_3D)
This class allows loading and storing values and vectors of different types from a configuration text...
std::string getTempFileName()
Returns the name of a proposed temporary file name.
Definition: filesystem.cpp:283
void generic_kf_slam_test(const std::string &ini_filename, const std::string &rawlog_filename, config_changer_t cfg_changer)
const std::string ini_fil
void write(const std::string &section, const std::string &name, enum_t value, const int name_padding_width=-1, const int value_padding_width=-1, const std::string &comment=std::string())
const char * argv[]
double loc_error_wrt_gt
Average localization error, when supplied with a ground-truth file.
Definition: KFSLAMApp.h:63
std::string exception_to_str(const std::exception &e)
Builds a nice textual representation of a nested exception, which if generated using MRPT macros (THR...
Definition: exceptions.cpp:59
const int argc
std::function< void(mrpt::config::CConfigFileBase &)> config_changer_t



Page generated by Doxygen 1.8.14 for MRPT 2.0.4 Git: 33de1d0ad Sat Jun 20 11:02:42 2020 +0200 at sáb jun 20 17:35:17 CEST 2020