move_base_topo.h
Go to the documentation of this file.
00001 /*********************************************************************
00002 *
00003 * Software License Agreement (BSD License)
00004 *
00005 *  Copyright (c) 2009, 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 #ifndef TOPOLOGICAL_ROADMAP_MOVE_BASE_TOPO_H_
00039 #define TOPOLOGICAL_ROADMAP_MOVE_BASE_TOPO_H_
00040 
00041 #include <ros/ros.h>
00042 #include <topological_nav_msgs/TopologicalRoadmap.h>
00043 #include <topological_nav_msgs/TopologicalGraph.h>
00044 #include <nav_msgs/GetPlan.h>
00045 
00046 #include <topological_roadmap/roadmap.h>
00047 #include <topological_roadmap/shortest_paths.h>
00048 
00049 #include <boost/thread.hpp>
00050 
00051 #include <topological_nav_msgs/MoveBaseTopoAction.h>
00052 #include <actionlib/server/simple_action_server.h>
00053 
00054 #include <tf/transform_listener.h>
00055 #include <costmap_2d/costmap_2d_ros.h>
00056 
00057 #include <navfn/navfn_ros.h>
00058 
00059 #include <boost/foreach.hpp>
00060 
00061 #include <sstream>
00062 
00063 #include <actionlib/client/simple_action_client.h>
00064 #include <move_base_msgs/MoveBaseAction.h>
00065 #include <mongo_roscpp/message_collection.h>
00066 #include <std_msgs/String.h>
00067 
00068 namespace topological_roadmap
00069 {
00070 
00071 typedef std::vector<unsigned> WaypointVec;
00072 
00073 struct BlockedEdge
00074 {
00075   unsigned from, to;
00076   ros::Time blocked_time;
00077 
00078   BlockedEdge(unsigned from, unsigned to, ros::Time blocked_time):
00079     from(from), to(to), blocked_time(blocked_time){}
00080 };
00081 
00082 class MoveBaseTopo
00083 {
00084 public:
00085   MoveBaseTopo();
00086 
00087   void roadmapCB(topological_nav_msgs::TopologicalRoadmap::ConstPtr roadmap);
00088   void localizationCB(const geometry_msgs::PoseStamped& l);
00089   void executeCB(const topological_nav_msgs::MoveBaseTopoGoal::ConstPtr& goal);
00090   double shortestPathDistance(const geometry_msgs::Pose& p1);
00091   geometry_msgs::PoseStamped nodePoseOnGrid(unsigned n, unsigned g) const;
00092   typedef actionlib::SimpleActionClient<move_base_msgs::MoveBaseAction> MoveBaseClient;
00093 
00094 private:
00095   void cleanup();
00096   unsigned bestGrid (const WaypointVec& path) const;
00097   bool robotWithinTolerance(double tolerance_dist, unsigned node_id);
00098   unsigned lastWaypointOnGridIndex(const Path& plan, const std::string& global_frame);
00099   unsigned lastWaypointOnGridIndex(const WaypointVec& plan, const unsigned g) const;
00100   bool makeRoadmapPlan(const topological_nav_msgs::MoveBaseTopoGoal::ConstPtr& goal,
00101                        boost::optional<Path>& plan, std::string& error_string);
00102   void checkEdgeTimeouts(const ros::TimerEvent& e);
00103   void removeBlockedEdges(const std::list<BlockedEdge>& blocked_edges, Roadmap& roadmap);
00104   void gridUpdateCB (const std_msgs::String& m);
00105   nav_msgs::OccupancyGrid::ConstPtr getGrid (const unsigned g) const;
00106   void graphCB (topological_nav_msgs::TopologicalGraph::ConstPtr m);
00107 
00108   inline double squareDist(const geometry_msgs::PoseStamped& p1, const geometry_msgs::PoseStamped& p2){
00109     return (p1.pose.position.x - p2.pose.position.x) * (p1.pose.position.x - p2.pose.position.x) 
00110       + (p1.pose.position.y - p2.pose.position.y) * (p1.pose.position.y - p2.pose.position.y);
00111   }
00112 
00113   tf::TransformListener tf_;
00114 
00115   mongo_roscpp::MessageCollection<nav_msgs::OccupancyGrid> grids_;
00116   ros::Subscriber roadmap_sub_, localization_sub_, grid_update_sub_, tmap_sub_;
00117   ros::Publisher path_pub_;
00118   ros::ServiceClient switch_grid_client_;
00119   mutable boost::mutex mutex_; // Mutable because const functions need to acquire lock
00120   Roadmap roadmap_;
00121   topological_map_2d::TopologicalMap tmap_;
00122   actionlib::SimpleActionServer<topological_nav_msgs::MoveBaseTopoAction> as_;
00123   boost::optional<unsigned> current_grid_;
00124   costmap_2d::Costmap2DROS costmap_;
00125   mutable navfn::NavfnROS planner_; // Mutable because it doesn't have a const-correct api
00126   MoveBaseClient move_base_client_;
00127   double progress_check_frequency_, next_waypoint_distance_;
00128   bool grid_switch_;
00129   std::string tf_prefix_;
00130   ros::Time last_valid_plan_;
00131   double planner_patience_;
00132   std::list<BlockedEdge> blocked_edges_;
00133   ros::Timer edge_watchdog_;
00134   double blocked_edge_timeout_;
00135   ros::ServiceClient make_plan_client_;
00136 };
00137 };
00138 
00139 #endif // include guard


topological_roadmap
Author(s): Bhaskara Marthi
autogenerated on Sun Jan 5 2014 11:39:33