38 initState(Eigen::Vector2d(0, 0), 0);
40 std::vector<Eigen::Vector3d> poses;
41 for (
double x = 0.0; x < 0.5; x += 0.01)
42 poses.push_back(Eigen::Vector3d(x, 0.0, 0.0));
43 poses.push_back(Eigen::Vector3d(0.5, 0.0, 0.0));
53 <<
"Timeout" << std::endl
54 <<
"Pos " << getPos() << std::endl
55 <<
"Yaw " <<
getYaw() << std::endl
56 <<
"Status " << std::endl
57 << status_ << std::endl;
63 if (status_->status == trajectory_tracker_msgs::TrajectoryTrackerStatus::GOAL)
66 for (
int j = 0; j < 5; ++j)
68 for (
int i = 0; i < 5; ++i)
76 ASSERT_NEAR(
getYaw(), 0.0, error_ang_)
77 <<
"[overshoot after goal (" << j <<
")] ";
78 ASSERT_NEAR(getPos()[0], 0.5, error_lin_)
79 <<
"[overshoot after goal (" << j <<
")] ";
80 ASSERT_NEAR(getPos()[1], 0.0, error_lin_)
81 <<
"[overshoot after goal (" << j <<
")] ";
83 ASSERT_EQ(last_path_header_.stamp, status_->path_header.stamp);
88 const double resolutions[] =
94 for (
const double resolution : resolutions)
96 const std::string info_message =
"resolution: " + std::to_string(resolution);
98 initState(Eigen::Vector2d(1, 0), 0);
100 std::vector<Eigen::Vector3d> poses;
101 for (
double x = 0.0; x < 0.5 - resolution; x += 0.1)
102 poses.push_back(Eigen::Vector3d(x, 0, 0));
103 poses.push_back(Eigen::Vector3d(0.5 - resolution, 0, 0));
104 poses.push_back(Eigen::Vector3d(0.5, 0, 0));
114 <<
"Timeout" << std::endl
115 <<
"Pos " << getPos() << std::endl
116 <<
"Yaw " <<
getYaw() << std::endl
117 <<
"Status " << std::endl
118 << status_ << std::endl
125 if (status_->status == trajectory_tracker_msgs::TrajectoryTrackerStatus::GOAL)
128 for (
int j = 0; j < 5; ++j)
130 for (
int i = 0; i < 5; ++i)
138 ASSERT_NEAR(
getYaw(), 0.0, error_ang_)
139 <<
"[overshoot after goal (" << j <<
")] "
141 EXPECT_NEAR(getPos()[0], 0.5, error_lin_)
142 <<
"[overshoot after goal (" << j <<
")] "
144 ASSERT_NEAR(getPos()[1], 0.0, error_lin_)
145 <<
"[overshoot after goal (" << j <<
")] "
148 ASSERT_EQ(last_path_header_.stamp, status_->path_header.stamp) << info_message;
154 const double vels[] = {0.02, 0.05, 0.1, 0.2, 0.5, 1.0};
155 const double path_length = 2.0;
156 for (
const double vel : vels)
158 const std::string info_message =
"linear vel: " + std::to_string(vel);
160 initState(Eigen::Vector2d(0, 0.01), 0);
162 std::vector<Eigen::Vector4d> poses;
163 for (
double x = 0.0; x < path_length; x += 0.01)
164 poses.push_back(Eigen::Vector4d(x, 0.0, 0.0, vel));
165 poses.push_back(Eigen::Vector4d(path_length, 0.0, 0.0, vel));
175 <<
"Timeout" << std::endl
176 <<
"Pos " << getPos() << std::endl
177 <<
"Yaw " <<
getYaw() << std::endl
178 <<
"Status " << std::endl
179 << status_ << std::endl
186 if (status_->status == trajectory_tracker_msgs::TrajectoryTrackerStatus::GOAL)
189 for (
int j = 0; j < 5; ++j)
191 for (
int i = 0; i < 5; ++i)
199 EXPECT_NEAR(
getYaw(), 0.0, error_ang_)
200 <<
"[overshoot after goal (" << j <<
")] "
202 EXPECT_NEAR(getPos()[0], path_length, error_lin_)
203 <<
"[overshoot after goal (" << j <<
")] "
205 EXPECT_NEAR(getPos()[1], 0.0, error_lin_)
206 <<
"[overshoot after goal (" << j <<
")] "
209 ASSERT_EQ(last_path_header_.stamp, status_->path_header.stamp);
215 initState(Eigen::Vector2d(0, 0), 0);
217 std::vector<Eigen::Vector4d> poses;
218 for (
double x = 0.0; x < 0.6; x += 0.01)
219 poses.push_back(Eigen::Vector4d(x, 0.0, 0.0, 0.3));
220 for (
double x = 0.6; x < 1.5; x += 0.01)
221 poses.push_back(Eigen::Vector4d(x, 0.0, 0.0, 0.5));
222 poses.push_back(Eigen::Vector4d(1.5, 0.0, 0.0, 0.5));
232 <<
"Timeout" << std::endl
233 <<
"Pos " << getPos() << std::endl
234 <<
"Yaw " <<
getYaw() << std::endl
235 <<
"Status " << std::endl
236 << status_ << std::endl;
243 if (0.3 < getPos()[0] && getPos()[0] < 0.35)
245 ASSERT_NEAR(cmd_vel_->linear.x, 0.3, error_lin_);
247 else if (0.95 < getPos()[0] && getPos()[0] < 1.0)
249 ASSERT_NEAR(cmd_vel_->linear.x, 0.5, error_lin_);
252 if (status_->status == trajectory_tracker_msgs::TrajectoryTrackerStatus::GOAL)
255 for (
int j = 0; j < 5; ++j)
257 for (
int i = 0; i < 5; ++i)
265 ASSERT_NEAR(
getYaw(), 0.0, error_ang_)
266 <<
"[overshoot after goal (" << j <<
")] ";
267 ASSERT_NEAR(getPos()[0], 1.5, error_lin_)
268 <<
"[overshoot after goal (" << j <<
")] ";
269 ASSERT_NEAR(getPos()[1], 0.0, error_lin_)
270 <<
"[overshoot after goal (" << j <<
")] ";
272 ASSERT_EQ(last_path_header_.stamp, status_->path_header.stamp);
277 initState(Eigen::Vector2d(0, 0), 0);
279 std::vector<Eigen::Vector3d> poses;
280 Eigen::Vector3d p(0.0, 0.0, 0.0);
281 for (
double t = 0.0;
t < 1.0;
t += 0.01)
283 p += Eigen::Vector3d(std::cos(p[2]) * 0.05, std::sin(p[2]) * 0.05, 0.005);
286 for (
double t = 0.0;
t < 1.0;
t += 0.01)
288 p += Eigen::Vector3d(std::cos(p[2]) * 0.05, std::sin(p[2]) * 0.05, 0.0);
300 <<
"Timeout" << std::endl
301 <<
"Pos " << getPos() << std::endl
302 <<
"Yaw " <<
getYaw() << std::endl
303 <<
"Status " << std::endl
304 << status_ << std::endl;
310 if (status_->status == trajectory_tracker_msgs::TrajectoryTrackerStatus::GOAL)
313 for (
int j = 0; j < 5; ++j)
315 for (
int i = 0; i < 5; ++i)
323 ASSERT_NEAR(
getYaw(), p[2], error_ang_)
324 <<
"[overshoot after goal (" << j <<
")] ";
325 ASSERT_NEAR(getPos()[0], p[0], error_large_lin_)
326 <<
"[overshoot after goal (" << j <<
")] ";
327 ASSERT_NEAR(getPos()[1], p[1], error_large_lin_)
328 <<
"[overshoot after goal (" << j <<
")] ";
330 ASSERT_EQ(last_path_header_.stamp, status_->path_header.stamp);
335 const float init_yaw_array[] = {0.0, 3.0};
336 for (
const float init_yaw : init_yaw_array)
338 const std::vector<float> target_angle_array[] =
342 {0.1, 0.2, 0.3, 0.4, 0.5},
343 {-0.1, -0.2, -0.3, -0.4, -0.5},
345 for (
const auto& angles : target_angle_array)
347 for (
const bool& has_short_path : {
false,
true})
349 std::stringstream condition_name;
351 <<
"init_yaw: " << init_yaw
352 <<
", angles: " << angles.front() <<
"-" << angles.back()
353 <<
", has_short_path: " << has_short_path;
355 initState(Eigen::Vector2d(0, 0), init_yaw);
357 std::vector<Eigen::Vector3d> poses;
360 poses.push_back(Eigen::Vector3d(-std::cos(init_yaw) * 0.01, std::sin(init_yaw) * 0.01, init_yaw));
362 for (
float ang : angles)
364 poses.push_back(Eigen::Vector3d(0.0, 0.0, init_yaw + ang));
370 for (
int i = 0;
ros::ok(); ++i)
375 << condition_name.str()
376 <<
"Timeout" << std::endl
377 <<
"Pos " << getPos() << std::endl
378 <<
"Yaw " <<
getYaw() << std::endl
379 <<
"Status " << std::endl
380 << status_ << std::endl;
387 if (cmd_vel_ && i > 5)
389 ASSERT_GT(cmd_vel_->angular.z * std::copysign(1.0, angles.back()), -error_ang_)
390 <<
"[overshoot detected] "
391 << condition_name.str();
393 if (status_ && i > 5)
395 ASSERT_LT(status_->angle_remains * std::copysign(1.0, angles.back()), error_ang_)
396 <<
"[overshoot detected] "
397 << condition_name.str();
400 if (status_->status == trajectory_tracker_msgs::TrajectoryTrackerStatus::GOAL)
403 ASSERT_TRUE(
static_cast<bool>(cmd_vel_)) << condition_name.str();
404 for (
int j = 0; j < 5; ++j)
406 for (
int i = 0; i < 5; ++i)
414 const double angle_diff = pose_.getRotation().angleShortestPath(
416 ASSERT_LT(angle_diff, error_ang_)
417 <<
"[overshoot after goal (" << j <<
")] "
418 << condition_name.str();
420 ASSERT_EQ(last_path_header_.stamp, status_->path_header.stamp);
428 initState(Eigen::Vector2d(0, 0), 0);
430 std::vector<Eigen::Vector3d> poses;
431 Eigen::Vector3d p(0.0, 0.0, 0.0);
432 for (
double t = 0.0;
t < 0.5;
t += 0.01)
434 p -= Eigen::Vector3d(std::cos(p[2]) * 0.05, std::sin(p[2]) * 0.05, -0.01);
437 for (
double t = 0.0;
t < 0.5;
t += 0.01)
439 p += Eigen::Vector3d(std::cos(p[2]) * 0.05, std::sin(p[2]) * 0.05, 0.01);
451 <<
"Timeout" << std::endl
452 <<
"Pos " << getPos() << std::endl
453 <<
"Yaw " <<
getYaw() << std::endl
454 <<
"Status " << std::endl
455 << status_ << std::endl;
461 if (status_->status == trajectory_tracker_msgs::TrajectoryTrackerStatus::GOAL)
464 for (
int j = 0; j < 5; ++j)
466 for (
int i = 0; i < 5; ++i)
474 ASSERT_NEAR(
getYaw(), p[2], error_ang_)
475 <<
"[overshoot after goal (" << j <<
")] ";
476 ASSERT_NEAR(getPos()[0], p[0], error_large_lin_)
477 <<
"[overshoot after goal (" << j <<
")] ";
478 ASSERT_NEAR(getPos()[1], p[1], error_large_lin_)
479 <<
"[overshoot after goal (" << j <<
")] ";
481 ASSERT_EQ(last_path_header_.stamp, status_->path_header.stamp);
486 initState(Eigen::Vector2d(0, 0), 0);
488 std::vector<Eigen::Vector3d> poses;
489 std::vector<Eigen::Vector3d> poses_second_half;
490 Eigen::Vector3d p(0.0, 0.0, 0.0);
491 for (
double t = 0.0;
t < 0.5;
t += 0.01)
493 p -= Eigen::Vector3d(std::cos(p[2]) * 0.05, std::sin(p[2]) * 0.05, -0.01);
496 const Eigen::Vector2d pos_local_goal = p.head<2>();
497 for (
double t = 0.0;
t < 1.0;
t += 0.01)
499 p += Eigen::Vector3d(std::cos(p[2]) * 0.05, std::sin(p[2]) * 0.05, 0.01);
501 poses_second_half.push_back(p);
505 int cnt_arrive_local_goal(0);
508 for (
int i = 0;
ros::ok(); i++)
513 <<
"Timeout" << std::endl
514 <<
"Pos " << getPos() << std::endl
515 <<
"Yaw " <<
getYaw() << std::endl
516 <<
"Status " << std::endl
517 << status_ << std::endl;
523 if (status_->status == trajectory_tracker_msgs::TrajectoryTrackerStatus::GOAL)
526 if ((pos_local_goal - getPos()).norm() < 0.1)
527 cnt_arrive_local_goal++;
532 if (cnt_arrive_local_goal > 25)
534 publishPath(poses_second_half);
542 ASSERT_GT(cnt_arrive_local_goal, 25)
543 <<
"failed to update path";
544 for (
int j = 0; j < 5; ++j)
546 for (
int i = 0; i < 5; ++i)
554 ASSERT_NEAR(
getYaw(), p[2], error_ang_)
555 <<
"[overshoot after goal (" << j <<
")] ";
556 ASSERT_NEAR(getPos()[0], p[0], error_large_lin_)
557 <<
"[overshoot after goal (" << j <<
")] ";
558 ASSERT_NEAR(getPos()[1], p[1], error_large_lin_)
559 <<
"[overshoot after goal (" << j <<
")] ";
561 ASSERT_EQ(last_path_header_.stamp, status_->path_header.stamp);
566 const double y_pos = 500.0;
569 std::vector<Eigen::Vector3d> poses;
570 for (
double x = 0.0; x < 0.5; x += 0.01)
571 poses.push_back(Eigen::Vector3d(x, y_pos, 0.0));
572 poses.push_back(Eigen::Vector3d(0.5, y_pos, 0.0));
582 <<
"Timeout" << std::endl
583 <<
"Pos " << getPos() << std::endl
584 <<
"Yaw " <<
getYaw() << std::endl
585 <<
"Status " << std::endl
586 << status_ << std::endl;
592 if (status_->status == trajectory_tracker_msgs::TrajectoryTrackerStatus::GOAL)
595 for (
int j = 0; j < 5; ++j)
597 for (
int i = 0; i < 5; ++i)
605 ASSERT_NEAR(
getYaw(), 0.0, error_ang_)
606 <<
"[overshoot after goal (" << j <<
")] ";
607 ASSERT_NEAR(getPos()[0], 0.5, error_lin_)
608 <<
"[overshoot after goal (" << j <<
")] ";
609 ASSERT_NEAR(getPos()[1], y_pos, error_lin_)
610 <<
"[overshoot after goal (" << j <<
")] ";
612 ASSERT_EQ(last_path_header_.stamp, status_->path_header.stamp);
619 nh.
param(
"/use_sim_time", use_sim_time,
false);
629 rosgraph_msgs::Clock clock;
630 clock.clock.fromNSec(time.
toNSec());
637 int main(
int argc,
char** argv)
639 testing::InitGoogleTest(&argc, argv);
640 ros::init(argc, argv,
"test_trajectory_tracker");
644 return RUN_ALL_TESTS();