Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef LOCOMOTOR_LOCOMOTOR_H
00036 #define LOCOMOTOR_LOCOMOTOR_H
00037
00038 #include <ros/ros.h>
00039 #include <locomotor/executor.h>
00040 #include <locomotor/publishers.h>
00041 #include <locomotor_msgs/NavigationState.h>
00042 #include <locomotor_msgs/ResultCode.h>
00043 #include <nav_core2/exceptions.h>
00044 #include <nav_core2/costmap.h>
00045 #include <nav_core2/global_planner.h>
00046 #include <nav_core2/local_planner.h>
00047 #include <pluginlib/class_loader.h>
00048 #include <nav_2d_utils/odom_subscriber.h>
00049 #include <nav_2d_utils/plugin_mux.h>
00050 #include <map>
00051 #include <string>
00052 #include <vector>
00053
00054 namespace locomotor
00055 {
00056
00057 using CostmapUpdateCallback = std::function<void (const ros::Duration&)>;
00058 using CostmapUpdateExceptionCallback = std::function<void (nav_core2::NavCore2ExceptionPtr, const ros::Duration&)>;
00059 using GlobalPlanCallback = std::function<void (const nav_2d_msgs::Path2D&, const ros::Duration&)>;
00060 using LocalPlanCallback = std::function<void (const nav_2d_msgs::Twist2DStamped&, const ros::Duration&)>;
00061 using PlannerExceptionCallback = std::function<void (nav_core2::NavCore2ExceptionPtr, const ros::Duration&)>;
00062 using NavigationCompleteCallback = std::function<void ()>;
00063 using NavigationFailureCallback = std::function<void (const locomotor_msgs::ResultCode)>;
00064
00065 inline locomotor_msgs::ResultCode makeResultCode(int component = -1, int result_code = -1,
00066 const std::string& message = "")
00067 {
00068 locomotor_msgs::ResultCode code;
00069 code.component = component;
00070 code.result_code = result_code;
00071 code.message = message;
00072 return code;
00073 }
00074
00079 class Locomotor
00080 {
00081 public:
00085 explicit Locomotor(const ros::NodeHandle& private_nh);
00086
00092 void initializeGlobalCostmap(Executor& ex);
00093 void initializeLocalCostmap(Executor& ex);
00094 void initializeGlobalPlanners(Executor& ex);
00095 void initializeLocalPlanners(Executor& ex);
00097
00102 virtual void setGoal(nav_2d_msgs::Pose2DStamped goal);
00103
00116 void requestGlobalCostmapUpdate(Executor& work_ex, Executor& result_ex,
00117 CostmapUpdateCallback cb = nullptr,
00118 CostmapUpdateExceptionCallback fail_cb = nullptr);
00119
00127 void requestLocalCostmapUpdate(Executor& work_ex, Executor& result_ex,
00128 CostmapUpdateCallback cb = nullptr,
00129 CostmapUpdateExceptionCallback fail_cb = nullptr);
00130
00138 void requestGlobalPlan(Executor& work_ex, Executor& result_ex,
00139 GlobalPlanCallback cb = nullptr,
00140 PlannerExceptionCallback fail_cb = nullptr);
00141
00150 void requestLocalPlan(Executor& work_ex, Executor& result_ex,
00151 LocalPlanCallback cb = nullptr,
00152 PlannerExceptionCallback fail_cb = nullptr,
00153 NavigationCompleteCallback complete_cb = nullptr);
00154
00161 void requestNavigationFailure(Executor& result_ex, const locomotor_msgs::ResultCode& result,
00162 NavigationFailureCallback cb = nullptr);
00164
00165 const locomotor_msgs::NavigationState& getNavigationState() const { return state_; }
00166
00167
00168 std::vector<std::string> getGlobalPlannerNames() const { return global_planner_mux_.getPluginNames(); }
00169 std::string getCurrentGlobalPlannerName() const { return global_planner_mux_.getCurrentPluginName(); }
00170 nav_core2::GlobalPlanner& getCurrentGlobalPlanner() { return global_planner_mux_.getCurrentPlugin(); }
00171 bool useGlobalPlanner(const std::string& name) { return global_planner_mux_.usePlugin(name); }
00172
00173 std::vector<std::string> getLocalPlannerNames() const { return local_planner_mux_.getPluginNames(); }
00174 std::string getCurrentLocalPlannerName() const { return local_planner_mux_.getCurrentPluginName(); }
00175 nav_core2::LocalPlanner& getCurrentLocalPlanner() { return local_planner_mux_.getCurrentPlugin(); }
00176 bool useLocalPlanner(const std::string& name) { return local_planner_mux_.usePlugin(name); }
00177
00178
00179 nav_core2::Costmap::Ptr getGlobalCostmap() const { return global_costmap_; }
00180 nav_core2::Costmap::Ptr getLocalCostmap() const { return local_costmap_; }
00181
00182
00183 TFListenerPtr getTFListener() const { return tf_; }
00184 nav_2d_msgs::Pose2DStamped getGlobalRobotPose() const { return getRobotPose(global_costmap_->getFrameId()); }
00185 nav_2d_msgs::Pose2DStamped getLocalRobotPose() const { return getRobotPose(local_costmap_->getFrameId()); }
00186
00187
00188 void publishPath(const nav_2d_msgs::Path2D& global_plan) { path_pub_.publishPath(global_plan); }
00189 void publishTwist(const nav_2d_msgs::Twist2DStamped& command) { twist_pub_.publishTwist(command); }
00190
00191 protected:
00196 void doCostmapUpdate(nav_core2::Costmap& costmap, Executor& result_ex,
00197 CostmapUpdateCallback cb, CostmapUpdateExceptionCallback fail_cb);
00198 void makeGlobalPlan(Executor& result_ex, GlobalPlanCallback cb, PlannerExceptionCallback fail_cb);
00199 void makeLocalPlan(Executor& result_ex, LocalPlanCallback cb, PlannerExceptionCallback fail_cb,
00200 NavigationCompleteCallback complete_cb);
00202
00208 virtual void switchLocalPlannerCallback(const std::string& old_planner, const std::string& new_planner);
00209
00210
00211 pluginlib::ClassLoader<nav_core2::Costmap> costmap_loader_;
00212
00213
00214 nav_2d_utils::PluginMux<nav_core2::GlobalPlanner> global_planner_mux_;
00215 nav_core2::Costmap::Ptr global_costmap_;
00216
00217
00218 nav_2d_utils::PluginMux<nav_core2::LocalPlanner> local_planner_mux_;
00219 nav_core2::Costmap::Ptr local_costmap_;
00220
00221
00222 nav_2d_msgs::Pose2DStamped getRobotPose(const std::string& target_frame) const;
00223 TFListenerPtr tf_;
00224 bool use_latest_pose_;
00225 std::shared_ptr<nav_2d_utils::OdomSubscriber> odom_sub_;
00226
00227
00228 ros::NodeHandle private_nh_;
00229 locomotor_msgs::NavigationState state_;
00230 std::string robot_base_frame_;
00231
00232
00233 PathPublisher path_pub_;
00234 TwistPublisher twist_pub_;
00235 };
00236 }
00237
00238 #endif // LOCOMOTOR_LOCOMOTOR_H