$search
00001 #include <nav_core/base_global_planner.h> 00002 #include <ros/ros.h> 00003 #include <geometry_msgs/PoseStamped.h> 00004 #include <pluginlib/class_list_macros.h> 00005 #include <std_msgs/String.h> 00006 00007 #include <sbpl_cart_planner/sbpl_cart_planner.h> 00008 #include <navfn/navfn_ros.h> 00009 00010 namespace global_planner_switcher { 00011 00012 class GlobalPlannerSwitcher : public nav_core::BaseGlobalPlanner 00013 { 00014 public: 00015 GlobalPlannerSwitcher() 00016 { 00017 sbpl_planner_= new SBPLCartPlanner(); 00018 navfn_planner_ = new navfn::NavfnROS(); 00019 00020 comp_ctor("global_planner_switcher"); 00021 } 00022 00023 00024 GlobalPlannerSwitcher(std::string name, costmap_2d::Costmap2DROS* costmap_ros) 00025 { 00026 sbpl_planner_ = new SBPLCartPlanner("SBPLCartPlanner", costmap_ros); 00027 navfn_planner_ = new navfn::NavfnROS("navfn/NavfnROS", costmap_ros); 00028 00029 comp_ctor(name); 00030 } 00031 00032 void initialize(std::string name, 00033 costmap_2d::Costmap2DROS* costmap_ros) 00034 { 00035 sbpl_planner_->initialize("SBPLCartPlanner", costmap_ros); 00036 navfn_planner_->initialize("navfn/NavfnROS", costmap_ros); 00037 } 00038 00039 virtual bool makePlan(const geometry_msgs::PoseStamped& start, 00040 const geometry_msgs::PoseStamped& goal, 00041 std::vector<geometry_msgs::PoseStamped>& plan) 00042 { 00043 if (sbpl_active_) 00044 return sbpl_planner_->makePlan(start, goal, plan); 00045 else 00046 return navfn_planner_->makePlan(start, goal, plan); 00047 } 00048 00049 ~GlobalPlannerSwitcher() 00050 { 00051 delete sbpl_planner_; 00052 delete navfn_planner_; 00053 } 00054 00055 private: 00056 SBPLCartPlanner *sbpl_planner_; 00057 navfn::NavfnROS *navfn_planner_; 00058 00059 ros::NodeHandle nh_; 00060 00061 void setPlannerCB(const std_msgs::String &msg) 00062 { 00063 sbpl_active_ = (msg.data == "sbpl"); 00064 ROS_INFO("Switching global planner. SBPL active: %d", sbpl_active_); 00065 00066 std_msgs::String status; 00067 if (sbpl_active_) { 00068 status.data = "sbpl"; 00069 } 00070 else { 00071 status.data = "navfn"; 00072 } 00073 00074 active_planner_pub_.publish(status); 00075 } 00076 00077 void comp_ctor(const std::string &name) 00078 { 00079 sbpl_active_ = false; 00080 00081 nh_ = ros::NodeHandle("move_base_node/global_planner_switcher"); 00082 active_planner_sub_ = nh_.subscribe("set_active_planner", 1, &GlobalPlannerSwitcher::setPlannerCB, this); 00083 active_planner_pub_ = nh_.advertise<std_msgs::String>("active_planner", 5, true); 00084 00085 std_msgs::String status; 00086 status.data = "navfn"; 00087 active_planner_pub_.publish(status); 00088 } 00089 00090 bool sbpl_active_; 00091 00092 ros::Subscriber active_planner_sub_; 00093 ros::Publisher active_planner_pub_; 00094 }; 00095 00096 PLUGINLIB_DECLARE_CLASS(global_planner_switcher, GlobalPlannerSwitcher, global_planner_switcher::GlobalPlannerSwitcher, nav_core::BaseGlobalPlanner); 00097 00098 } // namespace 00099 00100