Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
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_;
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_;
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