locomotor.h
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2017, Locus Robotics
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of the copyright holder nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  */
34 
35 #ifndef LOCOMOTOR_LOCOMOTOR_H
36 #define LOCOMOTOR_LOCOMOTOR_H
37 
38 #include <ros/ros.h>
39 #include <locomotor/executor.h>
40 #include <locomotor/publishers.h>
41 #include <locomotor_msgs/NavigationState.h>
42 #include <locomotor_msgs/ResultCode.h>
43 #include <nav_core2/exceptions.h>
44 #include <nav_core2/costmap.h>
47 #include <pluginlib/class_loader.h>
50 #include <map>
51 #include <string>
52 #include <vector>
53 
54 namespace locomotor
55 {
56 // Callback Type Definitions
57 using CostmapUpdateCallback = std::function<void (const ros::Duration&)>;
58 using CostmapUpdateExceptionCallback = std::function<void (nav_core2::NavCore2ExceptionPtr, const ros::Duration&)>;
59 using GlobalPlanCallback = std::function<void (const nav_2d_msgs::Path2D&, const ros::Duration&)>;
60 using LocalPlanCallback = std::function<void (const nav_2d_msgs::Twist2DStamped&, const ros::Duration&)>;
61 using PlannerExceptionCallback = std::function<void (nav_core2::NavCore2ExceptionPtr, const ros::Duration&)>;
62 using NavigationCompleteCallback = std::function<void ()>;
63 using NavigationFailureCallback = std::function<void (const locomotor_msgs::ResultCode)>;
64 
65 inline locomotor_msgs::ResultCode makeResultCode(int component = -1, int result_code = -1,
66  const std::string& message = "")
67 {
68  locomotor_msgs::ResultCode code;
69  code.component = component;
70  code.result_code = result_code;
71  code.message = message;
72  return code;
73 }
74 
79 class Locomotor
80 {
81 public:
85  explicit Locomotor(const ros::NodeHandle& private_nh);
86 
95  void initializeLocalPlanners(Executor& ex); // end of InitializeMethods group
97 
102  virtual void setGoal(nav_2d_msgs::Pose2DStamped goal);
103 
116  void requestGlobalCostmapUpdate(Executor& work_ex, Executor& result_ex,
117  CostmapUpdateCallback cb = nullptr,
118  CostmapUpdateExceptionCallback fail_cb = nullptr);
119 
127  void requestLocalCostmapUpdate(Executor& work_ex, Executor& result_ex,
128  CostmapUpdateCallback cb = nullptr,
129  CostmapUpdateExceptionCallback fail_cb = nullptr);
130 
138  void requestGlobalPlan(Executor& work_ex, Executor& result_ex,
139  GlobalPlanCallback cb = nullptr,
140  PlannerExceptionCallback fail_cb = nullptr);
141 
150  void requestLocalPlan(Executor& work_ex, Executor& result_ex,
151  LocalPlanCallback cb = nullptr,
152  PlannerExceptionCallback fail_cb = nullptr,
153  NavigationCompleteCallback complete_cb = nullptr);
154 
161  void requestNavigationFailure(Executor& result_ex, const locomotor_msgs::ResultCode& result,
162  NavigationFailureCallback cb = nullptr); // end of ActionRequests group
164 
165  const locomotor_msgs::NavigationState& getNavigationState() const { return state_; }
166 
167  // Global/Local Planner Access
168  std::vector<std::string> getGlobalPlannerNames() const { return global_planner_mux_.getPluginNames(); }
171  bool useGlobalPlanner(const std::string& name) { return global_planner_mux_.usePlugin(name); }
172 
173  std::vector<std::string> getLocalPlannerNames() const { return local_planner_mux_.getPluginNames(); }
176  bool useLocalPlanner(const std::string& name) { return local_planner_mux_.usePlugin(name); }
177 
178  // Costmap Access
181 
182  // Additional Convenience Access
183  TFListenerPtr getTFListener() const { return tf_; }
184  nav_2d_msgs::Pose2DStamped getGlobalRobotPose() const { return getRobotPose(global_costmap_->getFrameId()); }
185  nav_2d_msgs::Pose2DStamped getLocalRobotPose() const { return getRobotPose(local_costmap_->getFrameId()); }
186 
187  // Publisher Access
188  void publishPath(const nav_2d_msgs::Path2D& global_plan) { path_pub_.publishPath(global_plan); }
189  void publishTwist(const nav_2d_msgs::Twist2DStamped& command) { twist_pub_.publishTwist(command); }
190 
191 protected:
196  void doCostmapUpdate(nav_core2::Costmap& costmap, Executor& result_ex,
200  NavigationCompleteCallback complete_cb); // end of ActualActions group
202 
208  virtual void switchLocalPlannerCallback(const std::string& old_planner, const std::string& new_planner);
209 
210  // Costmap Loader
212 
213  // Global Planners and Costmap
216 
217  // Local Planners and Costmap
220 
221  // Tools for getting the position and velocity of the robot
222  nav_2d_msgs::Pose2DStamped getRobotPose(const std::string& target_frame) const;
225  std::shared_ptr<nav_2d_utils::OdomSubscriber> odom_sub_;
226 
227  // Core Variables
229  locomotor_msgs::NavigationState state_;
230  std::string robot_base_frame_;
231 
232  // Publishers
235 };
236 } // namespace locomotor
237 
238 #endif // LOCOMOTOR_LOCOMOTOR_H
nav_2d_utils::PluginMux< nav_core2::LocalPlanner > local_planner_mux_
Definition: locomotor.h:218
nav_core2::GlobalPlanner & getCurrentGlobalPlanner()
Definition: locomotor.h:170
nav_2d_msgs::Pose2DStamped getLocalRobotPose() const
Definition: locomotor.h:185
nav_2d_msgs::Pose2DStamped getRobotPose(const std::string &target_frame) const
Definition: locomotor.cpp:232
void publishTwist(const nav_2d_msgs::Twist2DStamped &command)
Definition: locomotor.h:189
std::function< void(const nav_2d_msgs::Path2D &, const ros::Duration &)> GlobalPlanCallback
Definition: locomotor.h:59
nav_core2::LocalPlanner & getCurrentLocalPlanner()
Definition: locomotor.h:175
pluginlib::ClassLoader< nav_core2::Costmap > costmap_loader_
Definition: locomotor.h:211
Collection of objects used in ROS CallbackQueue threading.
Definition: executor.h:71
std::vector< std::string > getGlobalPlannerNames() const
Definition: locomotor.h:168
TFListenerPtr tf_
Definition: locomotor.h:223
locomotor_msgs::ResultCode makeResultCode(int component=-1, int result_code=-1, const std::string &message="")
Definition: locomotor.h:65
std::string getCurrentLocalPlannerName() const
Definition: locomotor.h:174
TwistPublisher twist_pub_
Definition: locomotor.h:234
nav_core2::Costmap::Ptr global_costmap_
Definition: locomotor.h:215
std::function< void(const locomotor_msgs::ResultCode)> NavigationFailureCallback
Definition: locomotor.h:63
void requestLocalCostmapUpdate(Executor &work_ex, Executor &result_ex, CostmapUpdateCallback cb=nullptr, CostmapUpdateExceptionCallback fail_cb=nullptr)
Request the local costmap get updated as a new callback.
Definition: locomotor.cpp:131
std::vector< std::string > getLocalPlannerNames() const
Definition: locomotor.h:173
std::function< void(nav_core2::NavCore2ExceptionPtr, const ros::Duration &)> CostmapUpdateExceptionCallback
Definition: locomotor.h:58
void publishPath(const nav_2d_msgs::Path2D &global_plan)
Definition: publishers.cpp:71
void initializeGlobalPlanners(Executor &ex)
Definition: locomotor.cpp:92
ros::NodeHandle private_nh_
Definition: locomotor.h:228
virtual void setGoal(nav_2d_msgs::Pose2DStamped goal)
Starts a new navigation to the given goal.
Definition: locomotor.cpp:110
std::function< void(nav_core2::NavCore2ExceptionPtr, const ros::Duration &)> PlannerExceptionCallback
Definition: locomotor.h:61
bool useGlobalPlanner(const std::string &name)
Definition: locomotor.h:171
PathPublisher path_pub_
Definition: locomotor.h:233
locomotor_msgs::NavigationState state_
Definition: locomotor.h:229
void publishPath(const nav_2d_msgs::Path2D &global_plan)
Definition: locomotor.h:188
bool usePlugin(const std::string &name)
nav_2d_msgs::Pose2DStamped getGlobalRobotPose() const
Definition: locomotor.h:184
an extensible path planning coordination engine
Definition: locomotor.h:79
std::function< void(const ros::Duration &)> CostmapUpdateCallback
Definition: locomotor.h:57
std::string getCurrentPluginName() const
const locomotor_msgs::NavigationState & getNavigationState() const
Definition: locomotor.h:165
std::string robot_base_frame_
Definition: locomotor.h:230
void initializeLocalCostmap(Executor &ex)
Definition: locomotor.cpp:82
nav_2d_utils::PluginMux< nav_core2::GlobalPlanner > global_planner_mux_
Definition: locomotor.h:214
void initializeGlobalCostmap(Executor &ex)
Definition: locomotor.cpp:72
virtual void switchLocalPlannerCallback(const std::string &old_planner, const std::string &new_planner)
Callback for when the local planner switches to ensure the new planner has up to date information...
Definition: locomotor.cpp:117
void doCostmapUpdate(nav_core2::Costmap &costmap, Executor &result_ex, CostmapUpdateCallback cb, CostmapUpdateExceptionCallback fail_cb)
Definition: locomotor.cpp:157
TFListenerPtr getTFListener() const
Definition: locomotor.h:183
void initializeLocalPlanners(Executor &ex)
Definition: locomotor.cpp:101
void requestNavigationFailure(Executor &result_ex, const locomotor_msgs::ResultCode &result, NavigationFailureCallback cb=nullptr)
Request that a onNavigationFailure event be added as a new callback.
Definition: locomotor.cpp:151
Locomotor(const ros::NodeHandle &private_nh)
Base Constructor.
Definition: locomotor.cpp:48
bool useLocalPlanner(const std::string &name)
Definition: locomotor.h:176
nav_core2::Costmap::Ptr local_costmap_
Definition: locomotor.h:219
nav_core2::Costmap::Ptr getLocalCostmap() const
Definition: locomotor.h:180
std::function< void()> NavigationCompleteCallback
Definition: locomotor.h:62
std::shared_ptr< Costmap > Ptr
void makeLocalPlan(Executor &result_ex, LocalPlanCallback cb, PlannerExceptionCallback fail_cb, NavigationCompleteCallback complete_cb)
Definition: locomotor.cpp:197
std::shared_ptr< tf::TransformListener > TFListenerPtr
nav_core2::Costmap::Ptr getGlobalCostmap() const
Definition: locomotor.h:179
void makeGlobalPlan(Executor &result_ex, GlobalPlanCallback cb, PlannerExceptionCallback fail_cb)
Definition: locomotor.cpp:176
void publishTwist(const nav_2d_msgs::Twist2DStamped &command)
Definition: publishers.cpp:125
void requestGlobalCostmapUpdate(Executor &work_ex, Executor &result_ex, CostmapUpdateCallback cb=nullptr, CostmapUpdateExceptionCallback fail_cb=nullptr)
Request the global costmap get updated as a new callback.
Definition: locomotor.cpp:124
std::string getCurrentGlobalPlannerName() const
Definition: locomotor.h:169
std::function< void(const nav_2d_msgs::Twist2DStamped &, const ros::Duration &)> LocalPlanCallback
Definition: locomotor.h:60
void requestGlobalPlan(Executor &work_ex, Executor &result_ex, GlobalPlanCallback cb=nullptr, PlannerExceptionCallback fail_cb=nullptr)
Request the global planner get run as a new callback.
Definition: locomotor.cpp:138
std::vector< std::string > getPluginNames() const
std::shared_ptr< nav_2d_utils::OdomSubscriber > odom_sub_
Definition: locomotor.h:225
void requestLocalPlan(Executor &work_ex, Executor &result_ex, LocalPlanCallback cb=nullptr, PlannerExceptionCallback fail_cb=nullptr, NavigationCompleteCallback complete_cb=nullptr)
Request the local planner get run as a new callback.
Definition: locomotor.cpp:144


locomotor
Author(s):
autogenerated on Wed Jun 26 2019 20:06:18