30 #include <gtest/gtest.h>
35 #include <unordered_map>
38 #include <nav_msgs/Path.h>
56 .switch_back_prediction_sec_ = 2.0,
78 for (
int a = 0; a < static_cast<int>(
map_info_.angle); ++a)
80 for (
int y = 0; y < static_cast<int>(
map_info_.height); ++y)
82 for (
int x = 0; x < static_cast<int>(
map_info_.width); ++x)
89 const std::list<StartPosePredictor::Astar::Vec> path_grid_straight =
97 const std::list<StartPosePredictor::Astar::Vec> path_grid_switch_back =
113 nav_msgs::Path result_path;
114 result_path.header.frame_id =
"map";
115 for (
const auto& pose_grid : path_interpolated)
117 geometry_msgs::PoseStamped pose;
118 pose.header.frame_id =
"map";
121 pose.pose =
getPose(x, y, yaw);
122 result_path.poses.push_back(pose);
127 geometry_msgs::Pose
getPose(
const double x,
const double y,
const double yaw)
const
129 geometry_msgs::Pose pose;
132 pose.orientation.z = std::sin(yaw / 2);
133 pose.orientation.w = std::cos(yaw / 2);
142 std::unordered_map<std::string, std::pair<std::list<StartPosePredictor::Astar::Vec>, nav_msgs::Path>>
paths_;
149 EXPECT_FALSE(predictor_.process(getPose(0.0, 0.0, 0.0), cm_, map_info_, nav_msgs::Path(), start_grid));
152 EXPECT_FALSE(predictor_.process(getPose(0.0, 0.5, 0.0), cm_, map_info_,
153 paths_[
"straight"].second, start_grid));
156 nav_msgs::Path rotating_path;
157 rotating_path.header.frame_id =
"map";
158 rotating_path.poses.resize(1);
159 rotating_path.poses[0].header.frame_id =
"map";
160 rotating_path.poses[0].pose = getPose(0.01, 1.01, M_PI / 2);
162 EXPECT_TRUE(predictor_.process(getPose(0.0, 1.0, 1.3), cm_, map_info_, rotating_path, start_grid));
164 EXPECT_TRUE(predictor_.getPreservedPath().poses.empty());
171 EXPECT_TRUE(predictor_.process(getPose(0.05, 0.05, 0.0), cm_, map_info_, paths_[
"straight"].second, start_grid));
173 const auto preserved_path = predictor_.getPreservedPath();
175 ASSERT_EQ(preserved_path.poses.size(), 9);
176 for (
size_t i = 0; i < preserved_path.poses.size(); ++i)
178 const auto& path_pose = preserved_path.poses[i].pose;
179 EXPECT_NEAR(path_pose.position.x, 0.1f * (i + 1), 1.0e-6);
180 EXPECT_NEAR(path_pose.position.y, 0.0, 1.0e-6);
181 EXPECT_NEAR(
tf2::getYaw(path_pose.orientation), 0.0, 1.0e-6);
183 EXPECT_NEAR(predictor_.getPreservedPathLength(), 0.9, 1.0e-6);
187 EXPECT_TRUE(predictor_.process(getPose(-0.05, 0.05, 0.0), cm_, map_info_, paths_[
"straight"].second, start_grid));
189 const auto preserved_path = predictor_.getPreservedPath();
191 ASSERT_EQ(preserved_path.poses.size(), 10);
192 for (
size_t i = 0; i < preserved_path.poses.size(); ++i)
194 const auto& path_pose = preserved_path.poses[i].pose;
195 EXPECT_NEAR(path_pose.position.x, 0.1f * i, 1.0e-6);
196 EXPECT_NEAR(path_pose.position.y, 0.0, 1.0e-6);
197 EXPECT_NEAR(
tf2::getYaw(path_pose.orientation), 0.0, 1.0e-6);
199 EXPECT_NEAR(predictor_.getPreservedPathLength(), 1.0, 1.0e-6);
207 EXPECT_FALSE(predictor_.process(getPose(0.05, 0.05, 0.0), cm_, map_info_, paths_[
"straight"].second, start_grid));
208 EXPECT_TRUE(predictor_.getPreservedPath().poses.empty());
209 EXPECT_EQ(predictor_.getPreservedPathLength(), 0.0);
217 EXPECT_TRUE(predictor_.process(getPose(0.25, 0.0, 0.0), cm_, map_info_, paths_[
"switch_back"].second, start_grid));
220 const auto preserved_path = predictor_.getPreservedPath();
221 ASSERT_EQ(preserved_path.poses.size(), 17);
222 for (
size_t i = 0; i < preserved_path.poses.size(); ++i)
224 const auto& path_pose = preserved_path.poses[i].pose;
225 const auto& expected_path_pose = paths_[
"switch_back"].second.poses[i + 3].pose;
226 EXPECT_NEAR(path_pose.position.x, expected_path_pose.position.x, 1.0e-6);
227 EXPECT_NEAR(path_pose.position.y, expected_path_pose.position.y, 1.0e-6);
234 EXPECT_TRUE(predictor_.process(getPose(0.65, 0.0, 0.0), cm_, map_info_, paths_[
"switch_back"].second, start_grid));
237 const auto preserved_path = predictor_.getPreservedPath();
239 ASSERT_EQ(preserved_path.poses.size(), 4 + 10 + 13);
240 for (
size_t i = 0; i < preserved_path.poses.size(); ++i)
242 const auto& path_pose = preserved_path.poses[i].pose;
243 const auto& expected_path_pose = paths_[
"switch_back"].second.poses[i + 7].pose;
244 EXPECT_NEAR(path_pose.position.x, expected_path_pose.position.x, 1.0e-6);
245 EXPECT_NEAR(path_pose.position.y, expected_path_pose.position.y, 1.0e-6);
254 int main(
int argc,
char** argv)
256 testing::InitGoogleTest(&argc, argv);
258 return RUN_ALL_TESTS();