explore_frontier.h
Go to the documentation of this file.
00001 /*********************************************************************
00002  *
00003  * Software License Agreement (BSD License)
00004  *
00005  *  Copyright (c) 2008, Robert Bosch LLC.
00006  *  Copyright (c) 2015-2016, Jiri Horner.
00007  *  All rights reserved.
00008  *
00009  *  Redistribution and use in source and binary forms, with or without
00010  *  modification, are permitted provided that the following conditions
00011  *  are met:
00012  *
00013  *   * Redistributions of source code must retain the above copyright
00014  *     notice, this list of conditions and the following disclaimer.
00015  *   * Redistributions in binary form must reproduce the above
00016  *     copyright notice, this list of conditions and the following
00017  *     disclaimer in the documentation and/or other materials provided
00018  *     with the distribution.
00019  *   * Neither the name of the Jiri Horner nor the names of its
00020  *     contributors may be used to endorse or promote products derived
00021  *     from this software without specific prior written permission.
00022  *
00023  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00024  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00025  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00026  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00027  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00028  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00029  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00030  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00031  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00032  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00033  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00034  *  POSSIBILITY OF SUCH DAMAGE.
00035  *
00036  *********************************************************************/
00037 
00038 #ifndef EXPLORE_FRONTIER_H_
00039 #define EXPLORE_FRONTIER_H_
00040 
00041 #include <nav_msgs/OccupancyGrid.h>
00042 #include <geometry_msgs/Pose.h>
00043 #include <visualization_msgs/MarkerArray.h>
00044 #include <tf/LinearMath/Vector3.h>
00045 
00046 #include <explore/costmap_client.h>
00047 
00048 /* I have been using modified version of navfn for a long time here.
00049 Unfornutely my changes are affecting ABI of the component, so the can't be
00050 accepted for ROS Jade or below. I expect them be accepted for ROS Karmic. Then
00051 this should be moved back to using standard ROS navfn `<navfn/navfn_ros.h>`.
00052 For the meanwhile, to allow seamless building, I will be using internal
00053 version included from ROS. */
00054 
00055 #include <explore/navfn_ros.h>
00056 
00057 namespace explore {
00058 
00059 struct FrontierPoint {
00060   size_t idx;     //position
00061   tf::Vector3 d; //direction
00062 
00063   FrontierPoint() : idx(0) {}
00064   FrontierPoint(size_t idx_, const tf::Vector3& d_) : idx(idx_), d(d_) {}
00065 };
00066 
00067 struct Frontier {
00068   size_t size;
00069   geometry_msgs::Pose pose;
00070 
00071   Frontier() : size(0) {}
00072   Frontier(size_t size_, const geometry_msgs::Pose& pose_) : size(size_), pose(pose_) {}
00073 };
00074 
00075 struct WeightedFrontier {
00076   double cost;
00077   Frontier frontier;
00078 
00079   WeightedFrontier() : cost(1e9) {}
00080   WeightedFrontier(double cost_, const Frontier& frontier_) : cost(cost_), frontier(frontier_) {}
00081   bool operator<(const WeightedFrontier& o) const { return cost < o.cost; }
00082 };
00083 
00088 class ExploreFrontier {
00089 private:
00090   // can't be const as we will do locking
00091   Costmap2DClient* const costmap_client_;
00092   costmap_2d::Costmap2D* const costmap_;
00093   navfn::NavfnROS* const planner_;
00094 
00095   nav_msgs::OccupancyGrid map_;
00096   std::vector<Frontier> frontiers_;
00097 
00098   size_t last_markers_count_;
00099 
00103   void findFrontiers();
00104 
00109   double getFrontierCost(const Frontier& frontier);
00110 
00116   double getOrientationChange(const Frontier& frontier, const tf::Stamped<tf::Pose>& robot_pose) const;
00117 
00122   double getFrontierGain(const Frontier& frontier) const;
00123 
00124 public:
00131   ExploreFrontier(Costmap2DClient* costmap, navfn::NavfnROS* planner);
00132 
00138   bool getFrontiers(std::vector<geometry_msgs::Pose>& frontiers);
00139 
00157   bool getExplorationGoals(
00158     tf::Stamped<tf::Pose> start,
00159     std::vector<geometry_msgs::Pose>& goals,
00160     double cost_scale, double orientation_scale, double gain_scale
00161   );
00162 
00167   void getVisualizationMarkers(visualization_msgs::MarkerArray& markers);
00168 };
00169 
00170 }
00171 
00172 #endif /* EXPLORE_FRONTIER_H_ */


explore
Author(s): Jiri Horner
autogenerated on Sun Mar 26 2017 03:48:06