local_planner_util.cpp
Go to the documentation of this file.
00001 /*********************************************************************
00002  *
00003  * Software License Agreement (BSD License)
00004  *
00005  *  Copyright (c) 2008, Willow Garage, Inc.
00006  *  All rights reserved.
00007  *
00008  *  Redistribution and use in source and binary forms, with or without
00009  *  modification, are permitted provided that the following conditions
00010  *  are met:
00011  *
00012  *   * Redistributions of source code must retain the above copyright
00013  *     notice, this list of conditions and the following disclaimer.
00014  *   * Redistributions in binary form must reproduce the above
00015  *     copyright notice, this list of conditions and the following
00016  *     disclaimer in the documentation and/or other materials provided
00017  *     with the distribution.
00018  *   * Neither the name of Willow Garage, Inc. nor the names of its
00019  *     contributors may be used to endorse or promote products derived
00020  *     from this software without specific prior written permission.
00021  *
00022  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00025  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00026  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00028  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00029  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00030  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00032  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00033  *  POSSIBILITY OF SUCH DAMAGE.
00034  *
00035  * Author: Eitan Marder-Eppstein
00036  *********************************************************************/
00037 
00038 #include <base_local_planner/local_planner_util.h>
00039 
00040 #include <base_local_planner/goal_functions.h>
00041 
00042 namespace base_local_planner {
00043 
00044 void LocalPlannerUtil::initialize(
00045     tf::TransformListener* tf,
00046     costmap_2d::Costmap2D* costmap,
00047     std::string global_frame) {
00048   if(!initialized_) {
00049     tf_ = tf;
00050     costmap_ = costmap;
00051     global_frame_ = global_frame;
00052     initialized_ = true;
00053   }
00054   else{
00055     ROS_WARN("Planner utils have already been initialized, doing nothing.");
00056   }
00057 }
00058 
00059 void LocalPlannerUtil::reconfigureCB(LocalPlannerLimits &config, bool restore_defaults)
00060 {
00061   if(setup_ && restore_defaults) {
00062     config = default_limits_;
00063   }
00064 
00065   if(!setup_) {
00066     default_limits_ = config;
00067     setup_ = true;
00068   }
00069   boost::mutex::scoped_lock l(limits_configuration_mutex_);
00070   limits_ = LocalPlannerLimits(config);
00071 }
00072 
00073 costmap_2d::Costmap2D* LocalPlannerUtil::getCostmap() {
00074   return costmap_;
00075 }
00076 
00077 LocalPlannerLimits LocalPlannerUtil::getCurrentLimits() {
00078   boost::mutex::scoped_lock l(limits_configuration_mutex_);
00079   return limits_;
00080 }
00081 
00082 
00083 bool LocalPlannerUtil::getGoal(tf::Stamped<tf::Pose>& goal_pose) {
00084   //we assume the global goal is the last point in the global plan
00085   return base_local_planner::getGoalPose(*tf_,
00086         global_plan_,
00087         global_frame_,
00088         goal_pose);
00089 }
00090 
00091 bool LocalPlannerUtil::setPlan(const std::vector<geometry_msgs::PoseStamped>& orig_global_plan) {
00092   if(!initialized_){
00093     ROS_ERROR("Planner utils have not been initialized, please call initialize() first");
00094     return false;
00095   }
00096 
00097   //reset the global plan
00098   global_plan_.clear();
00099 
00100   global_plan_ = orig_global_plan;
00101 
00102   return true;
00103 }
00104 
00105 bool LocalPlannerUtil::getLocalPlan(tf::Stamped<tf::Pose>& global_pose, std::vector<geometry_msgs::PoseStamped>& transformed_plan) {
00106   //get the global plan in our frame
00107   if(!base_local_planner::transformGlobalPlan(
00108       *tf_,
00109       global_plan_,
00110       global_pose,
00111       *costmap_,
00112       global_frame_,
00113       transformed_plan)) {
00114     ROS_WARN("Could not transform the global plan to the frame of the controller");
00115     return false;
00116   }
00117 
00118   //now we'll prune the plan based on the position of the robot
00119   if(limits_.prune_plan) {
00120     base_local_planner::prunePlan(global_pose, transformed_plan, global_plan_);
00121   }
00122   return true;
00123 }
00124 
00125 
00126 
00127 
00128 } // namespace


base_local_planner
Author(s): Eitan Marder-Eppstein, Eric Perko, contradict@gmail.com
autogenerated on Sun Mar 3 2019 03:46:30