10 #include <gtest/gtest.h> 14 #include <test_mrpt_common.h> 23 mrpt::UNITTEST_BASEDIR + string(
"/tests/PTGs_for_tests.ini");
26 cerr <<
"**WARNING* Skipping tests since file cannot be found: '" 33 const unsigned int PTG_COUNT =
34 cfg.
read_int(
"PTG_UNIT_TESTS",
"PTG_COUNT", 0,
true);
36 vector<CParameterizedTrajectoryGenerator::Ptr> PTGs(PTG_COUNT);
38 for (
unsigned int n = 0; n < PTG_COUNT; n++)
42 "PTG_UNIT_TESTS",
format(
"PTG%u_Type", n),
"",
true);
43 PTGs[n] = CParameterizedTrajectoryGenerator::CreatePTG(
44 sPTGName, cfg,
"PTG_UNIT_TESTS",
format(
"PTG%u_", n));
45 EXPECT_TRUE(PTGs[n] !=
nullptr) <<
"Failed creating PTG #" << n << endl;
49 PTGs[n]->initialize(
string(),
false );
51 catch (
const std::exception& e)
53 GTEST_FAIL() <<
"Failed initializing PTG #" << n << endl
60 for (
unsigned int n = 0; n < PTG_COUNT; n++)
64 const std::string sPTGDesc = ptg->getDescription();
65 const double refDist = ptg->getRefDistance();
66 const size_t num_paths = ptg->getPathCount();
67 size_t num_tests_run = 0;
71 for (
double dist = 0.1; dist < refDist * 0.5; dist += 0.2)
73 bool any_good =
false;
74 for (
size_t k = 0; k < num_paths; k++)
78 if (ptg->getPathStepForDist(k, dist, step))
81 double d = ptg->getPathDist(k, step);
83 <<
"Test: step <-> dist match\n PTG: " << sPTGDesc
85 <<
"dist:" << dist << endl;
90 <<
"Test: step <-> dist match\n PTG: " << sPTGDesc << endl
91 <<
"dist:" << dist << endl;
98 bool skip_this_ptg =
false;
99 for (
double tx = -refDist * 0.5;
100 !skip_this_ptg && tx < refDist * 0.5; tx += 0.1)
102 for (
double ty = -refDist * 0.5;
103 !skip_this_ptg && ty < refDist * 0.5; ty += 0.1)
105 if (std::abs(tx) < 1e-2 && std::abs(ty) < 1e-2)
109 const double tolerance_dist = std::max(
110 0.10, 10.0 * std::sqrt(tx * tx + ty * ty) *
M_PI * 2 /
111 ptg->getPathCount());
115 bool valid = ptg->inverseMap_WS2TP(tx, ty, k, normalized_d);
116 if (valid && normalized_d < 1.0)
121 bool step_ok = ptg->getPathStepForDist(
122 k, normalized_d * refDist, step);
124 <<
"PTG: " << sPTGDesc << endl
125 <<
"(tx,ty): " << tx <<
" " << ty <<
" k= " << k
126 <<
" normalized_d=" << normalized_d << endl;
130 ptg->getPathPose(k, step, pose);
132 <<
"Test: inverseMap_WS2TP\n PTG#" << n <<
": " 134 <<
"(tx,ty): " << tx <<
" " << ty <<
" k= " << k
135 <<
" normalized_d=" << normalized_d << endl;
137 <<
"Test: inverseMap_WS2TP\n PTG#" << n <<
": " 139 <<
"(tx,ty): " << tx <<
" " << ty <<
" k= " << k
140 <<
" normalized_d=" << normalized_d << endl;
142 if (std::abs(pose.
x - tx) >= tolerance_dist ||
143 std::abs(pose.
y - ty) >= tolerance_dist)
144 skip_this_ptg =
true;
151 EXPECT_TRUE(any_ok) <<
"PTG: " << sPTGDesc << endl;
156 bool skip_this_ptg =
false;
157 bool any_change_all =
false;
158 for (
double ox = -refDist * 0.5;
159 !skip_this_ptg && ox < refDist * 0.5; ox += 0.1)
161 for (
double oy = -refDist * 0.5;
162 !skip_this_ptg && oy < refDist * 0.5; oy += 0.1)
164 if (std::abs(ox) < 1e-2 && std::abs(oy) < 1e-2)
168 std::vector<double> TP_obstacles;
169 ptg->initTPObstacles(TP_obstacles);
171 const std::vector<double> TP_obstacles_org = TP_obstacles;
172 ptg->updateTPObstacle(ox, oy, TP_obstacles);
174 const bool any_change = (TP_obstacles_org != TP_obstacles);
175 if (any_change) any_change_all =
true;
183 "PTG `%50s` run %6u tests.\n", sPTGDesc.c_str(),
184 (
unsigned int)num_tests_run);
EXPECT_TRUE(mrpt::system::fileExists(ini_fil))
std::string read_string(const std::string §ion, const std::string &name, const std::string &defaultValue, bool failIfNotFound=false) const
std::string std::string format(std::string_view fmt, ARGS &&... args)
This class allows loading and storing values and vectors of different types from ".ini" files easily.
bool fileExists(const std::string &fileName)
Test if a given file (or directory) exists.
int read_int(const std::string §ion, const std::string &name, int defaultValue, bool failIfNotFound=false) const
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
TEST(NavTests, PTGs_tests)
EXPECT_NEAR(out.cam_params.rightCameraPose.x, 0.1194, 0.005)