34 #include <gtest/gtest.h> 43 const auto nearest = path.
findNearest(path.begin(), path.end(), p);
44 const Eigen::Vector2d pos_on_line =
46 return path.
remainedDistance(path.begin(), nearest, path.end(), pos_on_line);
50 TEST(Path2D, RemainedDistance)
53 for (
double x = 0.0;
x < 10.0 - 1e-3;
x += 0.2)
58 for (
size_t l = 2; l < path_full.size(); ++l)
62 std::copy(path_full.end() - l, path_full.end(), path.begin());
64 std::string err_msg =
"failed for " + std::to_string(l) +
" pose(s) path";
66 ASSERT_NEAR(getRemainedDistance(path, Eigen::Vector2d(0, 0)), 10.0, 1e-2) << err_msg;
68 ASSERT_NEAR(getRemainedDistance(path, Eigen::Vector2d(8.25, 0)), 1.75, 1e-2) << err_msg;
69 ASSERT_NEAR(getRemainedDistance(path, Eigen::Vector2d(10.25, 0)), -0.25, 1e-2) << err_msg;
71 ASSERT_NEAR(getRemainedDistance(path, Eigen::Vector2d(8.25, 0.1)), 1.75, 1e-2) << err_msg;
72 ASSERT_NEAR(getRemainedDistance(path, Eigen::Vector2d(8.25, -0.1)), 1.75, 1e-2) << err_msg;
73 ASSERT_NEAR(getRemainedDistance(path, Eigen::Vector2d(10.25, 0.1)), -0.25, 1e-2) << err_msg;
74 ASSERT_NEAR(getRemainedDistance(path, Eigen::Vector2d(10.25, -0.1)), -0.25, 1e-2) << err_msg;
80 for (
float c = 1.0; c < 4.0; c += 0.4)
83 for (
double a = 0; a < 1.57; a += 0.1)
86 ASSERT_NEAR(path.
getCurvature(path.begin(), path.end(), path[0].pos_, 10.0), 1.0 / c, 1e-2);
90 TEST(Path2D, LocalGoalWithoutSwitchBack)
92 for (
int yaw_i = -1; yaw_i <= 1; ++yaw_i)
94 const double yaw_diff = yaw_i * 0.1;
97 Eigen::Vector2d p(0, 0);
99 for (
int i = 0; i < 10; ++i)
101 p -= Eigen::Vector2d(std::cos(yaw), std::sin(yaw)) * 0.1;
105 ASSERT_EQ(path.
findLocalGoal(path.begin(), path.end(),
true), path.end());
106 ASSERT_EQ(path.
findLocalGoal(path.begin(), path.end(),
false), path.end());
110 TEST(Path2D, LocalGoalWithSwitchBack)
112 for (
int yaw_i = -1; yaw_i <= 1; ++yaw_i)
114 const double yaw_diff = yaw_i * 0.1;
117 Eigen::Vector2d p(0, 0);
119 for (
int i = 0; i < 5; ++i)
121 p -= Eigen::Vector2d(std::cos(yaw), std::sin(yaw)) * 0.1;
125 for (
int i = 0; i < 5; ++i)
127 p += Eigen::Vector2d(std::cos(yaw), std::sin(yaw)) * 0.1;
131 const auto it_local_goal = path.
findLocalGoal(path.begin(), path.end(),
true);
132 ASSERT_EQ(it_local_goal, path.begin() + 5);
133 ASSERT_EQ(path.
findLocalGoal(it_local_goal, path.end(),
true), path.end());
136 ASSERT_EQ(path.
findLocalGoal(path.begin(), path.end(),
false), path.end());
140 int main(
int argc,
char** argv)
142 testing::InitGoogleTest(&argc, argv);
144 return RUN_ALL_TESTS();
double remainedDistance(const ConstIterator &begin, const ConstIterator &nearest, const ConstIterator &end, const Eigen::Vector2d &target_on_line) const
int main(int argc, char **argv)
TEST(Path2D, RemainedDistance)
ConstIterator findLocalGoal(const ConstIterator &begin, const ConstIterator &end, const bool allow_backward_motion) const
float getCurvature(const ConstIterator &begin, const ConstIterator &end, const Eigen::Vector2d &target_on_line, const float max_search_range) const
TFSIMD_FORCE_INLINE const tfScalar & x() const
Eigen::Vector2d projection2d(const Eigen::Vector2d &a, const Eigen::Vector2d &b, const Eigen::Vector2d &c)
ConstIterator findNearest(const ConstIterator &begin, const ConstIterator &end, const Eigen::Vector2d &target, const float max_search_range=0) const