locomove_base.h
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2017, Locus Robotics
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *   * Redistributions of source code must retain the above copyright
00012  *     notice, this list of conditions and the following disclaimer.
00013  *   * Redistributions in binary form must reproduce the above
00014  *     copyright notice, this list of conditions and the following
00015  *     disclaimer in the documentation and/or other materials provided
00016  *     with the distribution.
00017  *   * Neither the name of the copyright holder nor the names of its
00018  *     contributors may be used to endorse or promote products derived
00019  *     from this software without specific prior written permission.
00020  *
00021  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025  *  COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032  *  POSSIBILITY OF SUCH DAMAGE.
00033  */
00034 
00035 #ifndef LOCOMOVE_BASE_LOCOMOVE_BASE_H
00036 #define LOCOMOVE_BASE_LOCOMOVE_BASE_H
00037 
00038 #include <actionlib/server/simple_action_server.h>
00039 #include <locomotor/locomotor.h>
00040 #include <move_base_msgs/MoveBaseAction.h>
00041 #include <nav_core/recovery_behavior.h>
00042 #include <string>
00043 #include <vector>
00044 
00045 namespace locomove_base
00046 {
00047 enum RecoveryTrigger
00048 {
00049   PLANNING_R, CONTROLLING_R, OSCILLATION_R
00050 };
00051 
00052 class LocoMoveBase
00053 {
00054 public:
00055   explicit LocoMoveBase(const ros::NodeHandle& nh);
00056   void setGoal(nav_2d_msgs::Pose2DStamped goal);
00057   void resetState();
00058 protected:
00059   void requestNavigationFailure(const locomotor_msgs::ResultCode& result);
00060 
00061   void planLoopCallback(const ros::TimerEvent& event);
00062   void requestGlobalCostmapUpdate();
00063 
00064   void onGlobalCostmapUpdate(const ros::Duration& planning_time);
00065   void onGlobalCostmapException(nav_core2::NavCore2ExceptionPtr e_ptr, const ros::Duration& planning_time);
00066 
00067   void onNewGlobalPlan(nav_2d_msgs::Path2D new_global_plan, const ros::Duration& planning_time);
00068   void onGlobalPlanningException(nav_core2::NavCore2ExceptionPtr e_ptr, const ros::Duration& planning_time);
00069 
00070   void controlLoopCallback(const ros::TimerEvent& event);
00071 
00072   void onLocalCostmapUpdate(const ros::Duration& planning_time);
00073   void onLocalCostmapException(nav_core2::NavCore2ExceptionPtr e_ptr, const ros::Duration& planning_time);
00074 
00075   void onNewLocalPlan(nav_2d_msgs::Twist2DStamped new_command, const ros::Duration& planning_time);
00076   void onLocalPlanningException(nav_core2::NavCore2ExceptionPtr e_ptr, const ros::Duration& planning_time);
00077 
00078   void onNavigationCompleted();
00079   void onNavigationFailure(const locomotor_msgs::ResultCode result);
00080 
00081   void publishZeroVelocity();
00082 
00088   bool loadRecoveryBehaviors(ros::NodeHandle node);
00089 
00093   void loadDefaultRecoveryBehaviors();
00094 
00095   void recovery();
00096 
00097   ros::NodeHandle private_nh_;
00098   locomotor::Locomotor locomotor_;
00099 
00100   // Simple Goal Handling
00101   void goalCB(const geometry_msgs::PoseStamped::ConstPtr& goal);
00102   ros::Subscriber goal_sub_;
00103 
00104   // MoveBaseAction
00105   void executeCB();
00106   actionlib::SimpleActionServer<move_base_msgs::MoveBaseAction> server_;
00107 
00108   // Recoveries
00109   RecoveryTrigger recovery_trigger_;
00110   pluginlib::ClassLoader<nav_core::RecoveryBehavior> recovery_loader_;
00111   std::vector<boost::shared_ptr<nav_core::RecoveryBehavior> > recovery_behaviors_;
00112   unsigned int recovery_index_;
00113   bool recovery_behavior_enabled_ { true };
00114 
00115   // Timer Stuff
00116   double planner_frequency_ { 10.0 }, controller_frequency_ { 20.0 };
00117   ros::Duration desired_plan_duration_, desired_control_duration_;
00118   ros::Timer plan_loop_timer_, control_loop_timer_;
00119 
00120   // The Two Executors
00121   locomotor::Executor local_planning_ex_, global_planning_ex_;
00122 
00123   // Patience
00124   bool has_global_plan_;
00125   double planner_patience_ { 5.0 }, controller_patience_ { 15.0 };
00126   ros::Time last_valid_plan_, last_valid_control_;
00127   int max_planning_retries_ {-1},  // disabled by default
00128       planning_retries_;
00129 
00130   // Oscillation variables
00131   double oscillation_timeout_ {0.0}, oscillation_distance_{0.5};
00132   ros::Time last_oscillation_reset_;
00133   geometry_msgs::Pose2D oscillation_pose_;
00134 
00135   // Costmap Pointer Copies
00136   costmap_2d::Costmap2DROS* getCostmapPointer(const nav_core2::Costmap::Ptr& costmap);
00137   costmap_2d::Costmap2DROS* planner_costmap_ros_;
00138   costmap_2d::Costmap2DROS* controller_costmap_ros_;
00139 
00140   // Debug Publishing
00141   ros::Publisher goal_pub_;
00142 };
00143 }  // namespace locomove_base
00144 
00145 #endif  // LOCOMOVE_BASE_LOCOMOVE_BASE_H


locomove_base
Author(s):
autogenerated on Wed Jun 26 2019 20:09:50