38 #include <std_srvs/Empty.h> 39 #include <nav_msgs/Path.h> 40 #include <nav_msgs/GetPlan.h> 41 #include <nav_msgs/OccupancyGrid.h> 42 #include <costmap_cspace_msgs/CSpace3D.h> 44 #include <gtest/gtest.h> 52 nav_msgs::OccupancyGrid::ConstPtr
map_;
54 costmap_cspace_msgs::CSpace3D::ConstPtr
costmap_;
66 , local_map_apply_cnt_(0)
72 nh_.
serviceClient<std_srvs::EmptyRequest, std_srvs::EmptyResponse>(
73 "forget_planning_cost");
74 pub_map_ = nh_.
advertise<nav_msgs::OccupancyGrid>(
"map", 1,
true);
75 pub_map_local_ = nh_.
advertise<nav_msgs::OccupancyGrid>(
"overlay", 1,
true);
77 nh_.
advertise<geometry_msgs::PoseWithCovarianceStamped>(
"initialpose", 1,
true);
82 geometry_msgs::PoseWithCovarianceStamped pose;
83 pose.header.frame_id =
"map";
84 pose.pose.pose.position.x = 2.5;
85 pose.pose.pose.position.y = 0.45;
86 pose.pose.pose.orientation.z = 1.0;
87 pub_initial_pose_.
publish(pose);
98 std::cerr <<
"Map applied." << std::endl;
106 std_srvs::EmptyRequest req;
107 std_srvs::EmptyResponse res;
108 srv_forget_.
call(req, res);
112 void cbCostmap(
const costmap_cspace_msgs::CSpace3D::ConstPtr& msg)
115 std::cerr <<
"Costmap received." << std::endl;
117 void cbMap(
const nav_msgs::OccupancyGrid::ConstPtr& msg)
120 std::cerr <<
"Map received." << std::endl;
122 void cbMapLocal(
const nav_msgs::OccupancyGrid::ConstPtr& msg)
125 std::cerr <<
"Local map received." << std::endl;
131 pub_map_local_.
publish(map_local_);
132 if ((local_map_apply_cnt_++) % 30 == 0)
133 std::cerr <<
"Local map applied." << std::endl;
143 ASSERT_TRUE(static_cast<bool>(
map_));
146 path.poses.resize(2);
147 path.header.frame_id =
"map";
148 path.poses[0].header.frame_id = path.header.frame_id;
149 path.poses[0].pose.position.x = 1.7;
150 path.poses[0].pose.position.y = 2.8;
152 path.poses[1].header.frame_id = path.header.frame_id;
153 path.poses[1].pose.position.x = 1.9;
154 path.poses[1].pose.position.y = 2.8;
171 geometry_msgs::TransformStamped trans_tmp =
177 std::cerr << e.what() << std::endl;
181 auto goal_rel = trans.inverse() * goal;
182 if (goal_rel.getOrigin().length() < 0.2 &&
183 std::abs(
tf2::getYaw(goal_rel.getRotation())) < 0.2)
185 std::cerr <<
"Navagation success." << std::endl;
190 for (
int x = -2;
x <= 2; ++
x)
192 for (
int y = -1;
y <= 1; ++
y)
194 const tf2::Vector3 pos =
195 trans * tf2::Vector3(
x *
map_->info.resolution,
y *
map_->info.resolution, 0);
196 const int map_x = pos.x() /
map_->info.resolution;
197 const int map_y = pos.y() /
map_->info.resolution;
198 const size_t addr = map_x + map_y *
map_->info.width;
199 ASSERT_LT(addr,
map_->data.size());
200 ASSERT_LT(map_x, static_cast<int>(
map_->info.width));
201 ASSERT_LT(map_y, static_cast<int>(
map_->info.height));
204 ASSERT_NE(
map_->data[addr], 100);
216 ASSERT_TRUE(static_cast<bool>(
map_));
222 path.poses.resize(1);
223 path.header.frame_id =
"map";
224 path.poses[0].header.frame_id = path.header.frame_id;
225 path.poses[0].pose.position.x = 1.7;
226 path.poses[0].pose.position.y = 2.8;
244 geometry_msgs::TransformStamped trans_tmp =
250 std::cerr << e.what() << std::endl;
254 auto goal_rel = trans.inverse() * goal;
255 if (goal_rel.getOrigin().length() < 0.2 &&
256 std::abs(
tf2::getYaw(goal_rel.getRotation())) < 0.2)
258 std::cerr <<
"Navagation success." << std::endl;
263 for (
int x = -2;
x <= 2; ++
x)
265 for (
int y = -1;
y <= 1; ++
y)
267 const tf2::Vector3 pos =
268 trans * tf2::Vector3(
x *
map_->info.resolution,
y *
map_->info.resolution, 0);
269 const int map_x = pos.x() /
map_->info.resolution;
270 const int map_y = pos.y() /
map_->info.resolution;
271 const size_t addr = map_x + map_y *
map_->info.width;
272 ASSERT_LT(addr,
map_->data.size());
273 ASSERT_LT(map_x, static_cast<int>(
map_->info.width));
274 ASSERT_LT(map_y, static_cast<int>(
map_->info.height));
277 ASSERT_NE(
map_->data[addr], 100);
289 "/planner_3d/make_plan");
292 ASSERT_TRUE(static_cast<bool>(
map_));
294 nav_msgs::GetPlanRequest req;
295 nav_msgs::GetPlanResponse res;
298 req.start.header.frame_id =
"map";
299 req.start.pose.position.x = 1.95;
300 req.start.pose.position.y = 0.45;
301 req.start.pose.orientation =
304 req.goal.header.frame_id =
"map";
305 req.goal.pose.position.x = 1.25;
306 req.goal.pose.position.y = 2.15;
307 req.goal.pose.orientation =
310 ASSERT_FALSE(srv_plan.
call(req, res));
314 ASSERT_TRUE(srv_plan.
call(req, res));
315 EXPECT_NEAR(1.25, res.plan.poses.back().pose.position.x, 1.0e-5);
316 EXPECT_NEAR(2.25, res.plan.poses.back().pose.position.y, 1.0e-5);
319 req.tolerance = 0.2f;
320 ASSERT_TRUE(srv_plan.
call(req, res));
321 EXPECT_NEAR(1.25, res.plan.poses.back().pose.position.x, 1.0e-5);
322 EXPECT_NEAR(2.35, res.plan.poses.back().pose.position.y, 1.0e-5);
325 req.goal.header.frame_id =
"map";
326 req.goal.pose.position.x = 1.85;
327 req.goal.pose.position.y = 2.75;
328 req.goal.pose.orientation =
330 ASSERT_TRUE(srv_plan.
call(req, res));
332 EXPECT_NEAR(req.start.pose.position.x, res.plan.poses.front().pose.position.x, 1.0e-5);
333 EXPECT_NEAR(req.start.pose.position.y, res.plan.poses.front().pose.position.y, 1.0e-5);
334 EXPECT_NEAR(req.goal.pose.position.x, res.plan.poses.back().pose.position.x, 1.0e-5);
335 EXPECT_NEAR(req.goal.pose.position.y, res.plan.poses.back().pose.position.y, 1.0e-5);
337 for (
const geometry_msgs::PoseStamped& p : res.plan.poses)
339 const int map_x = p.pose.position.x /
map_->info.resolution;
340 const int map_y = p.pose.position.y /
map_->info.resolution;
341 const size_t addr = map_x + map_y *
map_->info.width;
342 ASSERT_LT(addr,
map_->data.size());
343 ASSERT_LT(map_x, static_cast<int>(
map_->info.width));
344 ASSERT_LT(map_y, static_cast<int>(
map_->info.height));
347 ASSERT_NE(
map_->data[addr], 100);
351 int main(
int argc,
char** argv)
353 testing::InitGoogleTest(&argc, argv);
356 return RUN_ALL_TESTS();
ServiceClient serviceClient(const std::string &service_name, bool persistent=false, const M_string &header_values=M_string())
void publish(const boost::shared_ptr< M > &message) const
void cbMap(const nav_msgs::OccupancyGrid::ConstPtr &msg)
nav_msgs::OccupancyGrid::ConstPtr map_
TEST_F(Navigate, Navigate)
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
void cbCostmap(const costmap_cspace_msgs::CSpace3D::ConstPtr &msg)
virtual geometry_msgs::TransformStamped lookupTransform(const std::string &target_frame, const std::string &source_frame, const ros::Time &time, const ros::Duration timeout) const
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
bool call(MReq &req, MRes &res)
costmap_cspace_msgs::CSpace3D::ConstPtr costmap_
TFSIMD_FORCE_INLINE const tfScalar & y() const
ros::Subscriber sub_map_local_
nav_msgs::OccupancyGrid::ConstPtr map_local_
tf2_ros::TransformListener tfl_
ros::Subscriber sub_costmap_
ros::Publisher pub_initial_pose_
bool waitForExistence(ros::Duration timeout=ros::Duration(-1))
void fromMsg(const A &, B &b)
ros::ServiceClient srv_forget_
TFSIMD_FORCE_INLINE const tfScalar & x() const
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
double getYaw(const A &a)
ros::Publisher pub_map_local_
ROSCPP_DECL void spinOnce()
size_t local_map_apply_cnt_
void cbMapLocal(const nav_msgs::OccupancyGrid::ConstPtr &msg)
int main(int argc, char **argv)