navfn_node.cpp
Go to the documentation of this file.
1 /*********************************************************************
2 *
3 * Software License Agreement (BSD License)
4 *
5 * Copyright (c) 2008, Willow Garage, Inc.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer in the documentation and/or other materials provided
17 * with the distribution.
18 * * Neither the name of the Willow Garage nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 *
35 * Author: Bhaskara Marthi
36 *********************************************************************/
37 #include <navfn/navfn_ros.h>
38 #include <navfn/MakeNavPlan.h>
39 #include <boost/shared_ptr.hpp>
42 
43 namespace cm=costmap_2d;
44 namespace rm=geometry_msgs;
45 
46 using std::vector;
47 using rm::PoseStamped;
48 using std::string;
49 using cm::Costmap2D;
50 using cm::Costmap2DROS;
51 
52 namespace navfn {
53 
54 class NavfnWithCostmap : public NavfnROS
55 {
56 public:
57  NavfnWithCostmap(string name, Costmap2DROS* cmap);
58  bool makePlanService(MakeNavPlan::Request& req, MakeNavPlan::Response& resp);
59 
60 private:
61  void poseCallback(const rm::PoseStamped::ConstPtr& goal);
65 };
66 
67 
68 bool NavfnWithCostmap::makePlanService(MakeNavPlan::Request& req, MakeNavPlan::Response& resp)
69 {
70  vector<PoseStamped> path;
71 
72  req.start.header.frame_id = "/map";
73  req.goal.header.frame_id = "/map";
74  bool success = makePlan(req.start, req.goal, path);
75  resp.plan_found = success;
76  if (success) {
77  resp.path = path;
78  }
79 
80  return true;
81 }
82 
83 void NavfnWithCostmap::poseCallback(const rm::PoseStamped::ConstPtr& goal) {
84  tf::Stamped<tf::Pose> global_pose;
85  geometry_msgs::PoseStamped msg;
86  cmap_->getRobotPose(msg);
87  tf::poseStampedMsgToTF(msg, global_pose);
88  vector<PoseStamped> path;
89  rm::PoseStamped start;
90  start.header.stamp = global_pose.stamp_;
91  start.header.frame_id = global_pose.frame_id_;
92  start.pose.position.x = global_pose.getOrigin().x();
93  start.pose.position.y = global_pose.getOrigin().y();
94  start.pose.position.z = global_pose.getOrigin().z();
95  start.pose.orientation.x = global_pose.getRotation().x();
96  start.pose.orientation.y = global_pose.getRotation().y();
97  start.pose.orientation.z = global_pose.getRotation().z();
98  start.pose.orientation.w = global_pose.getRotation().w();
99  makePlan(start, *goal, path);
100 }
101 
102 
104  NavfnROS(name, cmap)
105 {
106  ros::NodeHandle private_nh("~");
107  cmap_ = cmap;
109  pose_sub_ = private_nh.subscribe<rm::PoseStamped>("goal", 1, &NavfnWithCostmap::poseCallback, this);
110 }
111 
112 } // namespace
113 
114 int main (int argc, char** argv)
115 {
116  ros::init(argc, argv, "global_planner");
117 
118  tf2_ros::Buffer buffer(ros::Duration(10));
120 
121  costmap_2d::Costmap2DROS lcr("costmap", buffer);
122 
123  navfn::NavfnWithCostmap navfn("navfn_planner", &lcr);
124 
125  ros::spin();
126  return 0;
127 }
128 
129 
130 
131 
132 
133 
134 
135 
136 
137 
138 
139 
140 
141 
142 
143 
Definition: navfn.h:81
Costmap2DROS * cmap_
Definition: navfn_node.cpp:62
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
ros::ServiceServer make_plan_service_
Definition: navfn_node.cpp:63
NavfnWithCostmap(string name, Costmap2DROS *cmap)
Definition: navfn_node.cpp:103
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
Provides a ROS wrapper for the navfn planner which runs a fast, interpolated navigation function on a...
Definition: navfn_ros.h:58
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
bool makePlan(const geometry_msgs::PoseStamped &start, const geometry_msgs::PoseStamped &goal, std::vector< geometry_msgs::PoseStamped > &plan)
Given a goal pose in the world, compute a plan.
Definition: navfn_ros.cpp:210
bool getRobotPose(geometry_msgs::PoseStamped &global_pose) const
ROSCPP_DECL void spin()
ros::Time stamp_
std::string frame_id_
void poseCallback(const rm::PoseStamped::ConstPtr &goal)
Definition: navfn_node.cpp:83
static void poseStampedMsgToTF(const geometry_msgs::PoseStamped &msg, Stamped< Pose > &bt)
ros::Subscriber pose_sub_
Definition: navfn_node.cpp:64
bool makePlanService(MakeNavPlan::Request &req, MakeNavPlan::Response &resp)
Definition: navfn_node.cpp:68


asr_navfn
Author(s): Kurt Konolige, Eitan Marder-Eppstein, contradict@gmail.com, Felix Marek
autogenerated on Mon Feb 28 2022 21:51:47