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 #include "ros/ros.h"
00031 #include <hector_exploration_planner/hector_exploration_planner.h>
00032 #include <costmap_2d/costmap_2d_ros.h>
00033 #include <hector_nav_msgs/GetRobotTrajectory.h>
00034
00035 class SimpleExplorationPlanner
00036 {
00037 public:
00038 SimpleExplorationPlanner()
00039 {
00040 ros::NodeHandle nh;
00041
00042 costmap_2d_ros_ = new costmap_2d::Costmap2DROS("global_costmap", tfl_);
00043
00044 planner_ = new hector_exploration_planner::HectorExplorationPlanner();
00045 planner_->initialize("hector_exploration_planner",costmap_2d_ros_);
00046
00047 exploration_plan_service_server_ = nh.advertiseService("get_exploration_path", &SimpleExplorationPlanner::explorationServiceCallback, this);
00048
00049 exploration_plan_pub_ = nh.advertise<nav_msgs::Path>("exploration_path",2);
00050 }
00051
00052 bool explorationServiceCallback(hector_nav_msgs::GetRobotTrajectory::Request &req,
00053 hector_nav_msgs::GetRobotTrajectory::Response &res )
00054 {
00055 ROS_INFO("Exploration Service called");
00056
00057 tf::Stamped<tf::Pose> robot_pose_tf;
00058 costmap_2d_ros_->getRobotPose(robot_pose_tf);
00059
00060 geometry_msgs::PoseStamped pose;
00061 tf::poseStampedTFToMsg(robot_pose_tf, pose);
00062 planner_->doExploration(pose, res.trajectory.poses);
00063 res.trajectory.header.frame_id = "map";
00064 res.trajectory.header.stamp = ros::Time::now();
00065
00066 if (exploration_plan_pub_.getNumSubscribers() > 0)
00067 {
00068 exploration_plan_pub_.publish(res.trajectory);
00069 }
00070
00071 return true;
00072 }
00073
00074 protected:
00075 hector_exploration_planner::HectorExplorationPlanner* planner_;
00076 ros::ServiceServer exploration_plan_service_server_;
00077 ros::Publisher exploration_plan_pub_;
00078 costmap_2d::Costmap2DROS* costmap_2d_ros_;
00079 tf::TransformListener tfl_;
00080
00081 };
00082
00083 int main(int argc, char **argv) {
00084 ros::init(argc, argv, ROS_PACKAGE_NAME);
00085
00086 SimpleExplorationPlanner ep;
00087
00088 ros::spin();
00089
00090 return 0;
00091 }