13 #include <gtest/gtest.h> 31 string(
"/tests/PTGs_for_tests.ini");
34 cerr <<
"**WARNING* Skipping tests since file cannot be found: '" 41 const unsigned int PTG_COUNT =
42 cfg.
read_int(
"PTG_UNIT_TESTS",
"PTG_COUNT", 0,
true);
43 EXPECT_TRUE(PTG_COUNT > 0);
44 vector<CParameterizedTrajectoryGenerator*> PTGs(PTG_COUNT);
46 for (
unsigned int n = 0;
n < PTG_COUNT;
n++)
50 "PTG_UNIT_TESTS",
format(
"PTG%u_Type",
n),
"",
true);
51 PTGs[
n] = CParameterizedTrajectoryGenerator::CreatePTG(
52 sPTGName, cfg,
"PTG_UNIT_TESTS",
format(
"PTG%u_",
n));
53 EXPECT_TRUE(PTGs[
n] !=
nullptr) <<
"Failed creating PTG #" <<
n << endl;
57 PTGs[
n]->initialize(
string(),
false );
59 catch (std::exception& e)
61 GTEST_FAIL() <<
"Failed initializing PTG #" <<
n << endl
68 for (
unsigned int n = 0;
n < PTG_COUNT;
n++)
75 size_t num_tests_run = 0;
79 for (
double dist = 0.1; dist < refDist * 0.5; dist += 0.2)
81 bool any_good =
false;
82 for (
size_t k = 0; k < num_paths; k++)
90 EXPECT_NEAR(d, dist, 0.05)
91 <<
"Test: step <-> dist match\n PTG: " << sPTGDesc
93 <<
"dist:" << dist << endl;
98 <<
"Test: step <-> dist match\n PTG: " << sPTGDesc << endl
99 <<
"dist:" << dist << endl;
106 bool skip_this_ptg =
false;
107 for (
double tx = -refDist * 0.5;
108 !skip_this_ptg && tx < refDist * 0.5; tx += 0.1)
110 for (
double ty = -refDist * 0.5;
111 !skip_this_ptg &&
ty < refDist * 0.5;
ty += 0.1)
113 if (std::abs(tx) < 1e-2 && std::abs(
ty) < 1e-2)
117 const double tolerance_dist = std::max(
118 0.10, 10.0 * std::sqrt(tx * tx +
ty *
ty) *
M_PI * 2 /
124 if (valid && normalized_d < 1.0)
130 k, normalized_d * refDist, step);
132 <<
"PTG: " << sPTGDesc << endl
133 <<
"(tx,ty): " << tx <<
" " <<
ty <<
" k= " << k
134 <<
" normalized_d=" << normalized_d << endl;
139 EXPECT_NEAR(pose.
x, tx, tolerance_dist)
140 <<
"Test: inverseMap_WS2TP\n PTG#" <<
n <<
": " 142 <<
"(tx,ty): " << tx <<
" " <<
ty <<
" k= " << k
143 <<
" normalized_d=" << normalized_d << endl;
144 EXPECT_NEAR(pose.
y,
ty, tolerance_dist)
145 <<
"Test: inverseMap_WS2TP\n PTG#" <<
n <<
": " 147 <<
"(tx,ty): " << tx <<
" " <<
ty <<
" k= " << k
148 <<
" normalized_d=" << normalized_d << endl;
150 if (std::abs(pose.
x - tx) >= tolerance_dist ||
151 std::abs(pose.
y -
ty) >= tolerance_dist)
152 skip_this_ptg =
true;
159 EXPECT_TRUE(any_ok) <<
"PTG: " << sPTGDesc << endl;
164 bool skip_this_ptg =
false;
165 bool any_change_all =
false;
166 for (
double ox = -refDist * 0.5;
167 !skip_this_ptg && ox < refDist * 0.5; ox += 0.1)
169 for (
double oy = -refDist * 0.5;
170 !skip_this_ptg && oy < refDist * 0.5; oy += 0.1)
172 if (std::abs(ox) < 1e-2 && std::abs(oy) < 1e-2)
176 std::vector<double> TP_obstacles;
179 const std::vector<double> TP_obstacles_org = TP_obstacles;
182 const bool any_change = (TP_obstacles_org != TP_obstacles);
183 if (any_change) any_change_all =
true;
187 EXPECT_TRUE(any_change_all);
191 "PTG `%50s` run %6u tests.\n", sPTGDesc.c_str(),
192 (
unsigned int)num_tests_run);
197 for (
unsigned int n = 0;
n < PTG_COUNT;
n++)
delete PTGs[
n];
virtual bool getPathStepForDist(uint16_t k, double dist, uint32_t &out_step) const =0
Access path k ([0,N-1]=>[-pi,pi] in alpha): largest step count for which the traversed distance is < ...
std::string MRPT_GLOBAL_UNITTEST_SRC_DIR
double getRefDistance() const
This class allows loading and storing values and vectors of different types from ".ini" files easily.
void initTPObstacles(std::vector< double > &TP_Obstacles) const
Resizes and populates the initial appropriate contents in a vector of tp-obstacles (collision-free ra...
bool fileExists(const std::string &fileName)
Test if a given file (or directory) exists.
std::string read_string(const std::string §ion, const std::string &name, const std::string &defaultValue, bool failIfNotFound=false) const
uint16_t getPathCount() const
Get the number of different, discrete paths in this family.
virtual double getPathDist(uint16_t k, uint32_t step) const =0
Access path k ([0,N-1]=>[-pi,pi] in alpha): traversed distance at discrete step step.
virtual void getPathPose(uint16_t k, uint32_t step, mrpt::math::TPose2D &p) const =0
Access path k ([0,N-1]=>[-pi,pi] in alpha): pose of the vehicle at discrete step step.
int read_int(const std::string §ion, const std::string &name, int defaultValue, bool failIfNotFound=false) const
This is the base class for any user-defined PTG.
GLsizei const GLchar ** string
virtual void updateTPObstacle(double ox, double oy, std::vector< double > &tp_obstacles) const =0
Updates the radial map of closest TP-Obstacles given a single obstacle point at (ox,oy)
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
GLenum GLsizei GLenum format
TEST(NavTests, PTGs_tests)
unsigned __int32 uint32_t
virtual bool inverseMap_WS2TP(double x, double y, int &out_k, double &out_normalized_d, double tolerance_dist=0.10) const =0
Computes the closest (alpha,d) TP coordinates of the trajectory point closest to the Workspace (WS) C...
virtual std::string getDescription() const =0
Gets a short textual description of the PTG and its parameters.