38 #include <costmap_cspace_msgs/CSpace3D.h>
39 #include <nav_msgs/GetPlan.h>
40 #include <nav_msgs/OccupancyGrid.h>
41 #include <nav_msgs/Path.h>
42 #include <planner_cspace_msgs/PlannerStatus.h>
43 #include <std_srvs/Empty.h>
50 #include <gtest/gtest.h>
59 costmap_cspace_msgs::CSpace3D::ConstPtr
costmap_;
67 std::vector<tf2::Stamped<tf2::Transform>>
traj_;
79 "forget_planning_cost");
81 nh_.
advertise<geometry_msgs::PoseWithCovarianceStamped>(
"initialpose", 1,
true);
87 test_scope_ =
"[" + std::to_string(getpid()) +
"] ";
92 geometry_msgs::PoseWithCovarianceStamped pose;
93 pose.header.frame_id =
"map";
94 pose.pose.pose.position.x = 2.1;
95 pose.pose.pose.position.y = 3.0;
108 FAIL() <<
test_scope_ << now <<
" SetUp: transform timeout" << std::endl;
123 FAIL() <<
test_scope_ << now <<
" SetUp: costmap timeout" << std::endl;
127 std_srvs::EmptyRequest req;
128 std_srvs::EmptyResponse res;
133 void cbCostmap(
const costmap_cspace_msgs::CSpace3D::ConstPtr& msg)
136 std::cerr <<
test_scope_ <<
msg->header.stamp <<
" Costmap received." << std::endl;
138 void cbStatus(
const planner_cspace_msgs::PlannerStatus::ConstPtr& msg)
142 std::cerr <<
test_scope_ <<
msg->header.stamp <<
" Status updated." <<
msg << std::endl;
146 void cbPath(
const nav_msgs::Path::ConstPtr& msg)
150 if (
msg->poses.size() == 0)
152 std::cerr <<
test_scope_ <<
msg->header.stamp <<
" Path updated. (empty)" << std::endl;
157 <<
test_scope_ <<
msg->header.stamp <<
" Path updated." << std::endl
158 <<
msg->poses.front().pose.position.x <<
", " <<
msg->poses.front().pose.position.y << std::endl
159 <<
msg->poses.back().pose.position.x <<
", " <<
msg->poses.back().pose.position.y << std::endl;
166 geometry_msgs::TransformStamped trans_tmp =
170 traj_.push_back(trans);
175 double x_prev(0), y_prev(0);
178 std::cerr <<
test_scope_ <<
traj_.size() <<
" points recorded" << std::endl;
180 for (
const auto&
t :
traj_)
182 const double x =
t.getOrigin().getX();
183 const double y =
t.getOrigin().getY();
186 if (std::abs(x - x_prev) > 0.1 || std::abs(y - y_prev) > 0.1 || std::abs(yaw_diff) > 0.2)
191 std::cerr <<
t.stamp_ <<
" " << x <<
" " << y <<
" " <<
tf2::getYaw(rot) << std::endl;
214 <<
test_scope_ <<
"/" << name <<
": Navigation timeout." << std::endl
215 <<
"now: " << now << std::endl
216 <<
"status: " <<
planner_status_ <<
" (expected: " << expected_error <<
")";
233 path.poses.resize(1);
234 path.header.frame_id =
"map";
235 path.poses[0].header.frame_id = path.header.frame_id;
236 path.poses[0].pose.position.x = 1.5;
237 path.poses[0].pose.position.y = 5.6;
239 pub_patrol_nodes_.publish(path);
255 dumpRobotTrajectory();
257 << test_scope_ <<
"Navigation timeout." << std::endl
258 <<
"now: " << now << std::endl
259 <<
"status: " << planner_status_;
266 trans = lookupRobotTrans(now);
270 std::cerr << test_scope_ << e.what() << std::endl;
274 auto goal_rel = trans.inverse() * goal;
275 if (goal_rel.getOrigin().length() < 0.2 &&
276 std::abs(
tf2::getYaw(goal_rel.getRotation())) < 0.2)
278 std::cerr << test_scope_ <<
"Navagation success." << std::endl;
286 int main(
int argc,
char** argv)
288 testing::InitGoogleTest(&argc, argv);
289 ros::init(argc, argv,
"test_navigate_remember");
291 return RUN_ALL_TESTS();